Skip to content

Commit 4f21b11

Browse files
canovazcorpan
authored andcommitted
Don't rely on the pagereveal event in lcp/image-upscaling.html
After the changes in #56018 this test started to rely on `pagereveal` since the way we load the popup has changed. `pagereveal` is a new event type that's not implemented by every browsers yet and this test is for lcp rather than the CSS view transitions, so we shouldn't rely on that. On the other hand, if a browser doesn't expose the `pageshow` event it means that this is a sync `about:blank`, so the document should be immediately ready. That's why checking `popup.document.readyState` is simple and effective enough. Tested it with all major browsers and it seems like it's passing in all of them. Once Firefox lands the synchronous `about:blank` changes it would be good to remove this code all together.
1 parent cbe9409 commit 4f21b11

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

largest-contentful-paint/image-upscaling.html

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@
2020
t.add_cleanup(() => popup.close());
2121
});
2222

23-
// Per spec, we should end up with a pagereveal event once the
24-
// window is open. However, Gecko seems to load the initial
25-
// about:blank synchronously and then asynchronously load the
26-
// about:blank requested above, thus we also accept pageshow
27-
// here as a sign the popup is ready.
28-
await Promise.any([
29-
new Promise(resolve => popup.addEventListener('pagereveal', () => resolve(), {'once': true})),
30-
new Promise(resolve => popup.addEventListener('pageshow', () => resolve(), {'once': true})),
31-
]);
23+
// Ensure the popup document is ready before manipulating it.
24+
// Per spec, about:blank should load synchronously and should be
25+
// immediately ready. In older Gecko versions this may not be the case,
26+
// so we wait for pageshow if needed.
27+
if (popup.document.readyState !== 'complete') {
28+
await new Promise((resolve) =>
29+
popup.addEventListener('pageshow', resolve, { once: true })
30+
);
31+
}
3232

3333
const image = popup.document.createElement('img');
3434
image.src = imageURL;

0 commit comments

Comments
 (0)