…xts (#32437) Partially revert #32437 and add a test that console.log() messages from content scripts are properly reported Fixes https://github.com/microsoft/playwright/issues/32762
This commit is contained in:
parent
d93029f32f
commit
8b3ba3f34e
|
@ -690,15 +690,14 @@ class FrameSession {
|
||||||
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
if (!frame || this._eventBelongsToStaleFrame(frame._id))
|
||||||
return;
|
return;
|
||||||
const delegate = new CRExecutionContext(this._client, contextPayload);
|
const delegate = new CRExecutionContext(this._client, contextPayload);
|
||||||
let worldName: types.World;
|
let worldName: types.World|null = null;
|
||||||
if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
|
if (contextPayload.auxData && !!contextPayload.auxData.isDefault)
|
||||||
worldName = 'main';
|
worldName = 'main';
|
||||||
else if (contextPayload.name === UTILITY_WORLD_NAME)
|
else if (contextPayload.name === UTILITY_WORLD_NAME)
|
||||||
worldName = 'utility';
|
worldName = 'utility';
|
||||||
else
|
|
||||||
return;
|
|
||||||
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
||||||
(context as any)[contextDelegateSymbol] = delegate;
|
(context as any)[contextDelegateSymbol] = delegate;
|
||||||
|
if (worldName)
|
||||||
frame._contextCreated(worldName, context);
|
frame._contextCreated(worldName, context);
|
||||||
this._contextIdToContext.set(contextPayload.id, context);
|
this._contextIdToContext.set(contextPayload.id, context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,9 +50,9 @@ export function isNonRecoverableDOMError(error: Error) {
|
||||||
export class FrameExecutionContext extends js.ExecutionContext {
|
export class FrameExecutionContext extends js.ExecutionContext {
|
||||||
readonly frame: frames.Frame;
|
readonly frame: frames.Frame;
|
||||||
private _injectedScriptPromise?: Promise<js.JSHandle>;
|
private _injectedScriptPromise?: Promise<js.JSHandle>;
|
||||||
readonly world: types.World;
|
readonly world: types.World | null;
|
||||||
|
|
||||||
constructor(delegate: js.ExecutionContextDelegate, frame: frames.Frame, world: types.World) {
|
constructor(delegate: js.ExecutionContextDelegate, frame: frames.Frame, world: types.World|null) {
|
||||||
super(frame, delegate, world || 'content-script');
|
super(frame, delegate, world || 'content-script');
|
||||||
this.frame = frame;
|
this.frame = frame;
|
||||||
this.world = world;
|
this.world = world;
|
||||||
|
|
|
@ -163,15 +163,14 @@ export class FFPage implements PageDelegate {
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return;
|
return;
|
||||||
const delegate = new FFExecutionContext(this._session, executionContextId);
|
const delegate = new FFExecutionContext(this._session, executionContextId);
|
||||||
let worldName: types.World;
|
let worldName: types.World|null = null;
|
||||||
if (auxData.name === UTILITY_WORLD_NAME)
|
if (auxData.name === UTILITY_WORLD_NAME)
|
||||||
worldName = 'utility';
|
worldName = 'utility';
|
||||||
else if (!auxData.name)
|
else if (!auxData.name)
|
||||||
worldName = 'main';
|
worldName = 'main';
|
||||||
else
|
|
||||||
return;
|
|
||||||
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
||||||
(context as any)[contextDelegateSymbol] = delegate;
|
(context as any)[contextDelegateSymbol] = delegate;
|
||||||
|
if (worldName)
|
||||||
frame._contextCreated(worldName, context);
|
frame._contextCreated(worldName, context);
|
||||||
this._contextIdToContext.set(executionContextId, context);
|
this._contextIdToContext.set(executionContextId, context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -502,15 +502,14 @@ export class WKPage implements PageDelegate {
|
||||||
if (!frame)
|
if (!frame)
|
||||||
return;
|
return;
|
||||||
const delegate = new WKExecutionContext(this._session, contextPayload.id);
|
const delegate = new WKExecutionContext(this._session, contextPayload.id);
|
||||||
let worldName: types.World;
|
let worldName: types.World|null = null;
|
||||||
if (contextPayload.type === 'normal')
|
if (contextPayload.type === 'normal')
|
||||||
worldName = 'main';
|
worldName = 'main';
|
||||||
else if (contextPayload.type === 'user' && contextPayload.name === UTILITY_WORLD_NAME)
|
else if (contextPayload.type === 'user' && contextPayload.name === UTILITY_WORLD_NAME)
|
||||||
worldName = 'utility';
|
worldName = 'utility';
|
||||||
else
|
|
||||||
return;
|
|
||||||
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
const context = new dom.FrameExecutionContext(delegate, frame, worldName);
|
||||||
(context as any)[contextDelegateSymbol] = delegate;
|
(context as any)[contextDelegateSymbol] = delegate;
|
||||||
|
if (worldName)
|
||||||
frame._contextCreated(worldName, context);
|
frame._contextCreated(worldName, context);
|
||||||
this._contextIdToContext.set(contextPayload.id, context);
|
this._contextIdToContext.set(contextPayload.id, context);
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
console.log("Service worker script loaded");
|
||||||
|
|
||||||
|
chrome.runtime.onInstalled.addListener(() => {
|
||||||
|
console.log("Extension installed");
|
||||||
|
});
|
|
@ -0,0 +1 @@
|
||||||
|
console.log("Test console log from a third-party execution context");
|
|
@ -0,0 +1,17 @@
|
||||||
|
{
|
||||||
|
"manifest_version": 3,
|
||||||
|
"name": "Console Log Extension",
|
||||||
|
"version": "1.0",
|
||||||
|
"background": {
|
||||||
|
"service_worker": "background.js"
|
||||||
|
},
|
||||||
|
"permissions": [
|
||||||
|
"tabs"
|
||||||
|
],
|
||||||
|
"content_scripts": [
|
||||||
|
{
|
||||||
|
"matches": ["<all_urls>"],
|
||||||
|
"js": ["content.js"]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
|
@ -146,6 +146,27 @@ it('should support request/response events when using backgroundPage()', async (
|
||||||
await context.close();
|
await context.close();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should report console messages from content script', {
|
||||||
|
annotation: { type: 'issue', description: 'https://github.com/microsoft/playwright/issues/32762' }
|
||||||
|
}, async ({ browserType, createUserDataDir, asset, server }) => {
|
||||||
|
const userDataDir = await createUserDataDir();
|
||||||
|
const extensionPath = asset('extension-with-logging');
|
||||||
|
const extensionOptions = {
|
||||||
|
headless: false,
|
||||||
|
args: [
|
||||||
|
`--disable-extensions-except=${extensionPath}`,
|
||||||
|
`--load-extension=${extensionPath}`,
|
||||||
|
],
|
||||||
|
};
|
||||||
|
const context = await browserType.launchPersistentContext(userDataDir, extensionOptions);
|
||||||
|
const page = await context.newPage();
|
||||||
|
const consolePromise = page.waitForEvent('console', e => e.text().includes('Test console log from a third-party execution context'));
|
||||||
|
await page.goto(server.EMPTY_PAGE);
|
||||||
|
const message = await consolePromise;
|
||||||
|
expect(message.text()).toContain('Test console log from a third-party execution context');
|
||||||
|
await context.close();
|
||||||
|
});
|
||||||
|
|
||||||
it('should not create pages automatically', async ({ browserType }) => {
|
it('should not create pages automatically', async ({ browserType }) => {
|
||||||
const browser = await browserType.launch();
|
const browser = await browserType.launch();
|
||||||
const browserSession = await browser.newBrowserCDPSession();
|
const browserSession = await browser.newBrowserCDPSession();
|
||||||
|
|
Loading…
Reference in New Issue