An open API service indexing awesome lists of open source software.

https://github.com/regseb/playwright-ghost

Playwright overlay with plugins.
https://github.com/regseb/playwright-ghost

ghost headless playwright polyfill

Last synced: 5 months ago
JSON representation

Playwright overlay with plugins.

Awesome Lists containing this project

README

        

# Playwright-ghost

[![npm][img-npm]][link-npm] [![build][img-build]][link-build]
[![coverage][img-coverage]][link-coverage] [![semver][img-semver]][link-semver]

> [!NOTE]
>
> This project is not officially commissioned or supported by Microsoft and
> Playwright.

Playwright-ghost is an overlay on [Playwright](https://playwright.dev/), adding
plugins to conceal the differences between a browser used by a human being and a
[headless browser](https://en.wikipedia.org/wiki/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])`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch)
and
[`browserType.launchPersistentContext(userDataDir, [options])`](https://playwright.dev/docs/api/class-browsertype#browser-type-launch-persistent-context)
methods.

The `plugins` property is an array containing the plugins to be added.

## Install

[`playwright-ghost`](https://www.npmjs.com/package/playwright-ghost) doesn't
provide [`playwright`](https://www.npmjs.com/package/playwright), so you need to
add it to your dependencies.

```shell
npm install playwright playwright-ghost
```

`playwright-ghost` can also be used with
[`rebrowser-playwright`](https://www.npmjs.com/package/rebrowser-playwright).

```shell
npm install rebrowser-playwright playwright-ghost
```

## Use

Here's an example with the recommended plugins.

```javascript
import { chromium, plugins } from "playwright-ghost";
// Or to use rebrowser-playwright:
// 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.

```javascript
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.

```javascript
import { chromium, plugins } from "playwright-ghost";

const browser = await chromium.launch({
plugins: [...plugins.recommended(), plugins.utils.locale()],
});
// ...
```

## Plugins

⭐ is in `recommended` / βš™οΈ has options / πŸ“¦ requires dependency

NameDescription

⭐

polyfill.automation

Disable --enable-automation in Chromium.


⭐

polyfill.headless


Correct many differences in Javascript APIs between the headful and
headless versions of Chromium.



⭐ βš™οΈ

polyfill.screen


Set a realistic value for screen size: 1920x1080.



βš™οΈ

polyfill.userAgent


Change the browser's user agent.



⭐ βš™οΈ

polyfill.viewport


Vary viewport size with random values between 1000x500 and 1800x800.



⭐

polyfill.webdriver


Set navigator.webdriver to false.





polyfill.webGL


Modify WebGL parameter values.



⭐ βš™οΈ

humanize.dialog


Close <dialog> within a humanly possible time (between
1 and 5 seconds).



βš™οΈ πŸ“¦

utils.adblocker


Add Ghostery adblocker.





utils.debug


Display messages from the browser console in the program console.





utils.locale


Use the locally installed browser.

## Anti-bots



Chromiumᡃ
Firefoxᡇ



Brotector


❌¹ 0.98 (UA_Override & Input.cordinatesLeak)


❌ 1.00 (navigator.webdriver & PWinitScript)




BrowserScan

βœ…
❌ WebDriver



Chromedriver Detector

βœ…
βœ…



CreepJS

βœ… B-
❌ F+



Datadome

βœ…
βœ…



Deviceandbrowserinfo

❌ GPU
❌ Webdriver



Device Info

βœ…
❌



FingerprintJS

βœ…
❌ Automation Tool



HeadlessDetectJS

βœ…
❌ 0.2



infosimples

βœ…
❌ Webdriver & Plugins



Chrome Headless Detection (Intoli)

βœ…
❌ WebDriver & Plugins



rebrowser-bot-detector

❌ pwInitScripts
❌ navigatorWebdriver



Antibot (Sannysoft)

βœ…
❌ Webdriver & Plugins



Cloudflare turnstile demo

βœ…
βœ…

ᡃ Chromium with `rebrowser-playwright`, recommended plugins and the
`polyfill.userAgent` plugin (to remove _Headless_).\
ᡇ Firefox with `playwright` and recommended plugins.\
ΒΉ Without [_popupCrash_](https://github.com/kaliiiiiiiiii/brotector#popupcrash).

[img-npm]:
https://img.shields.io/npm/dm/playwright-ghost?label=npm&logo=npm&logoColor=whitesmoke
[img-build]:
https://img.shields.io/github/actions/workflow/status/regseb/playwright-ghost/ci.yml?branch=main&logo=github&logoColor=whitesmoke
[img-coverage]:
https://img.shields.io/endpoint?label=coverage&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fregseb%2Fplaywright-ghost%2Fmain
[img-semver]:
https://img.shields.io/badge/semver-2.0.0-blue?logo=semver&logoColor=whitesmoke
[link-npm]: https://www.npmjs.com/package/playwright-ghost
[link-build]:
https://github.com/regseb/playwright-ghost/actions/workflows/ci.yml?query=branch%3Amain
[link-coverage]:
https://dashboard.stryker-mutator.io/reports/github.com/regseb/playwright-ghost/main
[link-semver]: https://semver.org/spec/v2.0.0.html "Semantic Versioning 2.0.0"