diff --git a/packages/playwright-core/src/client/browserType.ts b/packages/playwright-core/src/client/browserType.ts index eca564e69c..2e1e12a529 100644 --- a/packages/playwright-core/src/client/browserType.ts +++ b/packages/playwright-core/src/client/browserType.ts @@ -216,7 +216,7 @@ export class BrowserType extends ChannelOwner imple const browser = Browser.from(result.browser); this._didLaunchBrowser(browser, {}, params.logger); if (result.defaultContext) - await this._didCreateContext(BrowserContext.from(result.defaultContext), {}, {}, undefined); + await this._didCreateContext(BrowserContext.from(result.defaultContext), {}, {}, params.logger); return browser; } diff --git a/tests/library/chromium/connect-over-cdp.spec.ts b/tests/library/chromium/connect-over-cdp.spec.ts index 570460fe04..0262b73c7a 100644 --- a/tests/library/chromium/connect-over-cdp.spec.ts +++ b/tests/library/chromium/connect-over-cdp.spec.ts @@ -40,6 +40,33 @@ test('should connect to an existing cdp session', async ({ browserType, mode }, } }); +test('should use logger in default context', async ({ browserType }, testInfo) => { + test.info().annotations.push({ type: 'issue', description: 'https://github.com/microsoft/playwright/issues/28813' }); + const port = 9339 + testInfo.workerIndex; + const browserServer = await browserType.launch({ + args: ['--remote-debugging-port=' + port] + }); + try { + const log = []; + const browser = await browserType.connectOverCDP({ + endpointURL: `http://127.0.0.1:${port}/`, + logger: { + log: (name, severity, message) => log.push({ name, severity, message }), + isEnabled: (name, severity) => severity !== 'verbose' + } + }); + const page = await browser.contexts()[0].newPage(); + await page.setContent(''); + await page.click('button'); + await browser.close(); + expect(log.length > 0).toBeTruthy(); + expect(log.filter(item => item.message.includes('page.setContent')).length > 0).toBeTruthy(); + expect(log.filter(item => item.message.includes('page.click')).length > 0).toBeTruthy(); + } finally { + await browserServer.close(); + } +}); + test('should cleanup artifacts dir after connectOverCDP disconnects due to ws close', async ({ browserType, toImpl, mode }, testInfo) => { const port = 9339 + testInfo.workerIndex; const browserServer = await browserType.launch({