Skip to content

Commit

Permalink
fix(domworld): fix waitfor bindings (#6766) (#6775)
Browse files Browse the repository at this point in the history
* fix(domworld): fix waitfor bindings (#6766)

Co-authored-by: Johan Bay <jobay@google.com>
  • Loading branch information
jschfflr and johanbay committed Jan 25, 2021
1 parent 15bc900 commit cac540b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/common/DOMWorld.ts
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions src/common/ExecutionContext.ts
Expand Up @@ -56,6 +56,10 @@ export class ExecutionContext {
* @internal
*/
_contextId: number;
/**
* @internal
*/
_contextName: string;

/**
* @internal
Expand All @@ -68,6 +72,7 @@ export class ExecutionContext {
this._client = client;
this._world = world;
this._contextId = contextPayload.id;
this._contextName = contextPayload.name;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions test/ariaqueryhandler.spec.ts
Expand Up @@ -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);
Expand Down

0 comments on commit cac540b

Please sign in to comment.