Skip to content

Commit cc65870

Browse files
authored
adding wait for font function (#1810)
1 parent 841d07f commit cc65870

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

packages/core/src/discovery.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,15 @@ function waitForDiscoveryNetworkIdle(page, options) {
117117
return page.network.idle(filter, networkIdleTimeout, captureResponsiveAssetsEnabled);
118118
}
119119

120+
async function waitForFontLoading(page) {
121+
return await logger.measure('core:discovery', 'waitForFontLoading', undefined, async () => {
122+
return await Promise.race([
123+
page.eval('await document.fonts.ready;'),
124+
new Promise((res) => setTimeout(res, 5000))
125+
]);
126+
});
127+
}
128+
120129
// Creates an initial resource map for a snapshot containing serialized DOM
121130
function parseDomResources({ url, domSnapshot }) {
122131
const map = new Map();
@@ -231,6 +240,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
231240
deviceScaleFactor: device.deviceScaleFactor,
232241
mobile: true
233242
});
243+
yield waitForFontLoading(page);
234244
yield waitForDiscoveryNetworkIdle(page, discovery);
235245
}
236246
}
@@ -301,6 +311,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
301311
for (let i = 0; i < widths.length - 1; i++) {
302312
if (captureWidths) yield* takeSnapshot(snap, width);
303313
yield page.evaluate(execute?.beforeResize);
314+
yield waitForFontLoading(page);
304315
yield waitForDiscoveryNetworkIdle(page, discovery);
305316
yield resizePage(width = widths[i + 1]);
306317
if (snapshot.responsiveSnapshotCapture) { yield page.goto(snapshot.url, { cookies, forceReload: true }); }
@@ -328,6 +339,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
328339

329340
// wait for final network idle when not capturing DOM
330341
if (capture && snapshot.domSnapshot) {
342+
yield waitForFontLoading(page);
331343
yield waitForDiscoveryNetworkIdle(page, discovery);
332344
yield* captureResponsiveAssets();
333345
capture(processSnapshotResources(snapshot));

0 commit comments

Comments
 (0)