mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
fix: exposed functions should only be called once (#12560)
This commit is contained in:
parent
9d0b7e51ce
commit
8aac8b1ccb
@ -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) {
|
||||||
|
@ -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 () {
|
||||||
|
Loading…
Reference in New Issue
Block a user