ScreenshotNeo

BlogHow-to

How to Run a Playwright Script in Edge

Install Playwright, select Edge with the msedge channel, and run tests or standalone scripts in headed or headless mode.

By the ScreenshotNeo team1 October 20267 min read

Direct answer: Install Playwright, select Microsoft Edge with the msedge channel, then run either Playwright Test or a standalone Playwright script. Edge is Chromium-based, so Playwright uses its Chromium API with a branded Edge channel. Microsoft documents both workflows in its Edge Playwright guide.

Choose the way you want to run Edge

Use this route Best for How Edge is selected
Playwright Test Test discovery, fixtures, projects, retries and reporting use: { channel: 'msedge' } in a project
Playwright library A standalone script or a different test runner chromium.launch({ channel: 'msedge' })

Both routes are headless by default. Add headed mode when you need to watch the Edge window while debugging.

Prerequisites and installation

  1. Install a supported Node.js version for the Playwright version you choose. Check the current Playwright requirements before pinning a runtime; Microsoft’s 2023 article mentioned Node.js 12 or newer as historical guidance.
  2. Create or open a Node.js project.
  3. Install Playwright Test:
npm i -D @playwright/test

For a standalone library script instead, install the library package:

npm i playwright

Install browser binaries when needed:

npx playwright install

If Edge is not installed and you want Playwright to install the branded browser, run:

npx playwright install msedge

Playwright’s browser documentation notes that branded browser installation can use the operating system’s default global location. On managed machines, check where the browser was installed and whether enterprise policy controls it.

Run Edge with Playwright Test

1. Create the project configuration

Create playwright.config.ts:

import { defineConfig } from '@playwright/test';

export default defineConfig({
  testDir: './tests',
  projects: [
    {
      name: 'Microsoft Edge',
      use: {
        channel: 'msedge',
        baseURL: 'https://example.com',
      },
    },
  ],
});

The documented channel names include msedge, msedge-beta, msedge-dev and msedge-canary. Use the channel that matches the Edge release you intend to validate.

2. Add a test

Create tests/home.spec.ts:

import { test, expect } from '@playwright/test';

test('home page loads in Edge', async ({ page }) => {
  await page.goto('/');
  await expect(page).toHaveTitle(/Example Domain/);
});

3. Run it

npx playwright test

Open the visible Edge UI while the test runs:

npx playwright test --headed

Run only the Edge project when your configuration contains multiple projects:

npx playwright test --project="Microsoft Edge"

Pass a specific test file or use Playwright’s normal filtering options:

npx playwright test tests/home.spec.ts
npx playwright test -g "home page"

Run a standalone JavaScript script in Edge

Use Chromium’s API and set the Edge channel in the launch options. Save this as edge-screenshot.js:

const { chromium } = require('playwright');

(async () => {
  const browser = await chromium.launch({
    channel: 'msedge',
    headless: true,
  });

  const context = await browser.newContext({
    viewport: { width: 1440, height: 900 },
  });
  const page = await context.newPage();

  await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
  await page.screenshot({ path: 'edge-example.png', fullPage: true });

  await context.close();
  await browser.close();
})();

Run it with:

node edge-screenshot.js

For a visible browser window, set headless: false. Microsoft’s example explicitly creates a browser context and page before navigation and capture; keeping that shape is useful when you need context-level settings such as cookies, locale or permissions.

Run Edge with Playwright’s Python API

If your application is Python-based, install the package and browser support:

pip install playwright
python -m playwright install msedge

Then launch the Edge channel through Playwright’s Chromium API:

from playwright.sync_api import sync_playwright

with sync_playwright() as p:
    browser = p.chromium.launch(channel="msedge", headless=True)
    context = browser.new_context(viewport={"width": 1440, "height": 900})
    page = context.new_page()
    page.goto("https://example.com", wait_until="domcontentloaded")
    page.screenshot(path="edge-example.png", full_page=True)
    context.close()
    browser.close()

The same channel value applies to the asynchronous Python API; replace the synchronous calls with their async equivalents when your application already uses an event loop.

Headless versus headed Edge

  • Headless: No visible window. This is the default and is suitable for CI and server jobs.
  • Headed: Shows the full Edge UI. Use --headed with Playwright Test or headless: false in a library launch while diagnosing selectors, navigation or policy issues.

Playwright’s browser documentation warns that branded Edge’s newer headless implementation can behave differently from Playwright’s default Chromium headless shell. If a rendering or browser-specific issue appears only in one mode, reproduce it in the exact mode used by deployment.

Useful launch and context options

Option Example Why use it
Edge channel channel: 'msedge-beta' Run against a specific branded Edge channel.
Headed mode headless: false See the browser during debugging.
Viewport viewport: { width: 1280, height: 720 } Make layout checks repeatable.
Device scale deviceScaleFactor: 2 Exercise high-density rendering.
Locale and timezone locale: 'en-US', timezoneId: 'UTC' Reduce environment-dependent differences.
Storage state storageState: 'auth.json' Reuse a previously saved login state.
Proxy proxy: { server: 'http://proxy:8080' } Route traffic through a required network proxy.

Keep launch options that identify the browser (channel, headless mode and executable choice) separate from context options such as cookies, permissions and viewport. This makes it easier to reuse one Edge browser for several isolated contexts.

Choose a wait condition that represents readiness for your page:

await page.goto('https://example.com', { waitUntil: 'domcontentloaded' });
await page.locator('main').waitFor();
await page.screenshot({ path: 'ready.png', fullPage: true });

For pages that render after an API call, wait for a meaningful selector rather than relying only on a fixed timeout:

await page.goto('https://example.com/dashboard');
await page.locator('[data-testid="dashboard-ready"]').waitFor({ state: 'visible' });

Use a short, intentional timeout only when the application has no observable readiness signal. Long arbitrary sleeps slow every run and still fail when the page takes longer than expected.

CI checklist

  • Pin the Playwright version in your lockfile.
  • Install the Edge channel in the CI image or run npx playwright install msedge during setup.
  • Confirm the CI user can read the browser installation directory.
  • Run headless unless a virtual display is deliberately configured.
  • Save traces, screenshots and videos for failed tests using Playwright Test’s reporting options.
  • Check proxy, certificate and enterprise browser policies before changing test code.

Microsoft states that Chromium, Firefox and WebKit browser binaries work across Windows, macOS and Linux. The exact Edge installation and policy behavior still depends on the operating system and the managed environment.

Troubleshooting common errors

Symptom Likely cause Fix
browserType.launch: Executable doesn't exist The required browser or channel is not installed. Run npx playwright install msedge (or the equivalent Python command), then verify the installation path.
Edge channel is not found The channel name is misspelled or that release is unavailable. Use a documented value such as msedge, msedge-beta, msedge-dev or msedge-canary.
Works headed, fails headless Headless rendering or timing differs. Reproduce with the same headless setting as CI, replace sleeps with selector-based waits, and check the branded Edge headless differences documented by Playwright.
Browser starts then closes immediately An exception occurs before cleanup or a policy blocks automation. Wrap the script in error handling, log the exception, and ask the machine administrator to review enterprise Edge policies.
Navigation times out DNS, proxy, certificate, authentication or a slow application. Check connectivity from the runner, configure the required proxy or headers, and wait for a page-specific readiness signal.
Selectors pass locally but fail in CI Different viewport, locale, data or timing. Set context options explicitly and wait for the element state that proves the UI is ready.
Multiple Edge versions behave differently Different channels or automatic browser updates. Declare the channel in configuration and pin the Playwright dependency; record the browser version in CI logs.

Performance, reliability and cost considerations

  • Startup: Launching a new browser for every small operation adds overhead. Reuse a browser process and create isolated contexts when your runner permits it.
  • Parallelism: Playwright Test projects can run tests in parallel, but increase workers only as far as the CI CPU, memory and target site can handle.
  • Determinism: Fix viewport, locale, timezone, test data and browser channel when screenshots or visual assertions must be stable.
  • Reliability: Selector-based readiness checks, bounded retries and trace collection provide more useful failures than large fixed delays.
  • Cost: Self-hosted Playwright costs the compute and storage required by your runner. A hosted screenshot API can remove browser installation and maintenance when you only need rendered images or PDFs.

Or skip the browser setup

If your goal is a rendered screenshot rather than browser automation, ScreenshotNeo provides a single GET request for a PNG, JPEG, WebP or PDF. See the ScreenshotNeo API documentation for the complete option list.

curl -G "https://api.screenshotneo.com/v1/shot" -d access_key=YOUR_API_KEY --data-urlencode url=https://stripe.com -o shot.webp
import requests
r = requests.get("https://api.screenshotneo.com/v1/shot", params={"access_key": "YOUR_API_KEY", "url": "https://stripe.com"}, timeout=90)
open("shot.webp", "wb").write(r.content)
const q = new URLSearchParams({ access_key: 'YOUR_API_KEY', url: 'https://stripe.com' });
const res = await fetch(`https://api.screenshotneo.com/v1/shot?${q}`);

ScreenshotNeo removes cookie and consent banners, newsletter popups and chat widgets before capture. Bot checks, blank pages, failed loads, timeouts and cache hits are not billed as clean shots, and each response reports the result through X-Page-Verdict and X-Billed headers. It also provides an MCP server with take_screenshot, get_page_info and capture_pdf tools for AI agents. The Free plan includes 1,000 screenshots per month without a card; paid plans start at $5 for 3,000 screenshots. Create a free ScreenshotNeo account.

FAQ

Does Playwright use a separate Edge automation API?

No. Edge is built on Chromium, so Playwright uses its Chromium implementation and selects the branded browser with the msedge channel.

Can I run Edge Beta or Canary?

Yes. Use the documented channel name such as msedge-beta or msedge-canary in the project or launch options.

Which approach should I choose?

Choose Playwright Test when you want Playwright’s test discovery and fixtures. Choose the library API when browser control belongs inside another script or test runner.

Why does Edge automation fail only on a company laptop?

Enterprise browser policies can restrict launching or controlling Edge. Ask the administrator to review managed-browser settings, then compare the installed Playwright and Edge versions.

Can I watch a test run?

Yes. Add --headed to npx playwright test, or set headless: false when launching the library.