fix Runtime.enable race condition with event-based synchronization

Replace arbitrary sleep(200ms) with proper wait for Runtime.executionContextCreated
event in the relay server. This ensures pages are fully ready before Runtime.enable
returns to Playwright, fixing intermittent 'page not found' errors.
This commit is contained in:
Tommy D. Rossi
2025-12-28 15:16:17 +01:00
parent cb2c14b874
commit 98b3986062
4 changed files with 165 additions and 14 deletions
+2 -10
View File
@@ -232,7 +232,7 @@ async function handleCommand(msg: ExtensionCommandMessage): Promise<any> {
}
try {
await chrome.debugger.sendCommand(debuggee, 'Runtime.disable')
await sleep(400)
await sleep(200)
} catch (e) {
logger.debug('Error disabling Runtime (ignoring):', e)
}
@@ -507,15 +507,7 @@ function handleConnectionClose(reason: string, code: number): void {
return
}
store.setState((state) => {
const newTabs = new Map(state.tabs)
for (const [tabId, tab] of newTabs) {
if (tab.state === 'connected') {
newTabs.set(tabId, { ...tab, state: 'connecting' })
}
}
return { tabs: newTabs, connectionState: 'disconnected', errorText: undefined }
})
store.setState({ connectionState: 'disconnected', errorText: undefined })
if (tabs.size > 0) {
logger.debug('Tabs still connected, triggering reconnection')