|
1 |
| -# 🎭 [Playwright](https://playwright.dev) for Python [](https://pypi.python.org/pypi/playwright/) [](https://anaconda.org/Microsoft/playwright) [](https://aka.ms/playwright/discord) |
| 1 | +# 🎭 [Playwright](https://playwright.dev) for Python |
2 | 2 |
|
3 |
| -Playwright is a Python library to automate [Chromium](https://www.chromium.org/Home), [Firefox](https://www.mozilla.org/en-US/firefox/new/) and [WebKit](https://webkit.org/) browsers with a single API. Playwright delivers automation that is **ever-green**, **capable**, **reliable** and **fast**. [See how Playwright is better](https://playwright.dev/python/docs/why-playwright). |
| 3 | +[](https://badge.fury.io/py/undetected-playwright-patch) |
4 | 4 |
|
| 5 | +This is a patch of the original playwright implementation for Python. |
5 | 6 |
|
6 |
| -## Documentation |
| 7 | +It currently passes for sure (tested on Win10): |
| 8 | +- ✅ [CloudFare] |
| 9 | +- ✅ [Bet365] (shape//F5 I think) |
| 10 | +- [Others] Unknown/Not tested |
7 | 11 |
|
8 |
| -[https://playwright.dev/python/docs/intro](https://playwright.dev/python/docs/intro) |
| 12 | +Warnings: |
| 13 | +* the **Only chromium** part for Playwright is patched. |
9 | 14 |
|
10 |
| -## API Reference |
| 15 | +## Demos (tested on Win 10) |
| 16 | + |
| 17 | + |
11 | 18 |
|
12 |
| -[https://playwright.dev/python/docs/api/class-playwright](https://playwright.dev/python/docs/api/class-playwright) |
| 19 | + |
| 20 | +## Dependencies |
| 21 | + |
| 22 | +* Google-Chrome installed (`channel="chrome"` recommended, default) |
| 23 | + |
| 24 | +## Installation |
| 25 | + |
| 26 | +#### From PyPi (recommended) |
| 27 | + |
| 28 | +execute in your shell console |
| 29 | +```shell |
| 30 | +pip install undetected-playwright-patch |
| 31 | +``` |
| 32 | + |
| 33 | +#### Build from this repo: |
| 34 | +``` |
| 35 | +git clone https://github.com/kaliiiiiiiiii/undetected-playwright-python |
| 36 | +cd undetected-playwright-python |
| 37 | +python -m pip install -r local-requirements.txt |
| 38 | +python build_patched.py |
| 39 | +``` |
13 | 40 |
|
14 | 41 | ## Example
|
15 | 42 |
|
| 43 | +```python |
| 44 | +import asyncio |
| 45 | + |
| 46 | +# undetected-playwright here! |
| 47 | +from undetected_playwright.async_api import async_playwright, Playwright |
| 48 | + |
| 49 | + |
| 50 | +async def run(playwright: Playwright): |
| 51 | + args = [] |
| 52 | + |
| 53 | + # disable navigator.webdriver:true flag |
| 54 | + args.append("--disable-blink-features=AutomationControlled") |
| 55 | + browser = await playwright.chromium.launch(headless=False, |
| 56 | + args=args) |
| 57 | + page = await browser.new_page() |
| 58 | + await page.goto("https://nowsecure.nl/#relax") |
| 59 | + input("Press ENTER to continue to Creep-JS:") |
| 60 | + await page.goto("https://nowsecure.nl/#relax") |
| 61 | + await page.goto("https://abrahamjuliot.github.io/creepjs/") |
| 62 | + input("Press ENTER to exit:") |
| 63 | + await browser.close() |
| 64 | + |
| 65 | + |
| 66 | +async def main(): |
| 67 | + async with async_playwright() as playwright: |
| 68 | + await run(playwright) |
| 69 | + |
| 70 | + |
| 71 | +if __name__ == "__main__": |
| 72 | + loop = asyncio.ProactorEventLoop() |
| 73 | + loop.run_until_complete(main()) |
| 74 | + # asyncio.run(main) # should work for non-Windows as well |
| 75 | +``` |
| 76 | + |
16 | 77 | ```py
|
| 78 | + |
| 79 | +# undetected-playwright here! |
17 | 80 | from undetected_playwright.sync_api import sync_playwright
|
18 | 81 |
|
| 82 | + |
19 | 83 | with sync_playwright() as p:
|
20 |
| - for browser_type in [p.chromium, p.firefox, p.webkit]: |
21 |
| - browser = browser_type.launch() |
22 |
| - page = browser.new_page() |
23 |
| - page.goto('http://playwright.dev') |
24 |
| - page.screenshot(path=f'example-{browser_type.name}.png') |
25 |
| - browser.close() |
| 84 | + args = [] |
| 85 | + |
| 86 | + # disable navigator.webdriver:true flag |
| 87 | + args.append("--disable-blink-features=AutomationControlled") |
| 88 | + browser = p.chromium.launch(args=args, headless=False) |
| 89 | + page = browser.new_page() |
| 90 | + page.goto("https://nowsecure.nl/#relax") |
| 91 | + input("Press ENTER to continue to Creep-JS:") |
| 92 | + page.goto("https://nowsecure.nl/#relax") |
| 93 | + page.goto("https://abrahamjuliot.github.io/creepjs/") |
| 94 | + input("Press ENTER to exit:") |
| 95 | + browser.close() |
26 | 96 | ```
|
27 | 97 |
|
28 |
| -```py |
29 |
| -import asyncio |
30 |
| -from undetected_playwright.async_api import async_playwright |
| 98 | +## Documentation |
31 | 99 |
|
| 100 | +See the original |
| 101 | +[https://playwright.dev/python/docs/intro](https://playwright.dev/python/docs/intro) |
32 | 102 |
|
33 |
| -async def main(): |
34 |
| - async with async_playwright() as p: |
35 |
| - for browser_type in [p.chromium, p.firefox, p.webkit]: |
36 |
| - browser = await browser_type.launch() |
37 |
| - page = await browser.new_page() |
38 |
| - await page.goto('http://playwright.dev') |
39 |
| - await page.screenshot(path=f'example-{browser_type.name}.png') |
40 |
| - await browser.close() |
| 103 | +## API Reference |
| 104 | + |
| 105 | +[https://playwright.dev/python/docs/api/class-playwright](https://playwright.dev/python/docs/api/class-playwright) |
41 | 106 |
|
42 | 107 |
|
43 |
| -asyncio.run(main()) |
44 |
| -``` |
45 | 108 |
|
46 |
| -## Other languages |
| 109 | +## Patches |
| 110 | +- [ ] [`Runtime.enable`](https://chromedevtools.github.io/devtools-protocol/tot/Runtime/#method-enable) |
| 111 | + - [x] remove Runtime.enable occurences |
| 112 | + - [x] patch _context(world) getter |
| 113 | + - [x] isolatedWorld (utility) |
| 114 | + - [ ] main world (main) |
| 115 | + - [x] reset on frame-reload//navigation |
47 | 116 |
|
48 |
| -More comfortable in another programming language? [Playwright](https://playwright.dev) is also available in |
49 |
| -- [Node.js (JavaScript / TypeScript)](https://playwright.dev/docs/intro), |
50 |
| -- [.NET](https://playwright.dev/dotnet/docs/intro), |
51 |
| -- [Java](https://playwright.dev/java/docs/intro). |
| 117 | +## TODO's |
| 118 | +- [ ] add GitHub runner to build releases automated |
0 commit comments