Skip to content

Commit

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

async function waitForFontLoading(page) {
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 +238,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 +309,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 +337,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 904369d

Please sign in to comment.