mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
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;
|
params: Bidi.Script.AddPreloadScriptParameters;
|
||||||
returnType: Bidi.Script.AddPreloadScriptResult;
|
returnType: Bidi.Script.AddPreloadScriptResult;
|
||||||
};
|
};
|
||||||
|
'script.removePreloadScript': {
|
||||||
|
params: Bidi.Script.RemovePreloadScriptParameters;
|
||||||
|
returnType: Bidi.EmptyResult;
|
||||||
|
};
|
||||||
|
|
||||||
'browsingContext.activate': {
|
'browsingContext.activate': {
|
||||||
params: Bidi.BrowsingContext.ActivateParameters;
|
params: Bidi.BrowsingContext.ActivateParameters;
|
||||||
|
@ -22,6 +22,7 @@ import Protocol from 'devtools-protocol';
|
|||||||
import {
|
import {
|
||||||
GeolocationOptions,
|
GeolocationOptions,
|
||||||
MediaFeature,
|
MediaFeature,
|
||||||
|
NewDocumentScriptEvaluation,
|
||||||
Page as PageBase,
|
Page as PageBase,
|
||||||
PageEmittedEvents,
|
PageEmittedEvents,
|
||||||
ScreenshotOptions,
|
ScreenshotOptions,
|
||||||
@ -45,6 +46,7 @@ import {Tracing} from '../Tracing.js';
|
|||||||
import {EvaluateFunc, HandleFor} from '../types.js';
|
import {EvaluateFunc, HandleFor} from '../types.js';
|
||||||
import {
|
import {
|
||||||
debugError,
|
debugError,
|
||||||
|
evaluationString,
|
||||||
isString,
|
isString,
|
||||||
validateDialogType,
|
validateDialogType,
|
||||||
waitForEvent,
|
waitForEvent,
|
||||||
@ -726,6 +728,30 @@ export class Page extends PageBase {
|
|||||||
context: this.mainFrame()._id,
|
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(
|
function isConsoleLogEntry(
|
||||||
@ -755,3 +781,7 @@ function getStackTraceLocations(
|
|||||||
}
|
}
|
||||||
return stackTraceLocations;
|
return stackTraceLocations;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function evaluationExpression(fun: Function | string, ...args: unknown[]) {
|
||||||
|
return `() => {${evaluationString(fun, ...args)}}`;
|
||||||
|
}
|
||||||
|
@ -4150,5 +4150,17 @@
|
|||||||
"platforms": ["darwin", "linux", "win32"],
|
"platforms": ["darwin", "linux", "win32"],
|
||||||
"parameters": ["cdp", "chrome", "headless"],
|
"parameters": ["cdp", "chrome", "headless"],
|
||||||
"expectations": ["FAIL", "PASS"]
|
"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