fix: exposed functions should only be called once (#12560)

This commit is contained in:
Alex Rudenko 2024-06-10 14:02:10 +02:00 committed by GitHub
parent 9d0b7e51ce
commit 8aac8b1ccb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 4 deletions

View File

@ -158,6 +158,10 @@ export class ExecutionContext
async #onBindingCalled( async #onBindingCalled(
event: Protocol.Runtime.BindingCalledEvent event: Protocol.Runtime.BindingCalledEvent
): Promise<void> { ): Promise<void> {
if (event.executionContextId !== this.#id) {
return;
}
let payload: BindingPayload; let payload: BindingPayload;
try { try {
payload = JSON.parse(event.payload); payload = JSON.parse(event.payload);
@ -177,10 +181,6 @@ export class ExecutionContext
} }
try { try {
if (event.executionContextId !== this.#id) {
return;
}
const binding = this.#bindings.get(name); const binding = this.#bindings.get(name);
await binding?.run(this, seq, args, isTrivial); await binding?.run(this, seq, args, isTrivial);
} catch (err) { } catch (err) {

View File

@ -1193,6 +1193,22 @@ describe('Page', function () {
}); });
expect(result).toBe(36); expect(result).toBe(36);
}); });
it('should be called once', async () => {
const {page, server} = await getTestState();
await page.goto(server.PREFIX + '/frames/nested-frames.html');
let calls = 0;
await page.exposeFunction('call', function () {
calls++;
});
const frame = page.frames()[1]!;
await frame.evaluate(async function () {
return (globalThis as any).call();
});
expect(calls).toBe(1);
});
}); });
describe('Page.removeExposedFunction', function () { describe('Page.removeExposedFunction', function () {