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

Commit

Permalink
feat: disable spellcheck in argosScreenshot (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsfez authored Sep 21, 2023
1 parent 5d40cb3 commit c09e518
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
4 changes: 4 additions & 0 deletions fixtures/dummy.html
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ <h3>Image</h3>
<div class="hint">Hint: the image should be loaded.</div>
<img id="image" src="https://placebear.com/500/600" />

<h3>Input</h3>
<div class="hint">Hint: spellcheck should be disabled</div>
<input value="an orrange carrot" autofocus />

<h3>Paragraph</h3>
<div class="hint">
Hint: the font should be loaded and the scrollbar hidden.
Expand Down
14 changes: 12 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const GLOBAL_STYLES = `
font-family: monospace !important;
opacity: 0 !important;
}
[data-visual-test="removed"] {
display: none !important;
}
Expand All @@ -42,6 +42,15 @@ function waitForImagesLoading() {
return allImages.every((img) => img.complete);
}

// Disable spellcheck to avoid red underlines
function disableSpellCheck() {
const query =
"[contenteditable]:not([contenteditable=false]):not([spellcheck=false]), input:not([spellcheck=false]), textarea:not([spellcheck=false])";
const inputs = document.querySelectorAll(query);
inputs.forEach((input) => input.setAttribute("spellcheck", "false"));
return true;
}

type LocatorOptions = Parameters<Page["locator"]>[1];

type ScreenshotOptions<
Expand Down Expand Up @@ -78,10 +87,11 @@ export async function argosScreenshot(
// 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
// Code injection to improve the screenshot stability
await Promise.all([
page.waitForFunction(waitForImagesLoading),
page.waitForFunction(waitForFontLoading),
page.waitForFunction(disableSpellCheck),
]);

await handle.screenshot({
Expand Down

0 comments on commit c09e518

Please sign in to comment.