fix: expose function for Firefox BiDi (#11660)

This commit is contained in:
Nikolay Vitkov 2024-01-11 12:08:21 +01:00 committed by GitHub
parent 5f91f1e472
commit cf879b82f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 72 additions and 93 deletions

View File

@ -66,7 +66,6 @@ export class ExposeableFunction<Args extends unknown[], Ret> {
async expose(): Promise<void> { async expose(): Promise<void> {
const connection = this.#connection; const connection = this.#connection;
const channelArguments = this.#channelArguments; const channelArguments = this.#channelArguments;
const {name} = this;
// TODO(jrandolf): Implement cleanup with removePreloadScript. // TODO(jrandolf): Implement cleanup with removePreloadScript.
connection.on( connection.on(
@ -103,7 +102,7 @@ export class ExposeableFunction<Args extends unknown[], Ret> {
}, },
}); });
}, },
{name: JSON.stringify(name)} {name: JSON.stringify(this.name)}
) )
); );
@ -148,7 +147,9 @@ export class ExposeableFunction<Args extends unknown[], Ret> {
BidiSerializer.serializeRemoteValue(result), BidiSerializer.serializeRemoteValue(result),
], ],
awaitPromise: false, awaitPromise: false,
target: params.source, target: {
realm: params.source.realm,
},
}); });
} catch (error) { } catch (error) {
try { try {
@ -156,7 +157,7 @@ export class ExposeableFunction<Args extends unknown[], Ret> {
await connection.send('script.callFunction', { await connection.send('script.callFunction', {
functionDeclaration: stringifyFunction( functionDeclaration: stringifyFunction(
( (
[_, reject]: any, [_, reject]: [unknown, (error: Error) => void],
name: string, name: string,
message: string, message: string,
stack?: string stack?: string
@ -176,12 +177,17 @@ export class ExposeableFunction<Args extends unknown[], Ret> {
BidiSerializer.serializeRemoteValue(error.stack), BidiSerializer.serializeRemoteValue(error.stack),
], ],
awaitPromise: false, awaitPromise: false,
target: params.source, target: {
realm: params.source.realm,
},
}); });
} else { } else {
await connection.send('script.callFunction', { await connection.send('script.callFunction', {
functionDeclaration: stringifyFunction( functionDeclaration: stringifyFunction(
([_, reject]: any, error: unknown) => { (
[_, reject]: [unknown, (error: unknown) => void],
error: unknown
) => {
reject(error); reject(error);
} }
), ),
@ -190,7 +196,9 @@ export class ExposeableFunction<Args extends unknown[], Ret> {
BidiSerializer.serializeRemoteValue(error), BidiSerializer.serializeRemoteValue(error),
], ],
awaitPromise: false, awaitPromise: false,
target: params.source, target: {
realm: params.source.realm,
},
}); });
} }
} catch (error) { } catch (error) {

View File

@ -927,7 +927,7 @@
{ {
"testIdPattern": "[page.spec] Page Page.exposeFunction *", "testIdPattern": "[page.spec] Page Page.exposeFunction *",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
"parameters": ["firefox", "webDriverBiDi"], "parameters": ["cdp", "firefox"],
"expectations": ["SKIP"] "expectations": ["SKIP"]
}, },
{ {
@ -1279,6 +1279,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[browser.spec] Browser specs Browser.process should not return child_process for remote browser",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1813,12 +1819,6 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["SKIP"] "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", "testIdPattern": "[extensions.spec] extensions background_page target type should be available",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1963,6 +1963,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[ignorehttpserrors.spec] ignoreHTTPSErrors should work with mixed content",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -1975,6 +1981,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[ignorehttpserrors.spec] ignoreHTTPSErrors should work with request interception",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2059,6 +2071,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[launcher.spec] Launcher specs Puppeteer Browser.disconnect should reject navigation when browser closes",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2774,6 +2792,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[oopif.spec] OOPIF should support wait for navigation for transitions from local to OOPIF",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -2972,89 +2996,11 @@
"parameters": ["cdp", "firefox"], "parameters": ["cdp", "firefox"],
"expectations": ["SKIP"] "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", "testIdPattern": "[page.spec] Page Page.exposeFunction should be callable from-inside evaluateOnNewDocument",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["FAIL", "TIMEOUT"] "expectations": ["FAIL"]
},
{
"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"]
}, },
{ {
"testIdPattern": "[page.spec] Page Page.metrics metrics event fired on console.timeStamp", "testIdPattern": "[page.spec] Page Page.metrics metrics event fired on console.timeStamp",
@ -3656,6 +3602,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[worker.spec] Workers should report errors",
"platforms": ["darwin", "linux", "win32"], "platforms": ["darwin", "linux", "win32"],
@ -3668,6 +3620,12 @@
"parameters": ["chrome", "webDriverBiDi"], "parameters": ["chrome", "webDriverBiDi"],
"expectations": ["PASS"] "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", "testIdPattern": "[CDPSession.spec] Target.createCDPSession should send events",
"platforms": ["win32"], "platforms": ["win32"],

View File

@ -1154,6 +1154,19 @@ describe('Page', function () {
}); });
expect(result).toBe(15); 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 () => { it('should work on frames', async () => {
const {page, server} = await getTestState(); const {page, server} = await getTestState();