Skip to content

Commit bf6141e

Browse files
committed
fix(chromium): wait for existing patches when connecting
1 parent 2ea465b commit bf6141e

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

src/server/chromium/crBrowser.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,16 @@ export class CRBrowser extends Browser {
6161
return browser;
6262
}
6363
browser._defaultContext = new CRBrowserContext(browser, undefined, options.persistent);
64-
6564
await Promise.all([
66-
session.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }),
65+
session.send('Target.setAutoAttach', { autoAttach: true, waitForDebuggerOnStart: true, flatten: true }).then(async () => {
66+
// Target.setAutoAttach has a bug where it does not wait for new Targets being attached.
67+
// However making a dummy call afterwards fixes this.
68+
// This can be removed after https://chromium-review.googlesource.com/c/chromium/src/+/2885888 lands in stable.
69+
await session.send('Target.getTargetInfo');
70+
}),
6771
(browser._defaultContext as CRBrowserContext)._initialize(),
6872
]);
69-
73+
await browser._waitForAllPagesToBeInitialized();
7074
return browser;
7175
}
7276

@@ -104,6 +108,10 @@ export class CRBrowser extends Browser {
104108
return this.options.name === 'clank';
105109
}
106110

111+
async _waitForAllPagesToBeInitialized() {
112+
await Promise.all([...this._crPages.values()].map(page => page.pageOrError()));
113+
}
114+
107115
_onAttachedToTarget({targetInfo, sessionId, waitingForDebugger}: Protocol.Target.attachedToTargetPayload) {
108116
if (targetInfo.type === 'browser')
109117
return;

tests/chromium/chromium.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,6 @@ playwrightTest('should send extra headers with connect request', async ({browser
240240
});
241241

242242
playwrightTest('should report all pages in an existing browser', async ({ browserType, browserOptions }, testInfo) => {
243-
playwrightTest.fail();
244243
const port = 9339 + testInfo.workerIndex;
245244
const browserServer = await browserType.launch({
246245
...browserOptions,

0 commit comments

Comments
 (0)