From cac540be3ab8799a1d77b0951b16bc22ea1c2adb Mon Sep 17 00:00:00 2001 From: Jan Scheffler Date: Mon, 25 Jan 2021 13:01:59 +0100 Subject: [PATCH] fix(domworld): fix waitfor bindings (#6766) (#6775) * fix(domworld): fix waitfor bindings (#6766) Co-authored-by: Johan Bay --- src/common/DOMWorld.ts | 5 ++++- src/common/ExecutionContext.ts | 5 +++++ test/ariaqueryhandler.spec.ts | 10 ++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/common/DOMWorld.ts b/src/common/DOMWorld.ts index ae74ab9caf7..d087349401f 100644 --- a/src/common/DOMWorld.ts +++ b/src/common/DOMWorld.ts @@ -512,9 +512,12 @@ export class DOMWorld { const bind = async (name: string) => { const expression = helper.pageBindingInitString('internal', name); try { + // TODO: In theory, it would be enough to call this just once await context._client.send('Runtime.addBinding', { name, - executionContextId: context._contextId, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore The protocol definition is not up to date. + executionContextName: context._contextName, }); await context.evaluate(expression); } catch (error) { diff --git a/src/common/ExecutionContext.ts b/src/common/ExecutionContext.ts index 4420410de05..d393e9b3623 100644 --- a/src/common/ExecutionContext.ts +++ b/src/common/ExecutionContext.ts @@ -56,6 +56,10 @@ export class ExecutionContext { * @internal */ _contextId: number; + /** + * @internal + */ + _contextName: string; /** * @internal @@ -68,6 +72,7 @@ export class ExecutionContext { this._client = client; this._world = world; this._contextId = contextPayload.id; + this._contextName = contextPayload.name; } /** diff --git a/test/ariaqueryhandler.spec.ts b/test/ariaqueryhandler.spec.ts index 83f78fd611c..93e2a9f2334 100644 --- a/test/ariaqueryhandler.spec.ts +++ b/test/ariaqueryhandler.spec.ts @@ -185,6 +185,16 @@ describeChromeOnly('AriaQueryHandler', () => { await page.waitForSelector('aria/[role="button"]'); }); + it('should persist query handler bindings across reloads', async () => { + const { page, server } = getTestState(); + await page.goto(server.EMPTY_PAGE); + await page.evaluate(addElement, 'button'); + await page.waitForSelector('aria/[role="button"]'); + await page.reload(); + 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);