Fix auto-enable to work without delay by skipping duplicate Target.attachedToTarget

Move auto-create logic from onOpen to Target.setAutoAttach handler so it runs
synchronously in the CDP command flow. Add skipAttachedEvent option to extension's
attachTab to prevent sending Target.attachedToTarget when the relay will send it
via the Target.setAutoAttach response handler.
This commit is contained in:
Tommy D. Rossi
2026-01-01 02:53:10 +01:00
parent 002f72af2c
commit ef6ab59351
3 changed files with 80 additions and 43 deletions
+1 -3
View File
@@ -2924,12 +2924,10 @@ describe('Auto-enable Tests', () => {
// Connect Playwright - this should trigger auto-create
const browser = await chromium.connectOverCDP(getCdpUrl({ port: TEST_PORT }))
// Wait for auto-create to complete (async onOpen may not be fully awaited)
await new Promise(r => setTimeout(r, 500))
// Verify a page was auto-created
const pages = browser.contexts()[0].pages()
expect(pages.length).toBeGreaterThan(0)
expect(pages.length).toBe(1)
const autoCreatedPage = pages[0]
expect(autoCreatedPage.url()).toBe('about:blank')