fix(codegen): move injected recorder scripts to utility world (#6187)
This commit is contained in:
parent
b52cbfdb16
commit
345f7da573
|
|
@ -100,7 +100,7 @@ export class BrowserContextDispatcher extends Dispatcher<BrowserContext, channel
|
|||
const binding = new BindingCallDispatcher(this._scope, params.name, !!params.needsHandle, source, args);
|
||||
this._dispatchEvent('bindingCall', { binding });
|
||||
return binding.promise();
|
||||
});
|
||||
}, 'main');
|
||||
}
|
||||
|
||||
async newPage(params: channels.BrowserContextNewPageParams, metadata: CallMetadata): Promise<channels.BrowserContextNewPageResult> {
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ export abstract class BrowserContext extends SdkObject {
|
|||
});
|
||||
|
||||
if (debugMode() === 'console')
|
||||
await this.extendInjectedScript(consoleApiSource.source);
|
||||
await this.extendInjectedScript('main', consoleApiSource.source);
|
||||
}
|
||||
|
||||
async _ensureVideosPath() {
|
||||
|
|
@ -163,15 +163,15 @@ export abstract class BrowserContext extends SdkObject {
|
|||
return this._doSetHTTPCredentials(httpCredentials);
|
||||
}
|
||||
|
||||
async exposeBinding(name: string, needsHandle: boolean, playwrightBinding: frames.FunctionWithSource): Promise<void> {
|
||||
const identifier = PageBinding.identifier(name, 'main');
|
||||
async exposeBinding(name: string, needsHandle: boolean, playwrightBinding: frames.FunctionWithSource, world: types.World): Promise<void> {
|
||||
const identifier = PageBinding.identifier(name, world);
|
||||
if (this._pageBindings.has(identifier))
|
||||
throw new Error(`Function "${name}" has been already registered`);
|
||||
for (const page of this.pages()) {
|
||||
if (page.getBinding(name, 'main'))
|
||||
if (page.getBinding(name, world))
|
||||
throw new Error(`Function "${name}" has been already registered in one of the pages`);
|
||||
}
|
||||
const binding = new PageBinding(name, playwrightBinding, needsHandle, 'main');
|
||||
const binding = new PageBinding(name, playwrightBinding, needsHandle, world);
|
||||
this._pageBindings.set(identifier, binding);
|
||||
await this._doExposeBinding(binding);
|
||||
}
|
||||
|
|
@ -369,8 +369,8 @@ export abstract class BrowserContext extends SdkObject {
|
|||
}
|
||||
}
|
||||
|
||||
async extendInjectedScript(source: string, arg?: any) {
|
||||
const installInFrame = (frame: frames.Frame) => frame.extendInjectedScript(source, arg).catch(() => {});
|
||||
async extendInjectedScript(world: types.World, source: string, arg?: any) {
|
||||
const installInFrame = (frame: frames.Frame) => frame.extendInjectedScript(world, source, arg).catch(() => {});
|
||||
const installInPage = (page: Page) => {
|
||||
page.on(Page.Events.InternalFrameNavigatedToNewDocument, installInFrame);
|
||||
return Promise.all(page.frames().map(installInFrame));
|
||||
|
|
|
|||
|
|
@ -1219,9 +1219,9 @@ export class Frame extends SdkObject {
|
|||
this._networkIdleTimer = undefined;
|
||||
}
|
||||
|
||||
async extendInjectedScript(source: string, arg?: any): Promise<js.JSHandle> {
|
||||
const mainContext = await this._mainContext();
|
||||
const injectedScriptHandle = await mainContext.injectedScript();
|
||||
async extendInjectedScript(world: types.World, source: string, arg?: any): Promise<js.JSHandle> {
|
||||
const context = await this._context(world);
|
||||
const injectedScriptHandle = await context.injectedScript();
|
||||
return injectedScriptHandle.evaluateHandle((injectedScript, {source, arg}) => {
|
||||
return injectedScript.extend(source, arg);
|
||||
}, { source, arg });
|
||||
|
|
|
|||
|
|
@ -194,11 +194,11 @@ export class RecorderSupplement implements InstrumentationListener {
|
|||
// Input actions that potentially lead to navigation are intercepted on the page and are
|
||||
// performed by the Playwright.
|
||||
await this._context.exposeBinding('_playwrightRecorderPerformAction', false,
|
||||
(source: BindingSource, action: actions.Action) => this._performAction(source.frame, action));
|
||||
(source: BindingSource, action: actions.Action) => this._performAction(source.frame, action), 'utility');
|
||||
|
||||
// Other non-essential actions are simply being recorded.
|
||||
await this._context.exposeBinding('_playwrightRecorderRecordAction', false,
|
||||
(source: BindingSource, action: actions.Action) => this._recordAction(source.frame, action));
|
||||
(source: BindingSource, action: actions.Action) => this._recordAction(source.frame, action), 'utility');
|
||||
|
||||
await this._context.exposeBinding('_playwrightRecorderState', false, source => {
|
||||
let snapshotUrl: string | undefined;
|
||||
|
|
@ -223,21 +223,21 @@ export class RecorderSupplement implements InstrumentationListener {
|
|||
snapshotUrl,
|
||||
};
|
||||
return uiState;
|
||||
});
|
||||
}, 'utility');
|
||||
|
||||
await this._context.exposeBinding('_playwrightRecorderSetSelector', false, async (_, selector: string) => {
|
||||
this._setMode('none');
|
||||
await this._recorderApp?.setSelector(selector, true);
|
||||
await this._recorderApp?.bringToFront();
|
||||
});
|
||||
}, 'utility');
|
||||
|
||||
await this._context.exposeBinding('_playwrightResume', false, () => {
|
||||
this._debugger.resume(false);
|
||||
});
|
||||
}, 'main');
|
||||
|
||||
const snapshotBaseUrl = await this._snapshotter.initialize() + '/snapshot/';
|
||||
await this._context.extendInjectedScript(recorderSource.source, { isUnderTest: isUnderTest(), snapshotBaseUrl });
|
||||
await this._context.extendInjectedScript(consoleApiSource.source);
|
||||
await this._context.extendInjectedScript('utility', recorderSource.source, { isUnderTest: isUnderTest(), snapshotBaseUrl });
|
||||
await this._context.extendInjectedScript('main', consoleApiSource.source);
|
||||
|
||||
if (this._debugger.isPaused())
|
||||
this._pausedStateChanged();
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ export class TraceViewer {
|
|||
await controller.run(async progress => {
|
||||
await context._browser._defaultContext!._loadDefaultContextAsIs(progress);
|
||||
});
|
||||
await context.extendInjectedScript(consoleApiSource.source);
|
||||
await context.extendInjectedScript('main', consoleApiSource.source);
|
||||
const [page] = context.pages();
|
||||
page.on('close', () => process.exit(0));
|
||||
await page.mainFrame().goto(internalCallMetadata(), urlPrefix + '/traceviewer/traceViewer/index.html');
|
||||
|
|
|
|||
Loading…
Reference in a new issue