diff --git a/packages/puppeteer-core/src/cdp/ExecutionContext.ts b/packages/puppeteer-core/src/cdp/ExecutionContext.ts index 31e9deb994a..602da4995d7 100644 --- a/packages/puppeteer-core/src/cdp/ExecutionContext.ts +++ b/packages/puppeteer-core/src/cdp/ExecutionContext.ts @@ -158,6 +158,10 @@ export class ExecutionContext async #onBindingCalled( event: Protocol.Runtime.BindingCalledEvent ): Promise { + if (event.executionContextId !== this.#id) { + return; + } + let payload: BindingPayload; try { payload = JSON.parse(event.payload); @@ -177,10 +181,6 @@ export class ExecutionContext } try { - if (event.executionContextId !== this.#id) { - return; - } - const binding = this.#bindings.get(name); await binding?.run(this, seq, args, isTrivial); } catch (err) { diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts index c0c59d16748..1a8bce40de1 100644 --- a/test/src/page.spec.ts +++ b/test/src/page.spec.ts @@ -1193,6 +1193,22 @@ describe('Page', function () { }); 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 () {