mirror of
https://github.com/puppeteer/puppeteer
synced 2024-06-14 14:02:48 +00:00
feat: support running Puppeteer in extensions (#12459)
This commit is contained in:
@@ -30,7 +30,7 @@ const pageTargetInfo = {
|
||||
* implements missing commands and events.
|
||||
*
|
||||
* @experimental
|
||||
* @internal
|
||||
* @public
|
||||
*/
|
||||
export class ExtensionTransport implements ConnectionTransport {
|
||||
static async connectTab(tabId: number): Promise<ExtensionTransport> {
|
||||
@@ -178,5 +178,6 @@ export class ExtensionTransport implements ConnectionTransport {
|
||||
|
||||
close(): void {
|
||||
chrome.debugger.onEvent.removeListener(this.#debuggerEventHandler);
|
||||
void chrome.debugger.detach({tabId: this.#tabId});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,16 @@ export function stringifyFunction(fn: (...args: never) => unknown): string {
|
||||
let value = fn.toString();
|
||||
try {
|
||||
new Function(`(${value})`);
|
||||
} catch {
|
||||
} catch (err) {
|
||||
if (
|
||||
(err as Error).message.includes(
|
||||
`Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive`
|
||||
)
|
||||
) {
|
||||
// The content security policy does not allow Function eval. Let's
|
||||
// assume the value might be valid as is.
|
||||
return value;
|
||||
}
|
||||
// This means we might have a function shorthand (e.g. `test(){}`). Let's
|
||||
// try prefixing.
|
||||
let prefix = 'function ';
|
||||
|
||||
Reference in New Issue
Block a user