Skip to content

Commit 18d4a63

Browse files
committed
fix: add workaround for headless issue
1 parent 627696e commit 18d4a63

File tree

4 files changed

+35
-8
lines changed

4 files changed

+35
-8
lines changed

.changeset/itchy-socks-rule.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@web/test-runner-chrome': patch
3+
---
4+
5+
fix: add workaround for headless issue
6+
7+
This will patch `window.requestAnimationFrame` and `window.requestIdleCallback` and make sure that the tab running the test code is brought back to the front.

packages/test-runner-chrome/src/ChromeLauncherPage.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export class ChromeLauncherPage {
99
private product: string;
1010
public puppeteerPage: Page;
1111
private nativeInstrumentationEnabledOnPage = false;
12+
private patchAdded = false;
1213

1314
constructor(
1415
config: TestRunnerCoreConfig,
@@ -37,6 +38,31 @@ export class ChromeLauncherPage {
3738
});
3839
}
3940

41+
// Patching the browser page to workaround an issue in the new headless mode of Chrome where some functions
42+
// with callbacks (requestAnimationFrame and requestIdleCallback) are not executing their callbacks.
43+
// https://github.com/puppeteer/puppeteer/issues/10350
44+
if (!this.patchAdded) {
45+
await this.puppeteerPage.exposeFunction('__bringTabToFront', () =>
46+
this.puppeteerPage.bringToFront(),
47+
);
48+
await this.puppeteerPage.evaluateOnNewDocument(() => {
49+
// @ts-ignore
50+
function patchFunction(name, fn) {
51+
// @ts-ignore
52+
window[name] = (...args) => {
53+
fn.call(window, ...args);
54+
// Make sure that the tab running the test code is brought back to the front.
55+
// @ts-ignore
56+
window.__bringTabToFront();
57+
};
58+
}
59+
60+
patchFunction('requestAnimationFrame', window.requestAnimationFrame);
61+
patchFunction('requestIdleCallback', window.requestIdleCallback);
62+
});
63+
this.patchAdded = true;
64+
}
65+
4066
await this.puppeteerPage.setViewport({ height: 600, width: 800 });
4167
await this.puppeteerPage.goto(url);
4268
}

packages/test-runner-chrome/test/chromeLauncher.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ describe('test-runner-chrome', function testRunnerChrome() {
1313
runIntegrationTests(createConfig, {
1414
basic: true,
1515
many: true,
16-
// Focus tests are failing because of a puppeteer/chrome bug.
17-
// See https://github.com/puppeteer/puppeteer/issues/10350 and
18-
// https://bugs.chromium.org/p/chromium/issues/detail?id=1454012
19-
focus: false,
16+
focus: true,
2017
groups: true,
2118
parallel: true,
2219
testFailure: true,

packages/test-runner-puppeteer/test/puppeteerLauncher.test.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@ describe('test-runner-puppeteer', function testRunnerPuppeteer() {
1313
runIntegrationTests(createConfig, {
1414
basic: true,
1515
many: true,
16-
// Focus tests are failing because of a puppeteer/chrome bug.
17-
// See https://github.com/puppeteer/puppeteer/issues/10350 and
18-
// https://bugs.chromium.org/p/chromium/issues/detail?id=1454012
19-
focus: false,
16+
focus: true,
2017
groups: true,
2118
parallel: true,
2219
testFailure: true,

0 commit comments

Comments
 (0)