From b57bfd041472fe6bbe6d830f36a454dd38fb1336 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Mon, 13 May 2024 09:11:11 -0600 Subject: [PATCH 1/2] fix(playwright): skip unloaded iframes --- package-lock.json | 24 +++++++++---------- packages/playwright/package.json | 2 +- packages/playwright/src/index.ts | 9 ++++++- .../playwright/test/axe-playwright.spec.ts | 7 +++++- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index c30a2e86..94b18092 100644 --- a/package-lock.json +++ b/package-lock.json @@ -4511,12 +4511,12 @@ } }, "node_modules/@playwright/test": { - "version": "1.40.1", - "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.40.1.tgz", - "integrity": "sha512-EaaawMTOeEItCRvfmkI9v6rBkF1svM8wjl/YPRrg2N2Wmp+4qJYkWtJsbew1szfKKDm6fPLy4YAanBhIlf9dWw==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.44.0.tgz", + "integrity": "sha512-rNX5lbNidamSUorBhB4XZ9SQTjAqfe5M+p37Z8ic0jPFBMo5iCtQz1kRWkEMg+rYOKSlVycpQmpqjSFq7LXOfg==", "dev": true, "dependencies": { - "playwright": "1.40.1" + "playwright": "1.44.0" }, "bin": { "playwright": "cli.js" @@ -24698,12 +24698,12 @@ } }, "node_modules/playwright": { - "version": "1.40.1", - "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.40.1.tgz", - "integrity": "sha512-2eHI7IioIpQ0bS1Ovg/HszsN/XKNwEG1kbzSDDmADpclKc7CyqkHw7Mg2JCz/bbCxg25QUPcjksoMW7JcIFQmw==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/playwright/-/playwright-1.44.0.tgz", + "integrity": "sha512-F9b3GUCLQ3Nffrfb6dunPOkE5Mh68tR7zN32L4jCk4FjQamgesGay7/dAAe1WaMEGV04DkdJfcJzjoCKygUaRQ==", "dev": true, "dependencies": { - "playwright-core": "1.40.1" + "playwright-core": "1.44.0" }, "bin": { "playwright": "cli.js" @@ -24716,9 +24716,9 @@ } }, "node_modules/playwright-core": { - "version": "1.40.1", - "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.40.1.tgz", - "integrity": "sha512-+hkOycxPiV534c4HhpfX6yrlawqVUzITRKwHAmYfmsVreltEl6fAZJ3DPfLMOODw0H3s1Itd6MDCWmP1fl/QvQ==", + "version": "1.44.0", + "resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.44.0.tgz", + "integrity": "sha512-ZTbkNpFfYcGWohvTTl+xewITm7EOuqIqex0c7dNZ+aXsbrLj0qI8XlGKfPpipjm0Wny/4Lt4CJsWJk1stVS5qQ==", "bin": { "playwright-core": "cli.js" }, @@ -29886,7 +29886,7 @@ "axe-core": "~4.9.0" }, "devDependencies": { - "@playwright/test": "^1.34.3", + "@playwright/test": "^1.44.0", "@types/chai": "^4.3.3", "@types/express": "^4.17.14", "@types/mocha": "^10.0.0", diff --git a/packages/playwright/package.json b/packages/playwright/package.json index f9e85f06..b17866d0 100644 --- a/packages/playwright/package.json +++ b/packages/playwright/package.json @@ -54,7 +54,7 @@ "axe-core": "~4.9.0" }, "devDependencies": { - "@playwright/test": "^1.34.3", + "@playwright/test": "^1.44.0", "@types/chai": "^4.3.3", "@types/express": "^4.17.14", "@types/mocha": "^10.0.0", diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index cf0b3326..d15efed4 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -185,7 +185,14 @@ export default class AxeBuilder { private async inject(frames: Frame[]): Promise { for (const iframe of frames) { - await iframe.evaluate(await this.script()); + const race = new Promise((_, reject) => { + setTimeout(() => { + reject(new Error('Script Timeout')); + }, 1000); + }); + const evaluate = iframe.evaluate(this.script()); + + await Promise.race([evaluate, race]); await iframe.evaluate(await this.axeConfigure()); } } diff --git a/packages/playwright/test/axe-playwright.spec.ts b/packages/playwright/test/axe-playwright.spec.ts index 73b68257..5d64097a 100644 --- a/packages/playwright/test/axe-playwright.spec.ts +++ b/packages/playwright/test/axe-playwright.spec.ts @@ -447,7 +447,12 @@ describe('@axe-core/playwright', () => { .analyze(); assert.equal(res?.status(), 200); - assert.lengthOf(results.incomplete, 0); + assert.equal(results.incomplete[0].id, 'frame-tested'); + assert.lengthOf(results.incomplete[0].nodes, 1); + assert.deepEqual(results.incomplete[0].nodes[0].target, [ + '#ifr-lazy', + '#lazy-iframe' + ]); assert.equal(results.violations[0].id, 'label'); assert.lengthOf(results.violations[0].nodes, 1); assert.deepEqual(results.violations[0].nodes[0].target, [ From 41032a0b06c9b54d87d869553f47450e500fed49 Mon Sep 17 00:00:00 2001 From: Steven Lambert <2433219+straker@users.noreply.github.com> Date: Mon, 13 May 2024 11:31:38 -0600 Subject: [PATCH 2/2] throw only in run partial --- packages/playwright/src/index.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/playwright/src/index.ts b/packages/playwright/src/index.ts index d15efed4..32cfd592 100644 --- a/packages/playwright/src/index.ts +++ b/packages/playwright/src/index.ts @@ -183,7 +183,7 @@ export default class AxeBuilder { * @returns Promise */ - private async inject(frames: Frame[]): Promise { + private async inject(frames: Frame[], shouldThrow?: boolean): Promise { for (const iframe of frames) { const race = new Promise((_, reject) => { setTimeout(() => { @@ -192,8 +192,15 @@ export default class AxeBuilder { }); const evaluate = iframe.evaluate(this.script()); - await Promise.race([evaluate, race]); - await iframe.evaluate(await this.axeConfigure()); + try { + await Promise.race([evaluate, race]); + await iframe.evaluate(await this.axeConfigure()); + } catch (err) { + // in legacy mode we don't want to throw the error we just want to skip injecting into the frame + if (shouldThrow) { + throw err; + } + } } } @@ -263,7 +270,7 @@ export default class AxeBuilder { iframeHandle.asElement() as ElementHandle; const childFrame = await iframeElement.contentFrame(); if (childFrame) { - await this.inject([childFrame]); + await this.inject([childFrame], true); childResults = await this.runPartialRecursive( childFrame, frameContext