fluxwright 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. fluxwright-0.4.0/Cargo.toml +49 -0
  2. fluxwright-0.4.0/LICENSE +176 -0
  3. fluxwright-0.4.0/PKG-INFO +133 -0
  4. fluxwright-0.4.0/README.md +107 -0
  5. fluxwright-0.4.0/bindings/python/.gitignore +6 -0
  6. fluxwright-0.4.0/bindings/python/Cargo.lock +1146 -0
  7. fluxwright-0.4.0/bindings/python/Cargo.toml +20 -0
  8. fluxwright-0.4.0/bindings/python/LICENSE +176 -0
  9. fluxwright-0.4.0/bindings/python/README.md +107 -0
  10. fluxwright-0.4.0/bindings/python/src/lib.rs +1085 -0
  11. fluxwright-0.4.0/bindings/python/tests/test_smoke.py +337 -0
  12. fluxwright-0.4.0/crates/fluxwright/Cargo.toml +26 -0
  13. fluxwright-0.4.0/crates/fluxwright/examples/amazon_iphones.rs +131 -0
  14. fluxwright-0.4.0/crates/fluxwright/examples/thousand_jobs.rs +74 -0
  15. fluxwright-0.4.0/crates/fluxwright/src/lib.rs +15 -0
  16. fluxwright-0.4.0/crates/fluxwright/tests/integration.rs +1209 -0
  17. fluxwright-0.4.0/crates/fluxwright-cdp/Cargo.toml +26 -0
  18. fluxwright-0.4.0/crates/fluxwright-cdp/src/browser.rs +586 -0
  19. fluxwright-0.4.0/crates/fluxwright-cdp/src/connection.rs +297 -0
  20. fluxwright-0.4.0/crates/fluxwright-cdp/src/context.rs +298 -0
  21. fluxwright-0.4.0/crates/fluxwright-cdp/src/error.rs +75 -0
  22. fluxwright-0.4.0/crates/fluxwright-cdp/src/launch.rs +460 -0
  23. fluxwright-0.4.0/crates/fluxwright-cdp/src/lib.rs +17 -0
  24. fluxwright-0.4.0/crates/fluxwright-cdp/src/log.rs +228 -0
  25. fluxwright-0.4.0/crates/fluxwright-cdp/src/page.rs +923 -0
  26. fluxwright-0.4.0/crates/fluxwright-cdp/src/query.js +300 -0
  27. fluxwright-0.4.0/crates/fluxwright-cdp/src/route.rs +162 -0
  28. fluxwright-0.4.0/crates/fluxwright-core/Cargo.toml +22 -0
  29. fluxwright-0.4.0/crates/fluxwright-core/src/config.rs +185 -0
  30. fluxwright-0.4.0/crates/fluxwright-core/src/error.rs +31 -0
  31. fluxwright-0.4.0/crates/fluxwright-core/src/lib.rs +12 -0
  32. fluxwright-0.4.0/crates/fluxwright-core/src/metrics.rs +35 -0
  33. fluxwright-0.4.0/crates/fluxwright-core/src/pool.rs +1201 -0
  34. fluxwright-0.4.0/crates/fluxwright-core/src/process.rs +148 -0
  35. fluxwright-0.4.0/crates/fluxwright-core/src/source.rs +20 -0
  36. fluxwright-0.4.0/pyproject.toml +45 -0
  37. fluxwright-0.4.0/python/fluxwright/__init__.py +12 -0
  38. fluxwright-0.4.0/python/fluxwright/_errors.py +20 -0
  39. fluxwright-0.4.0/python/fluxwright/_native.pyi +160 -0
  40. fluxwright-0.4.0/python/fluxwright/_types.py +45 -0
  41. fluxwright-0.4.0/python/fluxwright/async_api.py +521 -0
  42. fluxwright-0.4.0/python/fluxwright/py.typed +0 -0
  43. fluxwright-0.4.0/python/fluxwright/sync_api.py +574 -0
