Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding wait for font function #1810

Merged
merged 3 commits into from
Dec 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading