fix(debug): do not generate source urls for anonymous scripts (#3787)
This commit is contained in:
parent
c83b2da54f
commit
74f1a64e36
|
|
@ -410,6 +410,11 @@ export class Frame extends ChannelOwner<channels.FrameChannel, channels.FrameIni
|
||||||
return (await this._channel.title()).value;
|
return (await this._channel.title()).value;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async _extendInjectedScript<Arg>(source: string, arg?: Arg): Promise<JSHandle> {
|
||||||
|
const result = await this._channel.extendInjectedScript({ source, arg: serializeArgument(arg) });
|
||||||
|
return JSHandle.from(result.handle);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function verifyLoadState(name: string, waitUntil: LifecycleEvent): LifecycleEvent {
|
export function verifyLoadState(name: string, waitUntil: LifecycleEvent): LifecycleEvent {
|
||||||
|
|
|
||||||
|
|
@ -22,16 +22,10 @@ import { Progress } from '../server/progress';
|
||||||
import { isDebugMode } from '../utils/utils';
|
import { isDebugMode } from '../utils/utils';
|
||||||
import * as debugScriptSource from '../generated/debugScriptSource';
|
import * as debugScriptSource from '../generated/debugScriptSource';
|
||||||
|
|
||||||
const debugScriptSymbol = Symbol('debugScript');
|
|
||||||
|
|
||||||
export class DebugController implements InstrumentingAgent {
|
export class DebugController implements InstrumentingAgent {
|
||||||
private async ensureInstalledInFrame(frame: frames.Frame) {
|
private async ensureInstalledInFrame(frame: frames.Frame) {
|
||||||
try {
|
try {
|
||||||
const mainContext = await frame._mainContext();
|
await frame.extendInjectedScript(debugScriptSource.source);
|
||||||
if ((mainContext as any)[debugScriptSymbol])
|
|
||||||
return;
|
|
||||||
(mainContext as any)[debugScriptSymbol] = true;
|
|
||||||
await mainContext.extendInjectedScript(debugScriptSource.source);
|
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,8 @@ import type InjectedScript from '../../server/injected/injectedScript';
|
||||||
export default class DebugScript {
|
export default class DebugScript {
|
||||||
consoleAPI: ConsoleAPI | undefined;
|
consoleAPI: ConsoleAPI | undefined;
|
||||||
constructor(injectedScript: InjectedScript) {
|
constructor(injectedScript: InjectedScript) {
|
||||||
|
if ((window as any).playwright)
|
||||||
|
return;
|
||||||
this.consoleAPI = new ConsoleAPI(injectedScript);
|
this.consoleAPI = new ConsoleAPI(injectedScript);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -178,4 +178,8 @@ export class FrameDispatcher extends Dispatcher<Frame, channels.FrameInitializer
|
||||||
async title(): Promise<channels.FrameTitleResult> {
|
async title(): Promise<channels.FrameTitleResult> {
|
||||||
return { value: await this._frame.title() };
|
return { value: await this._frame.title() };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async extendInjectedScript(params: channels.FrameExtendInjectedScriptParams): Promise<channels.FrameExtendInjectedScriptResult> {
|
||||||
|
return { handle: createHandle(this._scope, await this._frame.extendInjectedScript(params.source, parseArgument(params.arg))) };
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1111,6 +1111,7 @@ export interface FrameChannel extends Channel {
|
||||||
uncheck(params: FrameUncheckParams): Promise<FrameUncheckResult>;
|
uncheck(params: FrameUncheckParams): Promise<FrameUncheckResult>;
|
||||||
waitForFunction(params: FrameWaitForFunctionParams): Promise<FrameWaitForFunctionResult>;
|
waitForFunction(params: FrameWaitForFunctionParams): Promise<FrameWaitForFunctionResult>;
|
||||||
waitForSelector(params: FrameWaitForSelectorParams): Promise<FrameWaitForSelectorResult>;
|
waitForSelector(params: FrameWaitForSelectorParams): Promise<FrameWaitForSelectorResult>;
|
||||||
|
extendInjectedScript(params: FrameExtendInjectedScriptParams): Promise<FrameExtendInjectedScriptResult>;
|
||||||
}
|
}
|
||||||
export type FrameLoadstateEvent = {
|
export type FrameLoadstateEvent = {
|
||||||
add?: 'load' | 'domcontentloaded' | 'networkidle',
|
add?: 'load' | 'domcontentloaded' | 'networkidle',
|
||||||
|
|
@ -1510,6 +1511,16 @@ export type FrameWaitForSelectorOptions = {
|
||||||
export type FrameWaitForSelectorResult = {
|
export type FrameWaitForSelectorResult = {
|
||||||
element?: ElementHandleChannel,
|
element?: ElementHandleChannel,
|
||||||
};
|
};
|
||||||
|
export type FrameExtendInjectedScriptParams = {
|
||||||
|
source: string,
|
||||||
|
arg: SerializedArgument,
|
||||||
|
};
|
||||||
|
export type FrameExtendInjectedScriptOptions = {
|
||||||
|
|
||||||
|
};
|
||||||
|
export type FrameExtendInjectedScriptResult = {
|
||||||
|
handle: JSHandleChannel,
|
||||||
|
};
|
||||||
|
|
||||||
// ----------- Worker -----------
|
// ----------- Worker -----------
|
||||||
export type WorkerInitializer = {
|
export type WorkerInitializer = {
|
||||||
|
|
|
||||||
|
|
@ -1242,6 +1242,14 @@ Frame:
|
||||||
returns:
|
returns:
|
||||||
element: ElementHandle?
|
element: ElementHandle?
|
||||||
|
|
||||||
|
extendInjectedScript:
|
||||||
|
experimental: True
|
||||||
|
parameters:
|
||||||
|
source: string
|
||||||
|
arg: SerializedArgument
|
||||||
|
returns:
|
||||||
|
handle: JSHandle
|
||||||
|
|
||||||
events:
|
events:
|
||||||
|
|
||||||
loadstate:
|
loadstate:
|
||||||
|
|
|
||||||
|
|
@ -604,6 +604,10 @@ export function createScheme(tChannel: (name: string) => Validator): Scheme {
|
||||||
timeout: tOptional(tNumber),
|
timeout: tOptional(tNumber),
|
||||||
state: tOptional(tEnum(['attached', 'detached', 'visible', 'hidden'])),
|
state: tOptional(tEnum(['attached', 'detached', 'visible', 'hidden'])),
|
||||||
});
|
});
|
||||||
|
scheme.FrameExtendInjectedScriptParams = tObject({
|
||||||
|
source: tString,
|
||||||
|
arg: tType('SerializedArgument'),
|
||||||
|
});
|
||||||
scheme.WorkerEvaluateExpressionParams = tObject({
|
scheme.WorkerEvaluateExpressionParams = tObject({
|
||||||
expression: tString,
|
expression: tString,
|
||||||
isFunction: tBoolean,
|
isFunction: tBoolean,
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,6 @@ export class FrameExecutionContext extends js.ExecutionContext {
|
||||||
return this._injectedScriptPromise;
|
return this._injectedScriptPromise;
|
||||||
}
|
}
|
||||||
|
|
||||||
async extendInjectedScript(source: string, params?: any) {
|
|
||||||
const injectedScriptHandle = await this.injectedScript();
|
|
||||||
return injectedScriptHandle.evaluate((injectedScript, {source, params}) => {
|
|
||||||
return injectedScript.extend(source, params);
|
|
||||||
}, { source, params });
|
|
||||||
}
|
|
||||||
|
|
||||||
async doSlowMo() {
|
async doSlowMo() {
|
||||||
return this.frame._page._doSlowMo();
|
return this.frame._page._doSlowMo();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -975,6 +975,14 @@ export class Frame extends EventEmitter {
|
||||||
clearTimeout(this._networkIdleTimer);
|
clearTimeout(this._networkIdleTimer);
|
||||||
this._networkIdleTimer = undefined;
|
this._networkIdleTimer = undefined;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async extendInjectedScript(source: string, arg?: any): Promise<js.JSHandle> {
|
||||||
|
const mainContext = await this._mainContext();
|
||||||
|
const injectedScriptHandle = await mainContext.injectedScript();
|
||||||
|
return injectedScriptHandle.evaluateHandle((injectedScript, {source, arg}) => {
|
||||||
|
return injectedScript.extend(source, arg);
|
||||||
|
}, { source, arg });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RerunnableTask {
|
class RerunnableTask {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue