{"id":16178,"library":"playwright-core","title":"Playwright Core","description":"Playwright Core is the foundational JavaScript library for automating web browsers, providing a high-level API to control Chromium, Firefox, and WebKit through a single interface. It is designed for robust end-to-end testing, web scraping, and general browser automation tasks. As of version 1.59.1, the project maintains a rapid release cadence, typically monthly, delivering new features and browser updates. Recent additions include the `page.screencast` API for comprehensive recording capabilities and the introduction of a new CLI mode (`playwright-cli`) for AI agent-friendly, token-efficient operations. Key differentiators of Playwright Core include its auto-waiting functionality, resilient element interaction APIs, and native mobile emulation. While this package provides the raw browser automation API, it commonly serves as the underlying engine for the broader `playwright` package, which integrates a full test runner and pre-built browser binaries. It requires Node.js version 18 or higher to operate.","status":"active","version":"1.59.1","language":"javascript","source_language":"en","source_url":"https://github.com/microsoft/playwright","tags":["javascript","typescript"],"install":[{"cmd":"npm install playwright-core","lang":"bash","label":"npm"},{"cmd":"yarn add playwright-core","lang":"bash","label":"yarn"},{"cmd":"pnpm add playwright-core","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"For modern Node.js environments and Playwright versions >= 1.20, ES Modules (`import`) are the primary consumption method. CommonJS (`require`) may lead to `ERR_REQUIRE_ESM`.","wrong":"const { chromium } = require('playwright-core');","symbol":"chromium","correct":"import { chromium } from 'playwright-core';"},{"note":"When only importing types for TypeScript, use `import type` to prevent bundling unnecessary runtime code and ensure cleaner type-checking.","wrong":"import { Browser, Page } from 'playwright-core';","symbol":"Browser, Page","correct":"import type { Browser, Page } from 'playwright-core';"},{"note":"Similar to `chromium`, these are named exports for launching specific browser types directly from the core library.","symbol":"firefox, webkit","correct":"import { firefox, webkit } from 'playwright-core';"}],"quickstart":{"code":"import { chromium, type Browser, type Page } from 'playwright-core';\nimport * as fs from 'fs';\n\nasync function runBrowserAutomation() {\n  let browser: Browser | undefined;\n  try {\n    // Launch a headless Chromium browser\n    browser = await chromium.launch({ headless: true });\n    const page: Page = await browser.newPage();\n\n    // Navigate to a website\n    await page.goto('https://www.example.com');\n    console.log('Navigated to example.com');\n\n    // Take a screenshot and save it\n    const screenshotPath = 'example_screenshot.png';\n    await page.screenshot({ path: screenshotPath });\n    console.log(`Screenshot saved to ${screenshotPath}`);\n\n    // Get and print the page title\n    const title = await page.title();\n    console.log(`Page title: \"${title}\"`);\n\n    // Navigate to another page and interact with an element\n    await page.goto('https://playwright.dev');\n    const getStartedButton = page.locator('a', { hasText: 'Get started' }).first();\n    await getStartedButton.click();\n    console.log('Clicked \"Get started\" on Playwright.dev');\n\n    // Wait for navigation to complete and verify the URL\n    await page.waitForURL('**/docs/intro');\n    console.log(`Current URL after click: ${page.url()}`);\n\n  } catch (error) {\n    console.error('An error occurred during automation:', error);\n  } finally {\n    // Ensure the browser is closed even if an error occurs\n    if (browser) {\n      await browser.close();\n      console.log('Browser closed.');\n    }\n  }\n}\n\nrunBrowserAutomation();\n","lang":"typescript","description":"Demonstrates launching a headless Chromium browser, navigating to multiple pages, taking a screenshot, interacting with an element, and verifying the URL after navigation using Playwright Core."},"warnings":[{"fix":"Migrate Chromium extensions to Manifest V3. Consult Chromium documentation for migration guides.","message":"Playwright Core dropped support for Chromium extension manifest v2. Projects relying on these older manifest versions for browser extensions will need to update their extensions or browser versions.","severity":"breaking","affected_versions":">=1.55.0"},{"fix":"For a complete testing solution including test runner and auto-downloaded browsers, install `playwright` (`npm i -D playwright`). If you only need `playwright-core`, ensure you manually install browser binaries using `npx playwright install` or `npx playwright install chromium`.","message":"The `playwright-core` package provides only the low-level browser automation API. It does not include the Playwright Test runner or the pre-built browser binaries (Chromium, Firefox, WebKit). Attempting to use `playwright-core` without explicitly installing or managing browser binaries will lead to errors.","severity":"gotcha","affected_versions":">=1.0"},{"fix":"Upgrade your Node.js environment to version 18 or newer. Use a Node Version Manager (NVM) for easy switching (e.g., `nvm install 18 && nvm use 18`).","message":"Playwright Core requires Node.js version 18 or higher. Running with older Node.js versions will result in execution errors.","severity":"breaking","affected_versions":">=1.55.0"},{"fix":"This fix is included in `v1.59.1`. If encountering issues with `codegen`, `--ui`, or `show` commands on Windows with older versions, update to `v1.59.1` or newer. The console window will now be visible during browser spawning on Windows.","message":"The console window when spawning browser processes on Windows was reverted from being hidden, which previously caused regressions in features like `codegen`, `--ui`, and `show` commands.","severity":"gotcha","affected_versions":">=1.59.1"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Change your import statements from `const { chromium } = require('playwright-core');` to `import { chromium } from 'playwright-core';`. Ensure your `package.json` specifies `\"type\": \"module\"` or use `.mjs` file extensions.","cause":"Attempting to import `playwright-core` using CommonJS `require()` syntax in an ES Module context, or generally in newer Node.js versions where Playwright is published as an ESM module.","error":"ERR_REQUIRE_ESM"},{"fix":"Run `npx playwright install chromium` to download and install the Chromium browser binaries. For all browsers, use `npx playwright install`.","cause":"The required browser binaries (e.g., Chromium) have not been installed or are corrupted for `playwright-core`.","error":"Error: Browser type 'chromium' is not found. Close all running browsers and try again."},{"fix":"Upgrade your Node.js environment to version 18 or newer. Use NVM (`nvm install 18 && nvm use 18`) or update through your system's package manager.","cause":"The installed Node.js version is below the minimum requirement for the Playwright Core package.","error":"Error: Node.js v16.x is not supported. Please upgrade to Node.js v18 or higher."},{"fix":"Ensure the selector is correct and the element is present and visible on the page. Use `page.waitForSelector()` with appropriate state options (`'visible'`, `'attached'`, `'loaded'`) before interacting, or increase the locator's timeout: `page.locator('selector').click({ timeout: 60000 })`.","cause":"The specified element could not be found, was not visible, or was not actionable within the default timeout period.","error":"TimeoutError: locator.click: Timeout 30000ms exceeded."}],"ecosystem":"npm"}