Skip to content
This repository was archived by the owner on Oct 23, 2023. It is now read-only.

Commit dd1a2dd

Browse files
authored
fix: wait aria-busy before images & fonts (#9)
1 parent c328141 commit dd1a2dd

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/index.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ function waitForFontLoading() {
3737

3838
// Check if the images are loaded
3939
function waitForImagesLoading() {
40-
const allImages = Array.from(document.images);
41-
allImages.forEach(img => img.loading = "eager")
42-
return allImages.every((img)=>img.complete);
40+
const allImages = Array.from(document.images);
41+
allImages.forEach((img) => (img.loading = "eager"));
42+
return allImages.every((img) => img.complete);
4343
}
4444

4545
type LocatorOptions = Parameters<Page["locator"]>[1];
@@ -72,9 +72,14 @@ export async function argosScreenshot(
7272

7373
mkdir(screenshotFolder, { recursive: true });
7474

75+
// Inject global styles
76+
await page.addStyleTag({ content: GLOBAL_STYLES });
77+
78+
// Wait for all busy elements to be loaded
79+
await page.waitForSelector('[aria-busy="true"]', { state: "hidden" });
80+
81+
// Wait for all images and fonts to be loaded
7582
await Promise.all([
76-
page.addStyleTag({ content: GLOBAL_STYLES }),
77-
page.waitForSelector('[aria-busy="true"]', { state: "hidden" }),
7883
page.waitForFunction(waitForImagesLoading),
7984
page.waitForFunction(waitForFontLoading),
8085
]);

0 commit comments

Comments
 (0)