How to make Backstop wait until web fonts have loaded
- Dominant language
- JavaScript
- Stars
- 7.2k
- Forks
- 621
- PR merge metrics
- No merged PRs in 30d
Description
I'm having trouble editing `onReady.js` to make Backstop wait for web fonts to be confirmed as loaded.
```js
// engine_scripts/puppet/onReady.js
module.exports = async (page, scenario, vp) => {
console.log('SCENARIO > ' + scenario.label);
await require('./clickAndHoverHelper')(page, scenario);
// add more ready handlers here...
// https://github.com/puppeteer/puppeteer/blob/master/docs/api.md#pageevaluatehandlepagefunction-args
await page.evaluateHandle(() => {
// TODO: This doesn't seem to pause the scenario as we want.
// https://stackoverflow.com/a/32292880/464066
// https://developer.mozilla.org/en-US/docs/Web/API/Document/fonts
document.fonts.ready.then(function () {
// Fonts have loaded.
return true
});
// TODO: This doesn't pause the scenario either.
document.fonts.onloadingdone = function (fontFaceSetEvent) {
console.log('onloadingdone we have ' + fontFaceSetEvent.fontfaces.length + ' font faces loaded');
return true
};
})
};
```
Above are 2 different attempts to get this to work. As I'm sure you can tell, I have no idea what I'm doing with puppet. The `console.log` towards the end does fire and does include relevant info about the fonts being used so I know that my use of the fonts API is somewhat correct.
Can anyone point me in the right direction here?
Contributor guide
Assessment
This issue has not been assessed yet.