Skip to content

Commit

Permalink
Wait for fonts before goTo() and render() resolve
Browse files Browse the repository at this point in the history
Since fonts are downloaded asynchronously, we should await the `document.fonts.ready` promise since further network requests may not be available once the page has loads

Similarly, some components are made visible after initialising JavaScript (or new elements created and inserted) so we should wait for additional font downloads to complete there too

E.g. GDS Transport Light may have loaded already, but GDS Transport Bold may be requested on demand as required
  • Loading branch information
colinrotherham committed Oct 20, 2023
1 parent c1cde46 commit 2a29ce8
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/helpers/puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ async function render(page, componentName, renderOptions, browserOptions) {
{ cause: error }
)
}

await page.evaluateHandle('document.fonts.ready')
} finally {
// Disable middleware
page.off('request', requestHandler)
Expand Down Expand Up @@ -219,6 +221,7 @@ async function goTo(page, path, options) {
throw new Error(`HTTP ${code} for '${pathname}'`)
}

await page.evaluateHandle('document.fonts.ready')
await page.bringToFront()

return page
Expand Down

0 comments on commit 2a29ce8

Please sign in to comment.