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

Commit

Permalink
fix: wait aria-busy before images & fonts (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
gregberge authored Jul 12, 2023
1 parent c328141 commit dd1a2dd
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ function waitForFontLoading() {

// Check if the images are loaded
function waitForImagesLoading() {
const allImages = Array.from(document.images);
allImages.forEach(img => img.loading = "eager")
return allImages.every((img)=>img.complete);
const allImages = Array.from(document.images);
allImages.forEach((img) => (img.loading = "eager"));
return allImages.every((img) => img.complete);
}

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

mkdir(screenshotFolder, { recursive: true });

// Inject global styles
await page.addStyleTag({ content: GLOBAL_STYLES });

// Wait for all busy elements to be loaded
await page.waitForSelector('[aria-busy="true"]', { state: "hidden" });

// Wait for all images and fonts to be loaded
await Promise.all([
page.addStyleTag({ content: GLOBAL_STYLES }),
page.waitForSelector('[aria-busy="true"]', { state: "hidden" }),
page.waitForFunction(waitForImagesLoading),
page.waitForFunction(waitForFontLoading),
]);
Expand Down

0 comments on commit dd1a2dd

Please sign in to comment.