@@ -0,0 +1,49 @@
1
+ [workspace]
2
+ resolver = "2"
3
+ members = [
4
+ "crates/fluxwright-cdp",
5
+ "crates/fluxwright-core",
6
+ "crates/fluxwright",
7
+ "crates/fluxwright-cli",
8
+ "crates/fluxwright-mcp",
9
+ "benchmark-server",
10
+ "benchmarks",
11
+ ]
12
+ exclude = ["bindings/node", "bindings/python"]
13
+
14
+ [workspace.package]
15
+ version = "0.1.0"
16
+ edition = "2021"
17
+ license = "Apache-2.0"
18
+ repository = "https://github.com/harshit-d3v/fluxwright"
19
+ rust-version = "1.85"
20
+
21
+ [workspace.dependencies]
22
+ fluxwright-cdp = { path = "crates/fluxwright-cdp", version = "0.1.0" }
23
+ fluxwright-core = { path = "crates/fluxwright-core", version = "0.1.0" }
24
+ fluxwright = { path = "crates/fluxwright", version = "0.1.0" }
25
+ benchmark-server = { path = "benchmark-server", version = "0.1.0" }
26
+
27
+ tokio = { version = "1.47", features = ["full"] }
28
+ tokio-tungstenite = "0.26"
29
+ futures-util = "0.3"
30
+ serde = { version = "1.0", features = ["derive"] }
31
+ serde_json = "1.0"
32
+ thiserror = "2.0"
33
+ tracing = "0.1"
34
+ tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }
35
+ uuid = { version = "1.11", features = ["v4", "serde"] }
36
+ tempfile = "3.13"
37
+ sysinfo = "0.33"
38
+ bytes = "1.9"
39
+ clap = { version = "4.5", features = ["derive"] }
40
+ axum = "0.8"
41
+ http-body-util = "0.1"
42
+ hyper = { version = "1.6", features = ["http1", "server"] }
43
+ hyper-util = { version = "0.1", features = ["tokio"] }
44
+ anyhow = "1.0"
45
+ parking_lot = "0.12"
46
+ async-trait = "0.1"
47
+ base64 = "0.22"
48
+ napi = { version = "2.16", default-features = false, features = ["napi8", "async", "serde-json"] }
49
+ napi-derive = "2.16"
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,133 @@
1
+ Metadata-Version: 2.4
2
+ Name: fluxwright
3
+ Version: 0.4.0
4
+ Classifier: Development Status :: 4 - Beta
5
+ Classifier: Framework :: AsyncIO
6
+ Classifier: Intended Audience :: Developers
7
+ Classifier: Operating System :: Microsoft :: Windows
8
+ Classifier: Operating System :: MacOS
9
+ Classifier: Operating System :: POSIX :: Linux
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Rust
12
+ Classifier: Topic :: Internet :: WWW/HTTP :: Browsers
13
+ Classifier: Topic :: Software Development :: Testing
14
+ Classifier: Typing :: Typed
15
+ License-File: LICENSE
16
+ Summary: Run hundreds of headless Chrome jobs on one machine: pooling, queueing, recycling and crash recovery, with a Playwright-style API.
17
+ Keywords: chromium,chrome,headless,playwright,puppeteer,browser-pool,browser-automation,scraping,cdp
18
+ Author: Fluxwright contributors
19
+ License-Expression: Apache-2.0
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
22
+ Project-URL: Homepage, https://fluxwright.vercel.app
23
+ Project-URL: Issues, https://github.com/harshit-d3v/fluxwright/issues
24
+ Project-URL: Repository, https://github.com/harshit-d3v/fluxwright
25
+
26
+ # fluxwright
27
+
28
+ Run hundreds of headless Chrome jobs on one machine, with a Playwright-style API. Each `new_page` is a fresh browser context on a pooled Chrome. The engine queues jobs when every slot is busy, restarts browsers before they bloat, and replaces browsers that crash.
29
+
30
+ Docs: https://fluxwright.vercel.app
31
+
32
+ Requires a local Chrome/Chromium binary (`FLUXWRIGHT_CHROMIUM`, `CHROME`, `CHROMIUM`, or a standard install path). For headless jobs, chrome-headless-shell is picked up from `PATH` or Puppeteer's/Playwright's cache and opens pages much faster: `npx @puppeteer/browsers install chrome-headless-shell@stable`.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install fluxwright
38
+ ```
39
+
40
+ Wheels cover Windows x64, macOS (Intel and Apple Silicon) and Linux x86_64, for Python 3.10 and newer. Anywhere else, pip builds from source, which needs Rust.
41
+
42
+ ## Use
43
+
44
+ asyncio:
45
+
46
+ ```python
47
+ import asyncio
48
+ from fluxwright.async_api import async_playwright
49
+
50
+ async def main():
51
+ async with async_playwright() as p:
52
+ browser = await p.chromium.launch(max_browsers=4)
53
+ page = await browser.new_page()
54
+ await page.goto("https://example.com")
55
+ print(await page.get_by_role("heading").text_content()) # "Example Domain"
56
+ print(await page.evaluate("() => location.hostname"))
57
+ png = await page.screenshot(full_page=True) # bytes
58
+ await page.close()
59
+ await browser.close()
60
+
61
+ asyncio.run(main())
62
+ ```
63
+
64
+ Blocking code:
65
+
66
+ ```python
67
+ from fluxwright.sync_api import sync_playwright
68
+
69
+ with sync_playwright() as p:
70
+ browser = p.chromium.launch()
71
+ page = browser.new_page()
72
+ page.goto("https://example.com")
73
+ print(page.title())
74
+ browser.close()
75
+ ```
76
+
77
+ The names are Playwright's, so a Playwright script for the features below runs after changing `playwright.async_api` to `fluxwright.async_api` (or `sync_api`). `chromium` can also be imported directly: `from fluxwright.async_api import chromium`.
78
+
79
+ Many jobs at once: start them all and let the engine queue them.
80
+
81
+ ```python
82
+ async def job(browser, url):
83
+ page = await browser.new_page()
84
+ try:
85
+ await page.goto(url)
86
+ return await page.title()
87
+ finally:
88
+ await page.close()
89
+
90
+ titles = await asyncio.gather(*(job(browser, url) for url in urls))
91
+ ```
92
+
93
+ The sync API runs every call on one event loop in a background thread, so its objects work from any thread: a `ThreadPoolExecutor` of jobs sharing one browser is fine (Playwright's sync API does not allow that).
94
+
95
+ ### API
96
+
97
+ | Method | What it does |
98
+ |---|---|
99
+ | `chromium.launch(max_browsers=None, executable_path=None, headless=None)` | Start the pool (4 browsers by default). Headless uses chrome-headless-shell when installed (as Playwright does), else Chrome; `FLUXWRIGHT_CHROMIUM` or `executable_path` overrides |
100
+ | `browser.new_page(...)` | A fresh browser context. Every option applies to this page only: `proxy={"server", "bypass", "username", "password"}`, `user_agent`, `locale`, `timezone_id`, `geolocation={"latitude", "longitude", "accuracy"}` (with `permissions=["geolocation"]`), `permissions`, `viewport={"width", "height"}`, `device_scale_factor`, `color_scheme`, `storage_state` (a dict or a file path) |
101
+ | `page.storage_state(path=None)` | Every cookie in the context plus localStorage of the current origin, in Playwright's format. With `path`, also saved as JSON for `new_page(storage_state=path)` |
102
+ | `page.goto(url, wait_until=None)` | Navigate. `wait_until`: `load` (default), `domcontentloaded`, `networkidle`, `commit` |
103
+ | `page.title()` / `page.content()` | Read |
104
+ | `page.click(selector)` / `page.fill(selector, value)` | Scrolls into view, waits until enabled, stable, and not covered. Selector: CSS, `text=Foo`, `text="Exact"`, `role=button[name="Save"]` |
105
+ | `page.get_by_role(role, name=None, exact=None)` / `get_by_text(text, exact=None)` / `get_by_label` / `get_by_placeholder` / `get_by_test_id(id)` / `page.locator(selector)` | A `Locator` with `click()`, `fill(v)`, `wait_for()`, `text_content()`, `bounding_box()`, `screenshot(path=None)` and `evaluate("(el, arg) => ...", arg)` |
106
+ | `locator.nth(i)` / `.first` / `.last` / `filter(has_text=...)` / `locator.get_by_role(...)` and the other finders | Narrow a locator: by position (negative counts from the end), by contained text (case-insensitive), or by searching inside its matches |
107
+ | `page.frame_locator(iframe_selector)` | The same finders inside an iframe, same- or cross-origin; nest with `.frame_locator()` |
108
+ | `page.evaluate(expression, arg=None)` | Runs JavaScript in the page and returns its JSON result, awaiting promises. A function (`"(x) => x * 2"`) is called with `arg`; anything else is evaluated as is. A thrown error raises `fluxwright.Error` |
109
+ | `page.screenshot(full_page=None, path=None)` | PNG bytes, also written to `path` |
110
+ | `page.route(url, handler)` / `page.unroute(url, handler=None)` | Request interception: `url` is a glob (`**/api/*`), a compiled regex or a function of the URL; the handler gets `route` (and `request`, if it takes two arguments) and answers with `route.fulfill(status, headers, body, json, path, content_type)`, `route.continue_(url, method, headers, post_data)`, `route.abort(error_code)` or `route.fallback()`. The handler added last runs first |
111
+ | `page.on("console" \| "pageerror", handler)` / `once` / `remove_listener` | Console messages (`.type`, `.text`) and uncaught errors (`fluxwright.Error` with `.name`, `.message`, `.stack`) as they happen |
112
+ | `page.expect_download(timeout=None)` / `page.wait_for_download(timeout=None)` | The next download the page finished: `.url`, `.suggested_filename`, `path()`, `save_as(path)`. Files are deleted when the page closes |
113
+ | `page.console_messages()` / `page.page_errors()` | What the page, its popups and iframes logged, and the exceptions nothing caught, the last 1000 of each. Fail a job with `assert await page.page_errors() == []` |
114
+ | `page.set_viewport_size({"width", "height"})` | CSS-pixel viewport for this page |
115
+ | `page.wait_for_selector(selector)` | Waits until visible (Playwright's default state) |
116
+ | `page.close()` / `browser.close()` | Dispose the context / shut down |
117
+
118
+ Timeouts are in milliseconds, as in Playwright. Errors are `fluxwright.Error`, and `fluxwright.TimeoutError` when something ran out of time. Close pages when a job is done; a page you forget is cleaned up when Python collects it.
119
+
120
+ In the sync API, route handlers run on worker threads and event listeners one at a time on a thread of their own, so both can call the page.
121
+
122
+ ## Develop
123
+
124
+ ```bash
125
+ pip install maturin pytest
126
+ maturin develop # needs Rust
127
+ pytest # against a real Chrome
128
+ ```
129
+
130
+ ## License
131
+
132
+ Licensed under the [Apache License, Version 2.0](LICENSE).
133
+
@@ -0,0 +1,107 @@
1
+ # fluxwright
2
+
3
+ Run hundreds of headless Chrome jobs on one machine, with a Playwright-style API. Each `new_page` is a fresh browser context on a pooled Chrome. The engine queues jobs when every slot is busy, restarts browsers before they bloat, and replaces browsers that crash.
4
+
5
+ Docs: https://fluxwright.vercel.app
6
+
7
+ Requires a local Chrome/Chromium binary (`FLUXWRIGHT_CHROMIUM`, `CHROME`, `CHROMIUM`, or a standard install path). For headless jobs, chrome-headless-shell is picked up from `PATH` or Puppeteer's/Playwright's cache and opens pages much faster: `npx @puppeteer/browsers install chrome-headless-shell@stable`.
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install fluxwright
13
+ ```
14
+
15
+ Wheels cover Windows x64, macOS (Intel and Apple Silicon) and Linux x86_64, for Python 3.10 and newer. Anywhere else, pip builds from source, which needs Rust.
16
+
17
+ ## Use
18
+
19
+ asyncio:
20
+
21
+ ```python
22
+ import asyncio
23
+ from fluxwright.async_api import async_playwright
24
+
25
+ async def main():
26
+ async with async_playwright() as p:
27
+ browser = await p.chromium.launch(max_browsers=4)
28
+ page = await browser.new_page()
29
+ await page.goto("https://example.com")
30
+ print(await page.get_by_role("heading").text_content()) # "Example Domain"
31
+ print(await page.evaluate("() => location.hostname"))
32
+ png = await page.screenshot(full_page=True) # bytes
33
+ await page.close()
34
+ await browser.close()
35
+
36
+ asyncio.run(main())
37
+ ```
38
+
39
+ Blocking code:
40
+
41
+ ```python
42
+ from fluxwright.sync_api import sync_playwright
43
+
44
+ with sync_playwright() as p:
45
+ browser = p.chromium.launch()
46
+ page = browser.new_page()
47
+ page.goto("https://example.com")
48
+ print(page.title())
49
+ browser.close()
50
+ ```
51
+
52
+ The names are Playwright's, so a Playwright script for the features below runs after changing `playwright.async_api` to `fluxwright.async_api` (or `sync_api`). `chromium` can also be imported directly: `from fluxwright.async_api import chromium`.
53
+
54
+ Many jobs at once: start them all and let the engine queue them.
55
+
56
+ ```python
57
+ async def job(browser, url):
58
+ page = await browser.new_page()
59
+ try:
60
+ await page.goto(url)
61
+ return await page.title()
62
+ finally:
63
+ await page.close()
64
+
65
+ titles = await asyncio.gather(*(job(browser, url) for url in urls))
66
+ ```
67
+
68
+ The sync API runs every call on one event loop in a background thread, so its objects work from any thread: a `ThreadPoolExecutor` of jobs sharing one browser is fine (Playwright's sync API does not allow that).
69
+
70
+ ### API
71
+
72
+ | Method | What it does |
73
+ |---|---|
74
+ | `chromium.launch(max_browsers=None, executable_path=None, headless=None)` | Start the pool (4 browsers by default). Headless uses chrome-headless-shell when installed (as Playwright does), else Chrome; `FLUXWRIGHT_CHROMIUM` or `executable_path` overrides |
75
+ | `browser.new_page(...)` | A fresh browser context. Every option applies to this page only: `proxy={"server", "bypass", "username", "password"}`, `user_agent`, `locale`, `timezone_id`, `geolocation={"latitude", "longitude", "accuracy"}` (with `permissions=["geolocation"]`), `permissions`, `viewport={"width", "height"}`, `device_scale_factor`, `color_scheme`, `storage_state` (a dict or a file path) |
76
+ | `page.storage_state(path=None)` | Every cookie in the context plus localStorage of the current origin, in Playwright's format. With `path`, also saved as JSON for `new_page(storage_state=path)` |
77
+ | `page.goto(url, wait_until=None)` | Navigate. `wait_until`: `load` (default), `domcontentloaded`, `networkidle`, `commit` |
78
+ | `page.title()` / `page.content()` | Read |
79
+ | `page.click(selector)` / `page.fill(selector, value)` | Scrolls into view, waits until enabled, stable, and not covered. Selector: CSS, `text=Foo`, `text="Exact"`, `role=button[name="Save"]` |
80
+ | `page.get_by_role(role, name=None, exact=None)` / `get_by_text(text, exact=None)` / `get_by_label` / `get_by_placeholder` / `get_by_test_id(id)` / `page.locator(selector)` | A `Locator` with `click()`, `fill(v)`, `wait_for()`, `text_content()`, `bounding_box()`, `screenshot(path=None)` and `evaluate("(el, arg) => ...", arg)` |
81
+ | `locator.nth(i)` / `.first` / `.last` / `filter(has_text=...)` / `locator.get_by_role(...)` and the other finders | Narrow a locator: by position (negative counts from the end), by contained text (case-insensitive), or by searching inside its matches |
82
+ | `page.frame_locator(iframe_selector)` | The same finders inside an iframe, same- or cross-origin; nest with `.frame_locator()` |
83
+ | `page.evaluate(expression, arg=None)` | Runs JavaScript in the page and returns its JSON result, awaiting promises. A function (`"(x) => x * 2"`) is called with `arg`; anything else is evaluated as is. A thrown error raises `fluxwright.Error` |
84
+ | `page.screenshot(full_page=None, path=None)` | PNG bytes, also written to `path` |
85
+ | `page.route(url, handler)` / `page.unroute(url, handler=None)` | Request interception: `url` is a glob (`**/api/*`), a compiled regex or a function of the URL; the handler gets `route` (and `request`, if it takes two arguments) and answers with `route.fulfill(status, headers, body, json, path, content_type)`, `route.continue_(url, method, headers, post_data)`, `route.abort(error_code)` or `route.fallback()`. The handler added last runs first |
86
+ | `page.on("console" \| "pageerror", handler)` / `once` / `remove_listener` | Console messages (`.type`, `.text`) and uncaught errors (`fluxwright.Error` with `.name`, `.message`, `.stack`) as they happen |
87
+ | `page.expect_download(timeout=None)` / `page.wait_for_download(timeout=None)` | The next download the page finished: `.url`, `.suggested_filename`, `path()`, `save_as(path)`. Files are deleted when the page closes |
88
+ | `page.console_messages()` / `page.page_errors()` | What the page, its popups and iframes logged, and the exceptions nothing caught, the last 1000 of each. Fail a job with `assert await page.page_errors() == []` |
89
+ | `page.set_viewport_size({"width", "height"})` | CSS-pixel viewport for this page |
90
+ | `page.wait_for_selector(selector)` | Waits until visible (Playwright's default state) |
91
+ | `page.close()` / `browser.close()` | Dispose the context / shut down |
92
+
93
+ Timeouts are in milliseconds, as in Playwright. Errors are `fluxwright.Error`, and `fluxwright.TimeoutError` when something ran out of time. Close pages when a job is done; a page you forget is cleaned up when Python collects it.
94
+
95
+ In the sync API, route handlers run on worker threads and event listeners one at a time on a thread of their own, so both can call the page.
96
+
97
+ ## Develop
98
+
99
+ ```bash
100
+ pip install maturin pytest
101
+ maturin develop # needs Rust
102
+ pytest # against a real Chrome
103
+ ```
104
+
105
+ ## License
106
+
107
+ Licensed under the [Apache License, Version 2.0](LICENSE).
@@ -0,0 +1,6 @@
1
+ .venv/
2
+ __pycache__/
3
+ *.pyd
4
+ *.so
5
+ target/
6
+ dist/