playwright-ghost v0.11.0
Playwright-ghost
Playwright-ghost is an overlay on Playwright, adding plugins to conceal the differences between a browser used by a human being and a headless browser controlled by a program.
The Playwright-ghost API is identical to that of Playwright, except for the
addition of the plugins
option to the
browserType.launch([options])
and
browserType.launchPersistentContext(userDataDir, [options])
methods.
The plugins
property is an array containing the plugins to be added.
Disclaimer
This project is not officially commissioned or supported by Microsoft and Playwright.
Install
playwright-ghost
doesn't
provide playwright
, so you need to
add it to your dependencies.
npm install playwright playwright-ghost
playwright-ghost
can also be used with
patchright
or
rebrowser-playwright
.
npm install patchright playwright-ghost
npm install rebrowser-playwright playwright-ghost
Use
Here's an example with the recommended plugins.
import { chromium, plugins } from "playwright-ghost";
// Or to use patchright or rebrowser-playwright:
// import { chromium, plugins } from "playwright-ghost/patchright";
// import { chromium, plugins } from "playwright-ghost/rebrowser";
const browser = await chromium.launch({
plugins: plugins.recommended(),
});
const context = await browser.newContext();
const page = await context.newPage();
await page.goto("https://example.com/");
const title = await page.locator("h1").textContent();
console.log(title);
await context.close();
await browser.close();
In this other example, three plugins are added:
polyfill.headless
has no options;polyfill.screen
sets other values for screen size;utils.adblocker
uses default options.
import { chromium, plugins } from "playwright-ghost";
const browser = await chromium.launch({
plugins: [
plugins.polyfill.headless(),
plugins.polyfill.screen({ width: 2560, height: 1440 }),
plugins.utils.adblocker(),
],
});
// ...
And for this example, the recommended plugins and the utils.locale
plugin are
added.
import { chromium, plugins } from "playwright-ghost";
const browser = await chromium.launch({
plugins: [...plugins.recommended(), plugins.utils.locale()],
});
// ...
Plugins
⭐ is in recommended
/ ⚙️ has options / 📦
requires external tool
Anti-bots
To find out which plugins are used, see the anti-bots integration tests.