diff --git a/packages/puppeteer-core/src/bidi/ExposedFunction.ts b/packages/puppeteer-core/src/bidi/ExposedFunction.ts index d385ffedbb0..62c6b5e37ef 100644 --- a/packages/puppeteer-core/src/bidi/ExposedFunction.ts +++ b/packages/puppeteer-core/src/bidi/ExposedFunction.ts @@ -66,7 +66,6 @@ export class ExposeableFunction { async expose(): Promise { const connection = this.#connection; const channelArguments = this.#channelArguments; - const {name} = this; // TODO(jrandolf): Implement cleanup with removePreloadScript. connection.on( @@ -103,7 +102,7 @@ export class ExposeableFunction { }, }); }, - {name: JSON.stringify(name)} + {name: JSON.stringify(this.name)} ) ); @@ -148,7 +147,9 @@ export class ExposeableFunction { BidiSerializer.serializeRemoteValue(result), ], awaitPromise: false, - target: params.source, + target: { + realm: params.source.realm, + }, }); } catch (error) { try { @@ -156,7 +157,7 @@ export class ExposeableFunction { await connection.send('script.callFunction', { functionDeclaration: stringifyFunction( ( - [_, reject]: any, + [_, reject]: [unknown, (error: Error) => void], name: string, message: string, stack?: string @@ -176,12 +177,17 @@ export class ExposeableFunction { BidiSerializer.serializeRemoteValue(error.stack), ], awaitPromise: false, - target: params.source, + target: { + realm: params.source.realm, + }, }); } else { await connection.send('script.callFunction', { functionDeclaration: stringifyFunction( - ([_, reject]: any, error: unknown) => { + ( + [_, reject]: [unknown, (error: unknown) => void], + error: unknown + ) => { reject(error); } ), @@ -190,7 +196,9 @@ export class ExposeableFunction { BidiSerializer.serializeRemoteValue(error), ], awaitPromise: false, - target: params.source, + target: { + realm: params.source.realm, + }, }); } } catch (error) { diff --git a/test/TestExpectations.json b/test/TestExpectations.json index f4296efbbe8..7cb77a637e4 100644 --- a/test/TestExpectations.json +++ b/test/TestExpectations.json @@ -927,7 +927,7 @@ { "testIdPattern": "[page.spec] Page Page.exposeFunction *", "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], + "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, { @@ -1279,6 +1279,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[browser.spec] Browser specs Browser.isConnected should set the browser connected state", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[browser.spec] Browser specs Browser.process should not return child_process for remote browser", "platforms": ["darwin", "linux", "win32"], @@ -1813,12 +1819,6 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, - { - "testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluate should work from-inside an exposed function", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], - "expectations": ["FAIL", "TIMEOUT"] - }, { "testIdPattern": "[extensions.spec] extensions background_page target type should be available", "platforms": ["darwin", "linux", "win32"], @@ -1963,6 +1963,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[ignorehttpserrors.spec] ignoreHTTPSErrors should work", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[ignorehttpserrors.spec] ignoreHTTPSErrors should work with mixed content", "platforms": ["darwin", "linux", "win32"], @@ -1975,6 +1981,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[ignorehttpserrors.spec] ignoreHTTPSErrors should work with mixed content", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[ignorehttpserrors.spec] ignoreHTTPSErrors should work with request interception", "platforms": ["darwin", "linux", "win32"], @@ -2059,6 +2071,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.close should terminate network waiters", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect should reject navigation when browser closes", "platforms": ["darwin", "linux", "win32"], @@ -2774,6 +2792,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[oopif.spec] OOPIF should support lazy OOP frames", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[oopif.spec] OOPIF should support wait for navigation for transitions from local to OOPIF", "platforms": ["darwin", "linux", "win32"], @@ -2972,89 +2996,11 @@ "parameters": ["cdp", "firefox"], "expectations": ["SKIP"] }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should await returned promise", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, { "testIdPattern": "[page.spec] Page Page.exposeFunction should be callable from-inside evaluateOnNewDocument", "platforms": ["darwin", "linux", "win32"], "parameters": ["chrome", "webDriverBiDi"], - "expectations": ["FAIL", "TIMEOUT"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should be callable from-inside evaluateOnNewDocument", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should be callable from-inside evaluateOnNewDocument", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["firefox", "webDriverBiDi"], - "expectations": ["PASS"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should fallback to default export when passed a module object", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should not throw when frames detach", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should support throwing \"null\"", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should survive navigation", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should throw exception in page context", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should work", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should work on frames", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should work on frames before navigation", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should work with complex objects", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] - }, - { - "testIdPattern": "[page.spec] Page Page.exposeFunction should work with loading frames", - "platforms": ["darwin", "linux", "win32"], - "parameters": ["cdp", "firefox"], - "expectations": ["SKIP"] + "expectations": ["FAIL"] }, { "testIdPattern": "[page.spec] Page Page.metrics metrics event fired on console.timeStamp", @@ -3656,6 +3602,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[worker.spec] Workers should report console logs", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[worker.spec] Workers should report errors", "platforms": ["darwin", "linux", "win32"], @@ -3668,6 +3620,12 @@ "parameters": ["chrome", "webDriverBiDi"], "expectations": ["PASS"] }, + { + "testIdPattern": "[worker.spec] Workers should report errors", + "platforms": ["darwin", "linux", "win32"], + "parameters": ["chrome", "webDriverBiDi"], + "expectations": ["PASS"] + }, { "testIdPattern": "[CDPSession.spec] Target.createCDPSession should send events", "platforms": ["win32"], diff --git a/test/src/page.spec.ts b/test/src/page.spec.ts index cdee6ace650..3fda53c7763 100644 --- a/test/src/page.spec.ts +++ b/test/src/page.spec.ts @@ -1154,6 +1154,19 @@ describe('Page', function () { }); expect(result).toBe(15); }); + it('should await returned if called from function', async () => { + const {page} = await getTestState(); + + await page.exposeFunction('compute', function (a: number, b: number) { + return Promise.resolve(a * b); + }); + + const result = await page.evaluate(async function () { + const result = await (globalThis as any).compute(3, 5); + return result; + }); + expect(result).toBe(15); + }); it('should work on frames', async () => { const {page, server} = await getTestState();