chore: add evaluateOnNewDocument for BiDi (#10712)
This commit is contained in:
parent
f70048c84f
commit
47dfc3578d
@ -47,6 +47,10 @@ interface Commands {
|
||||
params: Bidi.Script.AddPreloadScriptParameters;
|
||||
returnType: Bidi.Script.AddPreloadScriptResult;
|
||||
};
|
||||
'script.removePreloadScript': {
|
||||
params: Bidi.Script.RemovePreloadScriptParameters;
|
||||
returnType: Bidi.EmptyResult;
|
||||
};
|
||||
|
||||
'browsingContext.activate': {
|
||||
params: Bidi.BrowsingContext.ActivateParameters;
|
||||
|
@ -22,6 +22,7 @@ import Protocol from 'devtools-protocol';
|
||||
import {
|
||||
GeolocationOptions,
|
||||
MediaFeature,
|
||||
NewDocumentScriptEvaluation,
|
||||
Page as PageBase,
|
||||
PageEmittedEvents,
|
||||
ScreenshotOptions,
|
||||
@ -45,6 +46,7 @@ import {Tracing} from '../Tracing.js';
|
||||
import {EvaluateFunc, HandleFor} from '../types.js';
|
||||
import {
|
||||
debugError,
|
||||
evaluationString,
|
||||
isString,
|
||||
validateDialogType,
|
||||
waitForEvent,
|
||||
@ -726,6 +728,30 @@ export class Page extends PageBase {
|
||||
context: this.mainFrame()._id,
|
||||
});
|
||||
}
|
||||
|
||||
override async evaluateOnNewDocument<
|
||||
Params extends unknown[],
|
||||
Func extends (...args: Params) => unknown = (...args: Params) => unknown,
|
||||
>(
|
||||
pageFunction: Func | string,
|
||||
...args: Params
|
||||
): Promise<NewDocumentScriptEvaluation> {
|
||||
const expression = evaluationExpression(pageFunction, ...args);
|
||||
const {result} = await this.#connection.send('script.addPreloadScript', {
|
||||
functionDeclaration: expression,
|
||||
// TODO: should change spec to accept browsingContext
|
||||
});
|
||||
|
||||
return {identifier: result.script};
|
||||
}
|
||||
|
||||
override async removeScriptToEvaluateOnNewDocument(
|
||||
id: string
|
||||
): Promise<void> {
|
||||
await this.#connection.send('script.removePreloadScript', {
|
||||
script: id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
function isConsoleLogEntry(
|
||||
@ -755,3 +781,7 @@ function getStackTraceLocations(
|
||||
}
|
||||
return stackTraceLocations;
|
||||
}
|
||||
|
||||
function evaluationExpression(fun: Function | string, ...args: unknown[]) {
|
||||
return `() => {${evaluationString(fun, ...args)}}`;
|
||||
}
|
||||
|
@ -4150,5 +4150,17 @@
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["cdp", "chrome", "headless"],
|
||||
"expectations": ["FAIL", "PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should evaluate before anything else on the page",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["webDriverBiDi"],
|
||||
"expectations": ["PASS"]
|
||||
},
|
||||
{
|
||||
"testIdPattern": "[evaluation.spec] Evaluation specs Page.evaluateOnNewDocument should work with CSP",
|
||||
"platforms": ["darwin", "linux", "win32"],
|
||||
"parameters": ["webDriverBiDi"],
|
||||
"expectations": ["PASS"]
|
||||
}
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user