Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
fix: restore PWDEBUG=console (#36748)
Dmitry Gozmanbeffe0276098
diff --git a/packages/playwright-core/src/server/browserContext.ts b/packages/playwright-core/src/server/browserContext.tsindex 531556374b..00ecf1792d 100644--- a/packages/playwright-core/src/server/browserContext.ts+++ b/packages/playwright-core/src/server/browserContext.ts@@ -138,8 +138,12 @@ export abstract class BrowserContext extends SdkObject {RecorderApp.showInspectorNoReply(this);});- if (debugMode() === 'console')- await this.extendInjectedScript('function Console(injectedScript) { injectedScript.consoleApi.install(); }');+ if (debugMode() === 'console') {+ await this.extendInjectedScript(`+ function installConsoleApi(injectedScript) { injectedScript.consoleApi.install(); }+ module.exports = { default: () => installConsoleApi };+ `);+ }if (this._options.serviceWorkers === 'block')await this.addInitScript(undefined, `\nif (navigator.serviceWorker) navigator.serviceWorker.register = async () => { console.warn('Service Worker registration blocked by Playwright'); };\n`);diff --git a/tests/playwright-test/playwright.spec.ts b/tests/playwright-test/playwright.spec.tsindex 51ec450d19..f1bdecb024 100644--- a/tests/playwright-test/playwright.spec.ts+++ b/tests/playwright-test/playwright.spec.ts@@ -895,3 +895,19 @@ test('page.pause() should disable test timeout', async ({ runInlineTest }) => {expect(result.passed).toBe(1);expect(result.output).toContain('success!');});++test('PWDEBUG=console should expose window.playwright', async ({ runInlineTest }) => {+ const result = await runInlineTest({+ 'a.test.ts': `+ import { test, expect } from '@playwright/test';++ test('test', async ({ page }) => {+ await page.setContent('<body></body>');+ const bodyTag = await page.evaluate(() => window.playwright.$('body').tagName);+ expect(bodyTag).toBe('BODY');+ });+ `,+ }, {}, { PWDEBUG: 'console' });+ expect(result.exitCode).toBe(0);+ expect(result.passed).toBe(1);+});