Skip to content

Instantly share code, notes, and snippets.

@observethenoyes
Created July 2, 2025 10:57
Show Gist options
  • Select an option

  • Save observethenoyes/b7c9d4eef1388cb59e35b86c38abd7e0 to your computer and use it in GitHub Desktop.

Select an option

Save observethenoyes/b7c9d4eef1388cb59e35b86c38abd7e0 to your computer and use it in GitHub Desktop.
Detect console errors with Playwright
import { test, expect } from '@playwright/test';
test.describe('Console error detection', () => {
test('should have no console errors on page load', async ({ page }) => {
const consoleErrors: string[] = [];
// Listen for console events and collect error messages
page.on('console', msg => {
if (msg.type() === 'error') {
consoleErrors.push(msg.text());
}
});
// Navigate to your target page
await page.goto('https://checklyhq.com');
// You can perform additional interactions here if needed
// Assert that no console errors were captured
expect(consoleErrors,
`Found console errors:\n${consoleErrors.join('\n')}`
).toHaveLength(0);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment