github microsoft/playwright-mcp v0.0.47

12 hours ago

New ways to provide initial state

There are now multiple ways to provide the initial state to the browser context or a page.

For the storage state, you can either:

  • Start with a user data directory using the --user-data-dir argument. This will persist all browser data between the sessions.
  • Start with a storage state file using the --storage-state argument. This will load cookies and local storage from the file into an isolated browser context.

For the page state, you can use:

  • ❗NEW❗ --init-page to point to a TypeScript file that will be evaluated on the Playwright page object. This allows you to run arbitrary code to set up the page. You can use various Playwright APIs there, perform necessary steps, etc.
// init-page.ts
export default async ({ page }) => {
  await page.context().grantPermissions(['geolocation']);
  await page.context().setGeolocation({ latitude: 37.7749, longitude: -122.4194 });
  await page.setViewportSize({ width: 1280, height: 720 });
};
  • --init-script to point to a JavaScript file that will be added as an initialization script. The script will be evaluated in every page before any of the page's scripts.
    This is useful for overriding browser APIs or setting up the environment.
// init-script.js
window.isPlaywrightMCP = true;

New run-code command to save tokens

There now is a new browser_run_code command that allows LLM to run Playwright APIs as well. LLM can call it with a batch of Playwright APIs:

{
    name: 'browser_run_code',
    arguments: {
      code: `
        await page.getByRole("checkbox", { name: "Accept" }).check();
        await page.getByRole("button", { name: "Submit" }).click();
      `;
    }
  }

This way LLM can speed up repetitive operations and save on context tokens.

Breaking changes

--allowed-origins and --blocked-origins flags are gone. Please use --proxy as a safer alternative or rely upon the underlying OS policies instead.

Don't miss a new playwright-mcp release

NewReleases is sending notifications on new releases.