Skip to content

Commit

Permalink
adding wait for font function (#1810)
Browse files Browse the repository at this point in the history
  • Loading branch information
prklm10 authored Dec 13, 2024
1 parent 841d07f commit cc65870
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,15 @@ function waitForDiscoveryNetworkIdle(page, options) {
return page.network.idle(filter, networkIdleTimeout, captureResponsiveAssetsEnabled);
}

async function waitForFontLoading(page) {
return await logger.measure('core:discovery', 'waitForFontLoading', undefined, async () => {
return await Promise.race([
page.eval('await document.fonts.ready;'),
new Promise((res) => setTimeout(res, 5000))
]);
});
}

// Creates an initial resource map for a snapshot containing serialized DOM
function parseDomResources({ url, domSnapshot }) {
const map = new Map();
Expand Down Expand Up @@ -231,6 +240,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
deviceScaleFactor: device.deviceScaleFactor,
mobile: true
});
yield waitForFontLoading(page);
yield waitForDiscoveryNetworkIdle(page, discovery);
}
}
Expand Down Expand Up @@ -301,6 +311,7 @@ async function* captureSnapshotResources(page, snapshot, options) {
for (let i = 0; i < widths.length - 1; i++) {
if (captureWidths) yield* takeSnapshot(snap, width);
yield page.evaluate(execute?.beforeResize);
yield waitForFontLoading(page);
yield waitForDiscoveryNetworkIdle(page, discovery);
yield resizePage(width = widths[i + 1]);
if (snapshot.responsiveSnapshotCapture) { yield page.goto(snapshot.url, { cookies, forceReload: true }); }
Expand Down Expand Up @@ -328,6 +339,7 @@ async function* captureSnapshotResources(page, snapshot, options) {

// wait for final network idle when not capturing DOM
if (capture && snapshot.domSnapshot) {
yield waitForFontLoading(page);
yield waitForDiscoveryNetworkIdle(page, discovery);
yield* captureResponsiveAssets();
capture(processSnapshotResources(snapshot));
Expand Down

0 comments on commit cc65870

Please sign in to comment.