fix(electron): flaky startup if stderr comes in too fast (#30855)
Chromium's `DevTools listening on` message sometimes arrives before Playwright is finished connecting to Node. Without this patch, it would miss the message and fail to connect.
This commit is contained in:
parent
68abd36464
commit
d0644f5444
|
|
@ -229,6 +229,8 @@ export class Electron extends SdkObject {
|
||||||
onExit: () => app?.emit(ElectronApplication.Events.Close),
|
onExit: () => app?.emit(ElectronApplication.Events.Close),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// All waitForLines must be started immediately.
|
||||||
|
// Otherwise the lines might come before we are ready.
|
||||||
const waitForXserverError = new Promise(async (resolve, reject) => {
|
const waitForXserverError = new Promise(async (resolve, reject) => {
|
||||||
waitForLine(progress, launchedProcess, /Unable to open X display/).then(() => reject(new Error([
|
waitForLine(progress, launchedProcess, /Unable to open X display/).then(() => reject(new Error([
|
||||||
'Unable to open X display!',
|
'Unable to open X display!',
|
||||||
|
|
@ -240,17 +242,20 @@ export class Electron extends SdkObject {
|
||||||
progress.metadata.log
|
progress.metadata.log
|
||||||
].join('\n')))).catch(() => {});
|
].join('\n')))).catch(() => {});
|
||||||
});
|
});
|
||||||
|
const nodeMatchPromise = waitForLine(progress, launchedProcess, /^Debugger listening on (ws:\/\/.*)$/);
|
||||||
|
const chromeMatchPromise = waitForLine(progress, launchedProcess, /^DevTools listening on (ws:\/\/.*)$/);
|
||||||
|
const debuggerDisconnectPromise = waitForLine(progress, launchedProcess, /Waiting for the debugger to disconnect\.\.\./);
|
||||||
|
|
||||||
const nodeMatch = await waitForLine(progress, launchedProcess, /^Debugger listening on (ws:\/\/.*)$/);
|
const nodeMatch = await nodeMatchPromise;
|
||||||
const nodeTransport = await WebSocketTransport.connect(progress, nodeMatch[1]);
|
const nodeTransport = await WebSocketTransport.connect(progress, nodeMatch[1]);
|
||||||
const nodeConnection = new CRConnection(nodeTransport, helper.debugProtocolLogger(), browserLogsCollector);
|
const nodeConnection = new CRConnection(nodeTransport, helper.debugProtocolLogger(), browserLogsCollector);
|
||||||
|
|
||||||
// Immediately release exiting process under debug.
|
// Immediately release exiting process under debug.
|
||||||
waitForLine(progress, launchedProcess, /Waiting for the debugger to disconnect\.\.\./).then(() => {
|
debuggerDisconnectPromise.then(() => {
|
||||||
nodeTransport.close();
|
nodeTransport.close();
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
const chromeMatch = await Promise.race([
|
const chromeMatch = await Promise.race([
|
||||||
waitForLine(progress, launchedProcess, /^DevTools listening on (ws:\/\/.*)$/),
|
chromeMatchPromise,
|
||||||
waitForXserverError,
|
waitForXserverError,
|
||||||
]) as RegExpMatchArray;
|
]) as RegExpMatchArray;
|
||||||
const chromeTransport = await WebSocketTransport.connect(progress, chromeMatch[1]);
|
const chromeTransport = await WebSocketTransport.connect(progress, chromeMatch[1]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue