Playwright WebKit and output the browser’s console log
To open a webpage using Playwright WebKit and output the browser’s console log for debugging purposes, use the Playwright API to launch the WebKit browser, open a page, and attach a listener to console events. This gives full visibility into all console output including log, warn, and error messages during your automated session.
see also https://webscraping.ai/faq/playwright/how-to-capture-console-logs-using-playwright
JavaScript Example
const { webkit } = require('playwright');
// Launch WebKit browser
(async () => {
const browser = await webkit.launch({ headless: false }); // headed mode for debugging
const page = await browser.newPage();
// Listen for all console events
page.on('console', msg => {
console.log(`Console ${msg.type()}: ${msg.text()}`);
});
await page.goto('https://example.com');
// Interact, debug, etc.
await browser.close();
})();
This script launches WebKit, opens a webpage, and prints console output directly to your terminal. See https://autify.com/blog/playwright-debug
CLI Usage & Debugging Tips
-
To run Playwright scripts from the command line, use
node your-script.js
. -
For interactive debugging, launch with
{ headless: false }
and optionally use Playwright Inspector or VSCode integration for breakpoints. -
You can also run Playwright tests in UI mode for more visual tracing:
npx playwright test --ui
. -
Collect all logs into an array for later assertion or analysis instead of printing immediately. See also https://www.checklyhq.com/blog/how-to-monitor-javascript-logs-and-exceptions-with-playwright/
-
Use environment variables such as
PWDEBUG=console
for more advanced inspection tools and developer console access during execution. https://playwright.dev/dotnet/docs/debug