Patchright is a patched and undetected version of the Playwright Testing and Automation Framework for .NET.
It can be used as a drop-in replacement for Playwright.
Note
This repository serves the Patchright .NET Package. To use Patchright with Python or NodeJS, check out the Python Package or the NodeJS Package. Also check out the main Patchright Driver Repository
Patchright can be found on NuGet and can be installed by copying and pasting the following command into your Package Manager Console within Visual Studio (Tools > NuGet Package Manager > Package Manager Console).
Install-Package PatchrightAlternatively if you're using .NET Core then you can install Patchright via the command line interface with the following command:
dotnet add package PatchrightInstead of using the Microsoft.Playwright package just install the Patchright package instead. Patchright is a drop-in-replacement for Playwright!
Warning
Patchright only patches CHROMIUM based browsers. Firefox and Webkit are not supported.
using Microsoft.Playwright;
using System.Threading.Tasks;
class Program
{
public static async Task Main()
{
using var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
var page = await browser.NewPageAsync();
await page.GotoAsync("https://playwright.dev");
await page.ScreenshotAsync(new() { Path = "screenshot.png" });
}
}To be completely undetected, use the following configuration:
await using var context = await playwright.Chromium.LaunchPersistentContextAsync(
userDataDir: "...",
new BrowserTypeLaunchPersistentContextOptions
{
Channel = "chrome",
Headless = false,
NoViewport = true,
// do NOT add custom browser headers or userAgent
});Note
We recommend using Google Chrome instead of Chromium.
You can install it via ./playwright.ps1 install --with-deps chrome (or via any other installation method) and use it with Channel = "chrome".
Runtime.enable Leak
This is the biggest Patch Patchright uses. To avoid detection by this leak, patchright avoids using Runtime.enable by executing Javascript in (isolated) ExecutionContexts.
Console.enable Leak
Patchright patches this leak by disabling the Console API all together. This means, console functionality will not work in Patchright. If you really need the console, you might be better off using Javascript loggers, although they also can be easily detected.
Patchright tweaks the Playwright Default Args to avoid detection by Command Flag Leaks. This (most importantly) affects:
--disable-blink-features=AutomationControlled(added) to avoid navigator.webdriver detection.--enable-automation(removed) to avoid navigator.webdriver detection.--disable-popup-blocking(removed) to avoid popup crashing.--disable-component-update(removed) to avoid detection as a Stealth Driver.--disable-default-apps(removed) to enable default apps.--disable-extensions(removed) to enable extensions
Patchright patches some general leaks in the Playwright codebase. This mainly includes poor setups and obvious detection points.
Patchright is able to interact with elements in Closed Shadow Roots. Just use normal locators and Patchright will do the rest.
Patchright is now also able to use XPaths in Closed Shadow Roots.
With the right setup, Patchright currently is considered undetectable. Patchright passes:
- Brotector ✅
- Cloudflare ✅
- Kasada ✅
- Akamai ✅
- Shape/F5 ✅
- Bet365 ✅
- Datadome ✅
- Fingerprint.com ✅
- CreepJS ✅
- Sannysoft ✅
- Incolumitas ✅
- IPHey ✅
- Browserscan ✅
- Pixelscan ✅
See the original Playwright .NET Documentation and API Reference
EvaluateAsync Method (IFrame.EvaluateAsync, IJSHandle.EvaluateAsync, ILocator.EvaluateAsync, IPage.EvaluateAsync, IWorker.EvaluateAsync)
- Added
isolatedContextto choose Execution Context (Main/Isolated).bool(optional, Defaults totrue)
Task<T> EvaluateAsync<T>(
string expression,
object? arg = default,
+ bool isolatedContext = true);EvaluateHandleAsync Method (IFrame.EvaluateHandleAsync, IJSHandle.EvaluateHandleAsync, ILocator.EvaluateHandleAsync, IPage.EvaluateHandleAsync, IWorker.EvaluateHandleAsync)
- Added
isolatedContextto choose Execution Context (Main/Isolated).bool(optional, Defaults totrue)
Task<IJSHandle> EvaluateHandleAsync(
string expression,
object? arg = default,
+ bool isolatedContext = true);EvaluateAllAsync Method (ILocator.EvaluateAllAsync)
- Added
isolatedContextto choose Execution Context (Main/Isolated).bool(optional, Defaults totrue)
Task<IJSHandle> EvaluateAllAsync(
string expression,
object? arg = default,
+ bool isolatedContext = true);EvalOnSelectorAsync Method (IPage.EvalOnSelectorAsync, IFrame.EvalOnSelectorAsync)
- Added
isolatedContextto choose Execution Context (Main/Isolated).bool(optional, Defaults totrue)
Task<T> EvalOnSelectorAsync<T>(
string selector,
string expression,
object? arg = default,
EvalOnSelectorOptions? options = default,
+ bool isolatedContext = true);EvalOnSelectorAllAsync Method (IPage.EvalOnSelectorAllAsync, IFrame.EvalOnSelectorAllAsync)
- Added
isolatedContextto choose Execution Context (Main/Isolated).bool(optional, Defaults totrue)
Task<T> EvalOnSelectorAllAsync<T>(
string selector,
string expression,
object? arg = default,
+ bool isolatedContext = true);The bugs are documented in the Patchright Driver Repository.
The TODO is documented in the Patchright Driver Repository.
Deployment of new Patchright versions are not automatic (yet), and bugs due to Playwright codebase changes may occur. Fixes for these bugs might take a few days to be released manually.
If you choose to support our work, please contact @vinyzu or @steve_abcdef on Discord.
© Vinyzu
Patchright is licensed Apache 2.0
This repository is provided for educational purposes only.
No warranties are provided regarding accuracy, completeness, or suitability for any purpose. Use at your own risk—the authors and maintainers assume no liability for any damages, legal issues, or warranty breaches resulting from use, modification, or distribution of this code.
Any misuse or legal violations are the sole responsibility of the user.