<h1 align="center">
🎭 Patchright
</h1>
<p align="center">
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/blob/main/LICENSE">
<img src="https://img.shields.io/badge/License-Apache%202.0-green">
</a>
<a>
<img src="https://img.shields.io/badge/Based%20on-Playwright-goldenrod">
</a>
<a>
<img src="https://img.shields.io/badge/Driver-Patched-blue">
</a>
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/releases/latest">
<img alt="Patchright Version" src="https://img.shields.io/github/v/release/Kaliiiiiiiiii-Vinyzu/patchright?display_name=release&label=Version">
</a>
<br/>
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python">
<img src="https://img.shields.io/badge/Package-Python-seagreen">
</a>
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python/releases">
<img alt="Python Downloads" src="https://img.shields.io/pepy/dt/patchright?color=red&label=Python%20Downloads">
</a>
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-nodejs">
<img src="https://img.shields.io/badge/Package-NodeJS-seagreen">
</a>
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-nodejs/releases">
<img alt="NodeJS Downloads" src="https://img.shields.io/npm/d18m/patchright?color=red&label=NodeJS%20Downloads">
</a>
<a href="https://github.com/DevEnterpriseSoftware/patchright-dotnet">
<img src="https://img.shields.io/badge/Package-.Net-seagreen">
</a>
<a href="https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-nodejs/releases">
<img alt=".Net Downloads" src="https://img.shields.io/nuget/dt/Patchright?label=.Net%20Downloads">
</a>
<br/>
<img src="https://img.shields.io/github/actions/workflow/status/Kaliiiiiiiiii-Vinyzu/patchright/patchright_tests.yml?label=Patchright%20Driver%20Tests">
<img src="https://img.shields.io/github/actions/workflow/status/Kaliiiiiiiiii-Vinyzu/patchright-python/patchright_tests.yml?label=Patchright%20Python%20Tests">
<img src="https://img.shields.io/github/actions/workflow/status/DevEnterpriseSoftware/patchright-dotnet/patchright_test.yml?label=Patchright%20.Net%20Tests">
</p>
#### Patchright 是 Playwright 测试与自动化框架的一个经过修补且未被检测的版本。</br> 它可作为 Playwright 的直接替代品使用。
> [!NOTE]
> 本仓库提供 Patchright 驱动。要使用 Patchright,请查看 [Python 包](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python)、[NodeJS 包](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-nodejs) 或 _社区驱动_ 的 [.Net 包](https://github.com/DevEnterpriseSoftware/patchright-dotnet/)
> [!IMPORTANT]
> Patchright 仅修补基于 CHROMIUM 的浏览器。不支持 Firefox 和 Webkit。
---
<details open id="sponsors">
<summary><h3>赞助商</h1></summary>
<sup>想要赞助本项目?请在 Discord 上联系 [@vinyzu](https://discordapp.com/users/935224495126487150)!</sup>
[<img width="60%" alt="NodeMaven Banner" src="https://assets.kitploit.com/production/public/readmes/41476/8409e9fd4ecade7fa018f576c77d6f51fb342f311f9e8e2b49984de007b5a605/fc71d82e04f5dc303d21f905310e811885d8a6a57ddffe892b4164bf12547371-display-v1.webp" />](https://go.nodemaven.com/Vinyzuoctober)
</br>
#### [NodeMaven](https://go.nodemaven.com/Vinyzuoctober):您用于网页抓取和自动化、提供高质量 IP 的高效代理服务商。
为什么选择 [NodeMaven](https://go.nodemaven.com/Vinyzuoctober)?
🎯 ZIP 定向
</br>
✅ 99.9% 正常运行时间
</br>
🔍 IP 过滤:保证代理的欺诈评分 <97%
</br>
🔰 无需 KYC
</br>
🎉 独特的免费工具:代理带宽检查器、Meta 标签检查器、IP 查询等!
**Patchright 用户专属优惠码**:
</br>
🔥 **PATCHRIGHT35** - 移动和住宅代理 **35% 折扣**
</br>
🔥 **PATCHRIGHT40** - ISP(静态)代理 **40% 折扣**
<sup>选择 [NodeMaven](https://go.nodemaven.com/Vinyzuoctober),获得质量与稳定性。</sup>
</br>
<sup>查看 Nodemaven 的新 GitHub,获取更多网页抓取和自动化解决方案 - https://github.com/nodemaven</sup>
---
[<img height="100" alt="swiftproxy banner" src="https://assets.kitploit.com/production/public/readmes/41476/71326e65aa66112fe5c3cd5a61951b775d58850b93eaaf166fd77930681f5174.png" />](https://www.swiftproxy.net/?ref=Vinyzu)
#### [Swiftproxy](https://www.swiftproxy.net/?ref=Vinyzu):面向可扩展数据收集的高性能住宅代理
专为需要**可靠**、反检测代理基础设施的开发者打造。[Swiftproxy](https://www.swiftproxy.net/?ref=Vinyzu) 提供**稳定连接**、**高成功率**以及面向**大规模抓取和自动化**的灵活控制。
- 🌍 195+ 个地区,提供符合道德来源的住宅 IP
- 🔄 **轮换**与**粘性会话**,支持精准地理定位
- ⚡ 针对**防封禁**与**高成功率**进行优化
- 🔌 支持 HTTP / HTTPS / SOCKS5
- 🧪 **免费 500MB 试用**,用于测试
- 💸 Patchright 用户专属**折扣**码:**PROXY90 - 10%**
<sup> 最适合:网页抓取、自动化、多账号运营和大规模数据提取 </sup>
---
[<img height="90" alt="rapidproxy banner" src="https://assets.kitploit.com/production/public/readmes/41476/2c138417cf7695cb48943327f3d6d9036986882c2a4ffe5e9172f07386a9f229.png" />](https://www.rapidproxy.io/?ref=Vinyzu)
#### [RapidProxy](https://www.rapidproxy.io/?ref=Vinyzu) 提供稳定且高性能的代理网络,专为大规模数据运营打造。
[RapidProxy](https://www.rapidproxy.io/?ref=Vinyzu) 提供:
- 🌍 9000 万+ 住宅 IP(200+ 个地区)
- 🔄 **轮换住宅代理** — 低至 **$0.65/GB**(流量不过期)
- 🧩 **静态住宅 IP** — **$5/IP**(30 天,不限流量)
- 🎯 精准地理定位
- ⚡ **提供免费试用** — 无风险测试代理性能
- 专为抓取、自动化和高性能数据工作流打造。
- 🔥 特别优惠:使用代码 **RAPID10** 可享 **9 折**
<sup> 快速开始。全球扩展。借助 [RapidProxy](https://www.rapidproxy.io/?ref=Vinyzu) 保持稳定。 </sup>
---
<div align="center">
<img src="https://assets.kitploit.com/production/public/readmes/41476/f3ac5dd3dd1ac541342eeda194f605fe1e28f9b044c0a90867b6db914c4a1b48/ad967b2ca510d337e9c8e72d654869c8fc75b08b088e358e074a6bbb003e6639-display-v1.webp" width="56" alt="Scrappey">
### 由 [Scrappey](https://scrappey.com?utm_source=patchright&utm_medium=github&utm_campaign=repo_readme) 赞助
</div>
让浏览器通过检测是一个问题。在数百万次请求中保持代理轮换、指纹更新和会话存活则是另一个问题。**Scrappey** 解决第二个问题:一个端点,返回已解决的页面。
- **Clearcote** — 我们自行维护的修补版 Chromium,并非现成构建
- **一个端点背后有多个引擎** — 在一个技术栈上被拦截,就路由到另一个
- **通过 API 点击、输入、等待和滚动** — 真实会话,而非抓取代理
- **包含住宅和数据中心代理**,也可自带代理
- **按请求计费**,无月度最低消费
```bash
curl -X POST "https://publisher.scrappey.com/api/v1?key=YOUR_KEY" \
-H "Content-Type: application/json" \
-d '{"cmd": "request.get", "url": "https://example.com"}'
```
使用优惠码 `PATCHRIGHT` 可享 9 折优惠
[文档](https://scrappey.com/docs?utm_source=patchright&utm_medium=github&utm_campaign=repo_readme) · [Discord](https://scrappey.com/discord?utm_source=patchright&utm_medium=github&utm_campaign=repo_readme) · [获取 API 密钥](https://scrappey.com?utm_source=patchright&utm_medium=github&utm_campaign=repo_readme)
---
[<img height="120" alt="ProxyLane Banner" src="https://assets.kitploit.com/production/public/readmes/41476/ed95563a028e0c1cefb4f5dccc8f7b69653f4c3fb7d5c4b5099b4cd5718714b7/7afb4fb03926a17d778280ff8bc7b2f62f5206d212d2b7525ea6ee90ae8ed0d3-display-v1.webp" />](https://proxylane.dev/?utm_source=patchright&utm_medium=partnership&utm_campaign=patchright_sponsor_202610&utm_content=readme)
</br>
#### [ProxyLane](https://proxylane.dev/?utm_source=patchright&utm_medium=partnership&utm_campaign=patchright_sponsor_202610&utm_content=readme):让每个 Patchright 配置文件保持一致性的住宅代理。
要使上报的时区与你的代理相匹配,请为每个配置文件分配一个固定到某个城市的粘性 IP,并设置相同的时区:
```py
context = playwright.chromium.launch_persistent_context(
user_data_dir="...", channel="chrome", headless=False, no_viewport=True,
proxy={"server": "http://us.gw.proxylane.dev:10000",
"username": "USER_c_US_city_Chicago_s_profile1", # one sticky IP per profile
"password": "PASS"},
timezone_id="America/Chicago", locale="en-US", # match the proxy city
)
```
<sup>提示:设置 `--webrtc-ip-handling-policy=disable_non_proxied_udp`,否则 [WebRTC 会暴露你的真实 IP](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python/issues/47)。</sup>
:earth_africa: 覆盖 195 个国家/地区的 2800 万个住宅 IP,支持按城市、ZIP 和 ASN 定向
</br>
:stopwatch: 粘性会话最长 72 小时,支持 HTTP 和 SOCKS5
</br>
:money_with_wings: 低至 $2/GB,流量永不过期
:fire: **PATCHLANE35** - Patchright 用户专享 **35% 折扣**
<sup>粘贴代码片段,添加你的凭据,然后通过 [ProxyLane](https://proxylane.dev/?utm_source=patchright&utm_medium=partnership&utm_campaign=patchright_sponsor_202610&utm_content=readme_caption) 在真实住宅 IP 上运行你的下一次 Patchright 会话。</sup>
</details>
---
## 补丁
### [Runtime.enable](https://vanilla.aslushnikov.com/?Runtime.enable) 泄漏
这是 Patchright 使用的最重要的补丁。为避免被此泄漏检测到,patchright 通过在(隔离的)ExecutionContexts 中执行 Javascript 来避免使用 [Runtime.enable](https://vanilla.aslushnikov.com/?Runtime.enable)。
### [Console.enable](https://vanilla.aslushnikov.com/?Console.enable) 泄漏
Patchright 通过完全禁用 Console API 来修补此泄漏。这意味着,控制台功能在 Patchright 中将无法使用。如果你确实需要控制台,使用 Javascript 日志记录器可能更好,尽管它们也很容易被检测到。
### 命令行标志泄漏
Patchright 调整了 Playwright 的默认参数,以避免被命令行标志泄漏检测到。这(最重要的是)影响:
- `--disable-blink-features=AutomationControlled`(已添加)以避免 navigator.webdriver 检测。
- `--enable-automation`(已移除)以避免 navigator.webdriver 检测。
- `--disable-popup-blocking`(已移除)以避免弹窗崩溃。
- `--disable-component-update`(已移除)以避免被检测为隐身驱动。
- `--disable-default-apps`(已移除)以启用默认应用。
- `--disable-extensions`(已移除)以启用扩展
### 一般泄漏
Patchright 修补了 Playwright 代码库中的一些一般泄漏。这主要包括糟糕的配置和明显的检测点。
### 封闭式 Shadow Root
Patchright 能够与封闭式 Shadow Root 中的元素进行交互。只需使用普通的定位器,Patchright 会完成其余工作。
<br/>
Patchright 现在也能够在封闭式 Shadow Root 中使用 XPath。
---
## 隐身性
在正确的配置下,Patchright 目前被认为是不可检测的。
Patchright 通过:
- [Brotector](https://kaliiiiiiiiii.github.io/brotector/) ✅(配合 [CDP-Patches](https://github.com/Kaliiiiiiiiii-Vinyzu/CDP-Patches/))
- [Cloudflare](https://cloudflare.com/) ✅
- [Kasada](https://www.kasada.io/) ✅
- [Akamai](https://www.akamai.com/products/bot-manager/) ✅
- [Shape/F5](https://www.f5.com/) ✅
- [Bet365](https://bet365.com/) ✅
- [Datadome](https://datadome.co/products/bot-protection/) ✅
- [Fingerprint.com](https://fingerprint.com/products/bot-detection/) ✅
- [CreepJS](https://abrahamjuliot.github.io/creepjs/) ✅
- [Sannysoft](https://bot.sannysoft.com/) ✅
- [Incolumitas](https://bot.incolumitas.com/) ✅
- [IPHey](https://iphey.com/) ✅
- [Browserscan](https://browserscan.net/) ✅
- [Pixelscan](https://pixelscan.net/) ✅
---
## 缺陷
#### 尽管我们花费了大量时间使 Patchright 尽可能稳定,但仍可能出现缺陷。如果你遇到任何缺陷,请在 [Issues](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues) 中报告。
#### Patchright 现在在每次发布后都会针对 Playwright 测试进行测试。参见[此处](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright-python/actions/workflows/patchright_tests.yml)
> [!WARNING]
> Patchright 通过了大多数但并非全部 Playwright 测试。有些缺陷被认为无法解决,有些则只是不相关。参见缺陷列表及其说明[此处](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/issues/30)。
#### 基于 Playwright 测试,我们得出结论:在常规使用场景中,你受到这些缺陷影响的可能性极低。
<details>
<summary><b>初始化脚本的玄机</b></summary>
### 说明
为了在不使用 [Runtime.enable](https://vanilla.aslushnikov.com/?Runtime.enable) 的情况下使用 InitScripts,Patchright 使用 Playwright Routes 将 JavaScript 注入 HTML 请求。
### 缺陷
Playwright Routes 可能会在你代码的其他部分引发一些缺陷。Patchright InitScripts 不会引发任何正常 Playwright Routes 不会引发的缺陷。</br> 如果你希望修复其中任何缺陷,你需要联系 Playwright 团队。
### 泄露风险
Patchright InitScripts 可以通过时序攻击被检测到。不过,目前没有任何反机器人系统会检查这类时序攻击,而且在相当长一段时间内很可能也不会有。</br> 我们认为它们不构成重大的检测风险。
</details>
---
### TODO
- [x] 实现选择执行上下文(Main/Isolated)的选项。
- [x] 修复可修复的缺陷。
- [x] 实现 .patch 更新器,以便轻松展示 Patchright 的补丁。
- [x] 在新版本发布时设置自动化测试。
- [x] 在 .NET 上实现 Patchright。
- [ ] 在 Java 上实现 Patchright。
---
## 开发
新的 Patchright 版本会自动部署,但由于 Playwright 代码库的变更,可能会出现缺陷。这些缺陷的修复可能需要几天时间才能发布。
---
## 支持我们的工作
如果你选择支持我们的工作,请在 Discord 上联系 [@vinyzu](https://discord.com/users/935224495126487150) 或 [@steve_abcdef](https://discord.com/users/936292409426477066)。
---
## 版权与许可
© [Vinyzu](https://github.com/Vinyzu/)
Patchright 采用 [Apache 2.0](https://choosealicense.com/licenses/apache-2.0/) 许可
[部分代码](https://github.com/Kaliiiiiiiiii-Vinyzu/patchright/blob/10c5a090e9a1dcd2107c253d65b3d8b27d0670a9/driver_patches/framesPatch.ts#L156-L171) 受到 [Driverless](https://github.com/kaliiiiiiiiii/Selenium-Driverless) 的启发。
感谢 [Nick Webson](https://github.com/rebrowser/rebrowser-patches) 提出的 .patch 文件文档化思路。
---
## 免责声明
本仓库仅供**教育目的**提供。\
不对准确性、完整性或任何用途的适用性提供任何保证。**使用风险自负**——作者和维护者对因使用、修改或分发此代码而导致的**任何损害**、**法律问题**或**保证违约**承担**不承担任何责任**。\
**任何误用或违法行为均由用户自行承担全部责任**。
---
## 作者
#### 现任维护者:[Vinyzu](https://github.com/Vinyzu/) </br> 联合维护者:[Kaliiiiiiiiii](https://github.com/kaliiiiiiiiii/)