Skip to content

Commit 79b0ba4

Browse files
committed
fix(test-runner-chrome): remove focus browser patches
The patches were added quite a while ago, and the upstream issues should be resolved in Chromium. See: https://issues.chromium.org/issues/40272146. Also see: puppeteer/puppeteer#10350 (comment). The patches are currently also resulting some instability of web test runner. That is because the patch calls an exposed function from inside the browser, while navigation later on during `stopSession` can happen; breaking the handle for retrieving function call arguments passed to the exposed function. Puppeteer team found this issue and also landed a fix to improve the failure mode here. See: puppeteer/puppeteer#13759
1 parent dbd418f commit 79b0ba4

File tree

4 files changed

+22
-51
lines changed

4 files changed

+22
-51
lines changed

.changeset/kind-schools-rule.md

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
---
2+
'@web/test-runner-chrome': patch
3+
---
4+
5+
This changeset removes the Puppeteer/Chrome focus browser patches that shouldn't
6+
be needed anymore, and can cause instability.
7+
8+
The patches were added quite a while ago, and the upstream issues should
9+
be resolved in Chromium. See: https://issues.chromium.org/issues/40272146.
10+
11+
Also see:
12+
https://github.com/puppeteer/puppeteer/issues/10350#issuecomment-1586858101.
13+
14+
The patches are currently also resulting some instability of web test
15+
runner. That is because the patch calls an exposed function from inside
16+
the browser, while navigation later on during `stopSession` can happen;
17+
breaking the handle for retrieving function call arguments passed to the
18+
exposed function.
19+
20+
Puppeteer team found this issue and also landed a fix to improve the
21+
failure mode here. See:
22+
https://github.com/puppeteer/puppeteer/pull/13759

package-lock.json

-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/test-runner-chrome/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
"dependencies": {
4949
"@web/test-runner-core": "^0.13.0",
5050
"@web/test-runner-coverage-v8": "^0.8.0",
51-
"async-mutex": "0.4.0",
5251
"chrome-launcher": "^0.15.0",
5352
"puppeteer-core": "^24.0.0"
5453
},

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

-40
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@ import { Page, JSCoverageEntry } from 'puppeteer-core';
22
import { TestRunnerCoreConfig } from '@web/test-runner-core';
33
import { v8ToIstanbul } from '@web/test-runner-coverage-v8';
44
import { SessionResult } from '@web/test-runner-core';
5-
import { Mutex } from 'async-mutex';
6-
7-
const mutex = new Mutex();
85

96
declare global {
107
interface Window {
@@ -49,43 +46,6 @@ export class ChromeLauncherPage {
4946
});
5047
}
5148

52-
// Patching the browser page to workaround an issue in the new headless mode of Chrome where some functions
53-
// with callbacks (requestAnimationFrame and requestIdleCallback) are not executing their callbacks.
54-
// https://github.com/puppeteer/puppeteer/issues/10350
55-
if (!this.patchAdded) {
56-
await this.puppeteerPage.exposeFunction('__bringTabToFront', (id: string) => {
57-
const promise = new Promise(resolve => {
58-
this.resolvers[id] = resolve as () => void;
59-
});
60-
return mutex.runExclusive(async () => {
61-
await this.puppeteerPage.bringToFront();
62-
await promise;
63-
});
64-
});
65-
await this.puppeteerPage.exposeFunction('__releaseLock', (id: string) => {
66-
this.resolvers[id]?.();
67-
});
68-
await this.puppeteerPage.evaluateOnNewDocument(() => {
69-
// eslint-disable-next-line @typescript-eslint/ban-types
70-
function patchFunction(name: string, fn: Function) {
71-
(window as any)[name] = (...args: unknown[]) => {
72-
const result = fn.call(window, ...args);
73-
const id = Math.random().toString().substring(2);
74-
// Make sure that the tab running the test code is brought back to the front.
75-
window.__bringTabToFront(id);
76-
fn.call(window, () => {
77-
window.__releaseLock(id);
78-
});
79-
return result;
80-
};
81-
}
82-
83-
patchFunction('requestAnimationFrame', window.requestAnimationFrame);
84-
patchFunction('requestIdleCallback', window.requestIdleCallback);
85-
});
86-
this.patchAdded = true;
87-
}
88-
8949
await this.puppeteerPage.setViewport({ height: 600, width: 800 });
9050
await this.puppeteerPage.goto(url);
9151
}

0 commit comments

Comments
 (0)