fix(domworld): fix waitfor bindings (#6766) (#6775)

* fix(domworld): fix waitfor bindings (#6766)

Co-authored-by: Johan Bay <jobay@google.com>
This commit is contained in:
Jan Scheffler 2021-01-25 13:01:59 +01:00 committed by GitHub
parent 15bc900be0
commit cac540be3a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 1 deletions

View File

@ -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) {

View File

@ -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;
}
/**

View File

@ -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);