diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index d087349401fe3..02b42cac0dd64 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -115,6 +115,7 @@ export class DOMWorld { async _setContext(context?: ExecutionContext): Promise { if (context) { + this._ctxBindings = new Set(); this._contextResolveCallback.call(null, context); this._contextResolveCallback = null; for (const waitTask of this._waitTasks) waitTask.rerun(); diff --git a/test/ariaqueryhandler.spec.ts b/test/ariaqueryhandler.spec.ts index 576dedf2623bb..026047fc9ae80 100644 --- a/test/ariaqueryhandler.spec.ts +++ b/test/ariaqueryhandler.spec.ts @@ -195,6 +195,22 @@ describeChromeOnly('AriaQueryHandler', () => { await page.waitForSelector('aria/[role="button"]'); }); + it('should persist query handler bindings across navigations', async () => { + const { page, server } = getTestState(); + + // Reset page but make sure that execution context ids start with 1. + await page.goto('data:text/html,'); + await page.goto(server.EMPTY_PAGE); + await page.evaluate(addElement, 'button'); + await page.waitForSelector('aria/[role="button"]'); + + // Reset page but again make sure that execution context ids start with 1. + await page.goto('data:text/html,'); + await page.goto(server.EMPTY_PAGE); + await page.evaluate(addElement, 'button'); + await page.waitForSelector('aria/[role="button"]'); + }); + it('should work independently of `exposeFunction`', async () => { const { page, server } = getTestState(); await page.goto(server.EMPTY_PAGE);