gecko-web-runtime-client 1.3.0__tar.gz → 1.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.
- gecko_web_runtime_client-1.4.0/PACKAGE_README.md +17 -0
- gecko_web_runtime_client-1.4.0/PKG-INFO +32 -0
- gecko_web_runtime_client-1.3.0/PKG-INFO → gecko_web_runtime_client-1.4.0/README.md +96 -14
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/__init__.py +71 -71
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/__main__.py +23 -23
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/_leases.py +4 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/__init__.py +7 -7
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/context.py +110 -110
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/page.py +384 -350
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/pool.py +146 -146
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/runtime.py +186 -186
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/data_plane.py +4 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/diagnostics/__init__.py +14 -14
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/diagnostics/gc_cc.py +68 -68
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/diagnostics/logging.py +39 -39
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/diagnostics/memory.py +194 -194
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/diagnostics/metrics.py +551 -551
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/diagnostics/resources.py +60 -60
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/http.py +41 -41
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/installer.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/iocp_pipe.py +4 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/models/__init__.py +5 -5
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/models/navigation.py +41 -41
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/network/__init__.py +3 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/network/_urls.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/network/client.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/network/exceptions.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/network/models.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/network/transport.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/pipe.py +4 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/session.py +608 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/workflows/__init__.py +6 -6
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/workflows/turnstile.py +680 -680
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/workflows/wechat.py +861 -706
- gecko_web_runtime_client-1.4.0/gecko_web_runtime/workflows/wechat_challenge.py +126 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime_client.egg-info/PKG-INFO +32 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime_client.egg-info/SOURCES.txt +2 -0
- gecko_web_runtime_client-1.4.0/gecko_web_runtime_client.egg-info/requires.txt +5 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/pyproject.toml +39 -35
- gecko_web_runtime_client-1.3.0/README.md +0 -500
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/_leases.py +0 -120
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/data_plane.py +0 -142
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/installer.py +0 -226
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/iocp_pipe.py +0 -204
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/network/__init__.py +0 -31
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/network/_urls.py +0 -31
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/network/client.py +0 -571
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/network/exceptions.py +0 -207
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/network/models.py +0 -292
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/network/transport.py +0 -118
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/pipe.py +0 -163
- gecko_web_runtime_client-1.3.0/gecko_web_runtime/session.py +0 -1350
- gecko_web_runtime_client-1.3.0/gecko_web_runtime_client.egg-info/PKG-INFO +0 -511
- gecko_web_runtime_client-1.3.0/gecko_web_runtime_client.egg-info/requires.txt +0 -3
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime_client.egg-info/dependency_links.txt +0 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime_client.egg-info/top_level.txt +0 -0
- {gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/setup.cfg +0 -0
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Gecko Web Runtime Client
|
|
2
|
+
|
|
3
|
+
Python page and browser client for a versioned Firefox-derived WPR runtime.
|
|
4
|
+
It exposes pages, contexts, navigation, DOM access, screenshots, diagnostics,
|
|
5
|
+
Turnstile and WeChat workflow adapters.
|
|
6
|
+
|
|
7
|
+
The native runtime is installed separately:
|
|
8
|
+
|
|
9
|
+
```powershell
|
|
10
|
+
python -m gecko_web_runtime install-runtime --version 155
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
The runtime is held in a private GitHub Release. Automatic download needs
|
|
14
|
+
access to `childclm/gecko-web-runtime`. The Python client depends on
|
|
15
|
+
`wpr-runtime-core` for Worker lifecycle and protocol compatibility. Historical
|
|
16
|
+
HTTP imports are retained through `wpr-http`.
|
|
17
|
+
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: gecko-web-runtime-client
|
|
3
|
+
Version: 1.4.0
|
|
4
|
+
Summary: Thin Python client for the Firefox-derived WPR Gecko Worker protocol
|
|
5
|
+
Author: WPR project
|
|
6
|
+
License: MPL-2.0-compatible client; see the runtime bundle notices
|
|
7
|
+
Project-URL: Repository, https://github.com/childclm/gecko-web-runtime-client
|
|
8
|
+
Project-URL: Documentation, https://github.com/childclm/gecko-web-runtime-client/blob/main/README.md
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
Requires-Dist: wpr-runtime-core<0.3,>=0.2.0
|
|
12
|
+
Requires-Dist: wpr-http<0.3,>=0.2.0
|
|
13
|
+
Provides-Extra: diagnostics
|
|
14
|
+
Requires-Dist: loguru>=0.7.2; extra == "diagnostics"
|
|
15
|
+
|
|
16
|
+
# Gecko Web Runtime Client
|
|
17
|
+
|
|
18
|
+
Python page and browser client for a versioned Firefox-derived WPR runtime.
|
|
19
|
+
It exposes pages, contexts, navigation, DOM access, screenshots, diagnostics,
|
|
20
|
+
Turnstile and WeChat workflow adapters.
|
|
21
|
+
|
|
22
|
+
The native runtime is installed separately:
|
|
23
|
+
|
|
24
|
+
```powershell
|
|
25
|
+
python -m gecko_web_runtime install-runtime --version 155
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
The runtime is held in a private GitHub Release. Automatic download needs
|
|
29
|
+
access to `childclm/gecko-web-runtime`. The Python client depends on
|
|
30
|
+
`wpr-runtime-core` for Worker lifecycle and protocol compatibility. Historical
|
|
31
|
+
HTTP imports are retained through `wpr-http`.
|
|
32
|
+
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: gecko-web-runtime-client
|
|
3
|
-
Version: 1.3.0
|
|
4
|
-
Summary: Thin Python client for the Firefox-derived WPR Gecko Worker protocol
|
|
5
|
-
Author: WPR project
|
|
6
|
-
License: MPL-2.0-compatible client; see the runtime bundle notices
|
|
7
|
-
Requires-Python: >=3.10
|
|
8
|
-
Description-Content-Type: text/markdown
|
|
9
|
-
Provides-Extra: diagnostics
|
|
10
|
-
Requires-Dist: loguru>=0.7.2; extra == "diagnostics"
|
|
11
|
-
|
|
12
1
|
# Python client
|
|
13
2
|
|
|
3
|
+
Version `1.3.1` pins runtime `155.0.6` with the native autonomous-navigation
|
|
4
|
+
viewport repair. Upgrade the client, then run
|
|
5
|
+
`python -m gecko_web_runtime install-runtime --version 155` to replace an older
|
|
6
|
+
runtime in place. The Python workflow API and HTTP concurrency defaults are unchanged.
|
|
7
|
+
|
|
14
8
|
Version `1.3.0` defaults to one Worker, 20 Channels,
|
|
15
9
|
`ipc_backend="iocp"` and `release_mode="piggyback"`. Published version 1.2.0
|
|
16
10
|
still defaults to one Channel, threaded IPC and immediate release. Runtime
|
|
@@ -30,6 +24,18 @@ bundle. Override paths with `WPR_RUNTIME_HOME`, `WPR_RUNTIME_DIR`,
|
|
|
30
24
|
`WPR_WORKER_EXE`, `WPR_PROFILE_ROOT`, or `WPR_LOG_ROOT` when embedding it in a
|
|
31
25
|
larger application.
|
|
32
26
|
|
|
27
|
+
### Current native fpfile options
|
|
28
|
+
|
|
29
|
+
[`examples/fpfile.current.example`](examples/fpfile.current.example) lists the
|
|
30
|
+
current Firefox 155 candidate's implemented fpfile options: six screen/window
|
|
31
|
+
dimensions and aliases, `canvas.mode` / `canvas.seed`, `language`, `timezone`,
|
|
32
|
+
and the supported WebRTC policy/address fields. Other keys from the wider
|
|
33
|
+
fpfile format, including Audio, WebGL, fonts, and proxy credentials, are not
|
|
34
|
+
applied by this candidate. Use a Worker built with the matching native
|
|
35
|
+
candidate; earlier bundled runtime binaries predate timezone support and ignore
|
|
36
|
+
that key. `webrtc.output_only` changes exposed candidate presentation; it does
|
|
37
|
+
not route or tunnel UDP traffic.
|
|
38
|
+
|
|
33
39
|
## Firefox Necko network client
|
|
34
40
|
|
|
35
41
|
The version-neutral `wpr-http-v1` API is exposed by
|
|
@@ -316,6 +322,18 @@ async with AsyncGeckoWorkerSession(
|
|
|
316
322
|
await session.page_create()
|
|
317
323
|
```
|
|
318
324
|
|
|
325
|
+
Canvas extraction uses Firefox's native behavior by default. To opt into
|
|
326
|
+
Firefox's pixel-randomization target, add `canvas.mode=pixel` to the fpfile.
|
|
327
|
+
This enables `CanvasRandomization` and disables `EfficientCanvasRandomization`
|
|
328
|
+
for that Worker in both normal and private contexts without enabling the full
|
|
329
|
+
FPP set in normal browsing. `canvas.mode=native`
|
|
330
|
+
retains the Firefox 155 defaults. Pixel mode can alter known-color Canvas
|
|
331
|
+
readbacks, so choose it explicitly for each Worker. Test on an HTTP(S) origin;
|
|
332
|
+
Firefox does not apply this protection to the local `file://` fixture.
|
|
333
|
+
Pixel mode is observable to a page that exports the Canvas, draws the result
|
|
334
|
+
into another Canvas, and reads it again: the second extraction is randomized.
|
|
335
|
+
The native default avoids that pixel-level inconsistency.
|
|
336
|
+
|
|
319
337
|
For application code, prefer the high-level runtime facade and workflow
|
|
320
338
|
adapter. Frame handles, pointer coordinates, WindowGlobal rebinding and
|
|
321
339
|
challenge waits remain internal:
|
|
@@ -486,9 +504,56 @@ for request in pending:
|
|
|
486
504
|
await session.page_permission_respond(request["callID"], "allow")
|
|
487
505
|
```
|
|
488
506
|
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
507
|
+
Content permissions, including Local Network Access, are also returned with
|
|
508
|
+
`kind="content_permission"`, `types`, `origin`, and `topOrigin`. They are scoped
|
|
509
|
+
to the owning page/document. Unanswered content requests expire with denial
|
|
510
|
+
after ten seconds; closing the page or replacing its document cancels them.
|
|
511
|
+
WebRTC requests retain their existing observer protocol and lifecycle.
|
|
512
|
+
|
|
513
|
+
`Page.permission_requests()` and `Page.respond_permission(call_id, decision)`
|
|
514
|
+
expose the same scoped interface. To inspect a partially loaded document first,
|
|
515
|
+
use `await page.navigate(url, wait_until="commit")`. Default load navigation
|
|
516
|
+
raises `WprProtocolError(code="PERMISSION_REQUIRED")` when a permission blocks
|
|
517
|
+
loading. Errors expose `rv`, `phase`, and `details` instead of silently reporting
|
|
518
|
+
success. A real load timeout uses `NAVIGATION_TIMEOUT`.
|
|
519
|
+
|
|
520
|
+
The WeChat adapter observes state after commit and accepts an explicit policy:
|
|
521
|
+
|
|
522
|
+
```python
|
|
523
|
+
workflow = WechatArticleWorkflow(permission_policy={
|
|
524
|
+
"https://mp.weixin.qq.com": {"local-network": "allow"},
|
|
525
|
+
})
|
|
526
|
+
```
|
|
527
|
+
|
|
528
|
+
This grants only the named permission for that exact top-level origin when
|
|
529
|
+
Firefox requests it, and does not grant loopback access or permissions to other
|
|
530
|
+
sites. The default policy reports the pending decision without auto-allowing it.
|
|
531
|
+
Callers should enable this only when their local network setup requires it.
|
|
532
|
+
|
|
533
|
+
`proxy=""` now explicitly disables both configured and system HTTP proxies
|
|
534
|
+
in the Worker profile; `proxy=None` retains configured/default behavior. This
|
|
535
|
+
does not turn off external fake-IP DNS or TUN routing. These changes require
|
|
536
|
+
the local permission-fix native build; they are not yet a published release.
|
|
537
|
+
|
|
538
|
+
The adapter also resynchronizes a measured zero viewport through the native
|
|
539
|
+
page-scoped surface RPC before sampling again. Automatic Tencent popups are
|
|
540
|
+
classified from the nested frame and popup state instead of waiting for an
|
|
541
|
+
unusable outer gate button. It never treats hidden preload alone as article
|
|
542
|
+
success or confirmation that a slider was solved.
|
|
543
|
+
|
|
544
|
+
Verification classification uses visible task text plus actual task controls
|
|
545
|
+
and media evidence. Tencent CSS backgrounds (`#slideBg`) with completed resource
|
|
546
|
+
entries and `.tc-slider-normal` controls are supported, alongside images/canvas.
|
|
547
|
+
Network/image loading errors, unknown/loading states, and success text pending
|
|
548
|
+
navigation remain distinct. Success text alone does not count as an article.
|
|
549
|
+
An offscreen/hidden preload is not classified as a visible interactive task.
|
|
550
|
+
|
|
551
|
+
Run `tests/integration/wechat_state_machine_regression.py --repeat 3 --output
|
|
552
|
+
<report.json>` with a compatible Worker for deterministic real-browser fixtures.
|
|
553
|
+
For live visual inspection use `tests/integration/wechat_render_diagnostic.py
|
|
554
|
+
--url <article-url> --runtime-dir <diagnostic-runtime> --output <directory>`.
|
|
555
|
+
The latter requires the optional native render-snapshot experiment; it saves
|
|
556
|
+
PNGs before closing the Page, without answering an interactive challenge.
|
|
492
557
|
|
|
493
558
|
For a private GitHub Release, set `GITHUB_TOKEN`, `GH_TOKEN`, or
|
|
494
559
|
`WPR_GITHUB_TOKEN`, or configure Git Credential Manager for the GitHub account.
|
|
@@ -509,3 +574,20 @@ The selected Firefox bundle launches `gecko-net-worker.exe`. Its response body
|
|
|
509
574
|
uses shared memory and is released when `atext()`, `aread()`, or `aclose()`
|
|
510
575
|
completes. Set `WPR_RUNTIME_HOME`, `WPR_RUNTIME_DIR`, and
|
|
511
576
|
`WPR_NETWORK_WORKER_EXE` to select a different Firefox-version adapter.
|
|
577
|
+
|
|
578
|
+
# Standalone HTTP client development
|
|
579
|
+
|
|
580
|
+
The HTTP implementation now lives in `http-client/wpr_http`, with common
|
|
581
|
+
infrastructure in `runtime-core/wpr_runtime_core`. The browser product stays in
|
|
582
|
+
`gecko_web_runtime`, including compatibility aliases for its existing HTTP API.
|
|
583
|
+
The new packages are development builds and have not yet been published to PyPI.
|
|
584
|
+
|
|
585
|
+
From this directory, install the three local projects together:
|
|
586
|
+
|
|
587
|
+
```powershell
|
|
588
|
+
uv pip install -e runtime-core -e http-client -e .
|
|
589
|
+
```
|
|
590
|
+
|
|
591
|
+
For HTTP-only development, omit `-e .`. See
|
|
592
|
+
[`../docs/http-client-extraction.md`](../docs/http-client-extraction.md) for
|
|
593
|
+
independent wheel installation, real engine version selection and publishing.
|
{gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/__init__.py
RENAMED
|
@@ -1,71 +1,71 @@
|
|
|
1
|
-
"""Portable Python client for the Firefox-derived WPR runtime bundle."""
|
|
2
|
-
|
|
3
|
-
from .api.context import BrowserContext
|
|
4
|
-
from .api.page import Page
|
|
5
|
-
from .api.pool import AsyncGeckoWorkerPool
|
|
6
|
-
from .api.runtime import AsyncGeckoRuntime, WorkerRecyclePolicy
|
|
7
|
-
from .data_plane import SharedBlob, SharedBlobDescriptor
|
|
8
|
-
from .diagnostics.metrics import MetricsOptions, WorkflowMetrics
|
|
9
|
-
from .http import (
|
|
10
|
-
AsyncWprHttpClient,
|
|
11
|
-
Headers,
|
|
12
|
-
HttpRequest,
|
|
13
|
-
HttpResponse,
|
|
14
|
-
NetworkTiming,
|
|
15
|
-
Request,
|
|
16
|
-
Timeout,
|
|
17
|
-
WprConnectError,
|
|
18
|
-
WprHttpClient,
|
|
19
|
-
WprHttpError,
|
|
20
|
-
WprHTTPStatusError,
|
|
21
|
-
WprPoolTimeoutError,
|
|
22
|
-
WprProxyError,
|
|
23
|
-
WprTimeoutError,
|
|
24
|
-
WprTransportError,
|
|
25
|
-
)
|
|
26
|
-
from .installer import install_runtime
|
|
27
|
-
from .models.navigation import TurnstileResult, WechatArticleResult
|
|
28
|
-
from .session import (
|
|
29
|
-
AsyncGeckoWorkerSession,
|
|
30
|
-
GeckoWorkerSession,
|
|
31
|
-
RuntimeConfig,
|
|
32
|
-
WprProtocolError,
|
|
33
|
-
)
|
|
34
|
-
from .workflows.turnstile import TurnstileWorkflow
|
|
35
|
-
from .workflows.wechat import WechatArticleWorkflow
|
|
36
|
-
|
|
37
|
-
__all__ = [
|
|
38
|
-
"AsyncGeckoRuntime",
|
|
39
|
-
"AsyncGeckoWorkerPool",
|
|
40
|
-
"AsyncGeckoWorkerSession",
|
|
41
|
-
"AsyncWprHttpClient",
|
|
42
|
-
"BrowserContext",
|
|
43
|
-
"GeckoWorkerSession",
|
|
44
|
-
"Headers",
|
|
45
|
-
"HttpRequest",
|
|
46
|
-
"HttpResponse",
|
|
47
|
-
"MetricsOptions",
|
|
48
|
-
"NetworkTiming",
|
|
49
|
-
"Page",
|
|
50
|
-
"Request",
|
|
51
|
-
"RuntimeConfig",
|
|
52
|
-
"SharedBlob",
|
|
53
|
-
"SharedBlobDescriptor",
|
|
54
|
-
"Timeout",
|
|
55
|
-
"TurnstileResult",
|
|
56
|
-
"TurnstileWorkflow",
|
|
57
|
-
"WechatArticleResult",
|
|
58
|
-
"WechatArticleWorkflow",
|
|
59
|
-
"WorkerRecyclePolicy",
|
|
60
|
-
"WorkflowMetrics",
|
|
61
|
-
"WprConnectError",
|
|
62
|
-
"WprHTTPStatusError",
|
|
63
|
-
"WprHttpClient",
|
|
64
|
-
"WprHttpError",
|
|
65
|
-
"WprPoolTimeoutError",
|
|
66
|
-
"WprProtocolError",
|
|
67
|
-
"WprProxyError",
|
|
68
|
-
"WprTimeoutError",
|
|
69
|
-
"WprTransportError",
|
|
70
|
-
"install_runtime",
|
|
71
|
-
]
|
|
1
|
+
"""Portable Python client for the Firefox-derived WPR runtime bundle."""
|
|
2
|
+
|
|
3
|
+
from .api.context import BrowserContext
|
|
4
|
+
from .api.page import Page
|
|
5
|
+
from .api.pool import AsyncGeckoWorkerPool
|
|
6
|
+
from .api.runtime import AsyncGeckoRuntime, WorkerRecyclePolicy
|
|
7
|
+
from .data_plane import SharedBlob, SharedBlobDescriptor
|
|
8
|
+
from .diagnostics.metrics import MetricsOptions, WorkflowMetrics
|
|
9
|
+
from .http import (
|
|
10
|
+
AsyncWprHttpClient,
|
|
11
|
+
Headers,
|
|
12
|
+
HttpRequest,
|
|
13
|
+
HttpResponse,
|
|
14
|
+
NetworkTiming,
|
|
15
|
+
Request,
|
|
16
|
+
Timeout,
|
|
17
|
+
WprConnectError,
|
|
18
|
+
WprHttpClient,
|
|
19
|
+
WprHttpError,
|
|
20
|
+
WprHTTPStatusError,
|
|
21
|
+
WprPoolTimeoutError,
|
|
22
|
+
WprProxyError,
|
|
23
|
+
WprTimeoutError,
|
|
24
|
+
WprTransportError,
|
|
25
|
+
)
|
|
26
|
+
from .installer import install_runtime
|
|
27
|
+
from .models.navigation import TurnstileResult, WechatArticleResult
|
|
28
|
+
from .session import (
|
|
29
|
+
AsyncGeckoWorkerSession,
|
|
30
|
+
GeckoWorkerSession,
|
|
31
|
+
RuntimeConfig,
|
|
32
|
+
WprProtocolError,
|
|
33
|
+
)
|
|
34
|
+
from .workflows.turnstile import TurnstileWorkflow
|
|
35
|
+
from .workflows.wechat import WechatArticleWorkflow
|
|
36
|
+
|
|
37
|
+
__all__ = [
|
|
38
|
+
"AsyncGeckoRuntime",
|
|
39
|
+
"AsyncGeckoWorkerPool",
|
|
40
|
+
"AsyncGeckoWorkerSession",
|
|
41
|
+
"AsyncWprHttpClient",
|
|
42
|
+
"BrowserContext",
|
|
43
|
+
"GeckoWorkerSession",
|
|
44
|
+
"Headers",
|
|
45
|
+
"HttpRequest",
|
|
46
|
+
"HttpResponse",
|
|
47
|
+
"MetricsOptions",
|
|
48
|
+
"NetworkTiming",
|
|
49
|
+
"Page",
|
|
50
|
+
"Request",
|
|
51
|
+
"RuntimeConfig",
|
|
52
|
+
"SharedBlob",
|
|
53
|
+
"SharedBlobDescriptor",
|
|
54
|
+
"Timeout",
|
|
55
|
+
"TurnstileResult",
|
|
56
|
+
"TurnstileWorkflow",
|
|
57
|
+
"WechatArticleResult",
|
|
58
|
+
"WechatArticleWorkflow",
|
|
59
|
+
"WorkerRecyclePolicy",
|
|
60
|
+
"WorkflowMetrics",
|
|
61
|
+
"WprConnectError",
|
|
62
|
+
"WprHTTPStatusError",
|
|
63
|
+
"WprHttpClient",
|
|
64
|
+
"WprHttpError",
|
|
65
|
+
"WprPoolTimeoutError",
|
|
66
|
+
"WprProtocolError",
|
|
67
|
+
"WprProxyError",
|
|
68
|
+
"WprTimeoutError",
|
|
69
|
+
"WprTransportError",
|
|
70
|
+
"install_runtime",
|
|
71
|
+
]
|
{gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/__main__.py
RENAMED
|
@@ -1,23 +1,23 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import argparse
|
|
4
|
-
|
|
5
|
-
from .installer import install_runtime
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
def main() -> int:
|
|
9
|
-
parser = argparse.ArgumentParser(prog="python -m gecko_web_runtime")
|
|
10
|
-
commands = parser.add_subparsers(dest="command", required=True)
|
|
11
|
-
install = commands.add_parser("install-runtime", help="download a pinned Gecko runtime")
|
|
12
|
-
install.add_argument("--version", required=True, help="runtime major version, e.g. 155")
|
|
13
|
-
install.add_argument("--runtime-home", help="optional installation directory")
|
|
14
|
-
install.add_argument("--force", action="store_true", help="reinstall the current version at the same path")
|
|
15
|
-
args = parser.parse_args()
|
|
16
|
-
if args.command == "install-runtime":
|
|
17
|
-
location = install_runtime(args.version, args.runtime_home, force=args.force)
|
|
18
|
-
print(location)
|
|
19
|
-
return 0
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
if __name__ == "__main__":
|
|
23
|
-
raise SystemExit(main())
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import argparse
|
|
4
|
+
|
|
5
|
+
from .installer import install_runtime
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def main() -> int:
|
|
9
|
+
parser = argparse.ArgumentParser(prog="python -m gecko_web_runtime")
|
|
10
|
+
commands = parser.add_subparsers(dest="command", required=True)
|
|
11
|
+
install = commands.add_parser("install-runtime", help="download a pinned Gecko runtime")
|
|
12
|
+
install.add_argument("--version", required=True, help="runtime major version, e.g. 155")
|
|
13
|
+
install.add_argument("--runtime-home", help="optional installation directory")
|
|
14
|
+
install.add_argument("--force", action="store_true", help="reinstall the current version at the same path")
|
|
15
|
+
args = parser.parse_args()
|
|
16
|
+
if args.command == "install-runtime":
|
|
17
|
+
location = install_runtime(args.version, args.runtime_home, force=args.force)
|
|
18
|
+
print(location)
|
|
19
|
+
return 0
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
if __name__ == "__main__":
|
|
23
|
+
raise SystemExit(main())
|
{gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/__init__.py
RENAMED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
"""High-level application-facing runtime API."""
|
|
2
|
-
|
|
3
|
-
from .context import BrowserContext
|
|
4
|
-
from .page import Page
|
|
5
|
-
from .runtime import AsyncGeckoRuntime, WorkerRecyclePolicy
|
|
6
|
-
|
|
7
|
-
__all__ = ["AsyncGeckoRuntime", "BrowserContext", "Page", "WorkerRecyclePolicy"]
|
|
1
|
+
"""High-level application-facing runtime API."""
|
|
2
|
+
|
|
3
|
+
from .context import BrowserContext
|
|
4
|
+
from .page import Page
|
|
5
|
+
from .runtime import AsyncGeckoRuntime, WorkerRecyclePolicy
|
|
6
|
+
|
|
7
|
+
__all__ = ["AsyncGeckoRuntime", "BrowserContext", "Page", "WorkerRecyclePolicy"]
|
{gecko_web_runtime_client-1.3.0 → gecko_web_runtime_client-1.4.0}/gecko_web_runtime/api/context.py
RENAMED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
"""BrowserContext facade for storage/session boundaries."""
|
|
2
|
-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
from pathlib import Path
|
|
6
|
-
from typing import TYPE_CHECKING
|
|
7
|
-
|
|
8
|
-
from ..session import AsyncGeckoWorkerSession, RuntimeConfig
|
|
9
|
-
from .page import Page
|
|
10
|
-
|
|
11
|
-
if TYPE_CHECKING:
|
|
12
|
-
from .runtime import AsyncGeckoRuntime
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class BrowserContext:
|
|
16
|
-
"""Own a logical Cookie/Storage session and its page.
|
|
17
|
-
|
|
18
|
-
``persistent`` reuses the runtime's Worker/profile. Each page gets a
|
|
19
|
-
native page id, and ``user_context_id``/``private_browsing_id`` are passed
|
|
20
|
-
to Gecko before its first navigation. ``isolated`` remains the explicit
|
|
21
|
-
separate-Worker fallback for callers that require process/profile
|
|
22
|
-
isolation rather than same-Worker OriginAttributes isolation.
|
|
23
|
-
"""
|
|
24
|
-
|
|
25
|
-
def __init__(
|
|
26
|
-
self,
|
|
27
|
-
runtime: "AsyncGeckoRuntime",
|
|
28
|
-
*,
|
|
29
|
-
isolation: str = "persistent",
|
|
30
|
-
config: RuntimeConfig | None = None,
|
|
31
|
-
fpfile: str | Path | None = None,
|
|
32
|
-
user_context_id: int = 0,
|
|
33
|
-
private_browsing_id: int = 0,
|
|
34
|
-
) -> None:
|
|
35
|
-
if isolation not in {"persistent", "isolated"}:
|
|
36
|
-
raise ValueError("isolation must be 'persistent' or 'isolated'")
|
|
37
|
-
self.runtime = runtime
|
|
38
|
-
self.isolation = isolation
|
|
39
|
-
self.config = config or runtime.config
|
|
40
|
-
self.fpfile = fpfile if fpfile is not None else runtime.fpfile
|
|
41
|
-
self.user_context_id = int(user_context_id)
|
|
42
|
-
self.private_browsing_id = int(private_browsing_id)
|
|
43
|
-
self._session: AsyncGeckoWorkerSession | None = None
|
|
44
|
-
self._owns_session = isolation == "isolated"
|
|
45
|
-
self._entered = False
|
|
46
|
-
self._pages: set[Page] = set()
|
|
47
|
-
|
|
48
|
-
@property
|
|
49
|
-
def session(self) -> AsyncGeckoWorkerSession:
|
|
50
|
-
if self._session is None:
|
|
51
|
-
raise RuntimeError("BrowserContext is not open")
|
|
52
|
-
return self._session
|
|
53
|
-
|
|
54
|
-
async def __aenter__(self) -> "BrowserContext":
|
|
55
|
-
if self._entered:
|
|
56
|
-
return self
|
|
57
|
-
if self.isolation == "persistent":
|
|
58
|
-
if self.runtime._session is None:
|
|
59
|
-
raise RuntimeError("AsyncGeckoRuntime is not open")
|
|
60
|
-
self._session = self.runtime._session
|
|
61
|
-
else:
|
|
62
|
-
self._session = AsyncGeckoWorkerSession(
|
|
63
|
-
self.config, self.fpfile, self.runtime.proxy
|
|
64
|
-
)
|
|
65
|
-
await self._session.__aenter__()
|
|
66
|
-
self._entered = True
|
|
67
|
-
return self
|
|
68
|
-
|
|
69
|
-
async def new_page(self) -> Page:
|
|
70
|
-
if not self._entered:
|
|
71
|
-
raise RuntimeError("BrowserContext is not open")
|
|
72
|
-
page = Page(
|
|
73
|
-
self.session,
|
|
74
|
-
user_context_id=self.user_context_id,
|
|
75
|
-
private_browsing_id=self.private_browsing_id,
|
|
76
|
-
owner=self,
|
|
77
|
-
)
|
|
78
|
-
try:
|
|
79
|
-
await page._ensure_created()
|
|
80
|
-
except Exception:
|
|
81
|
-
await page.close()
|
|
82
|
-
raise
|
|
83
|
-
self._pages.add(page)
|
|
84
|
-
return page
|
|
85
|
-
|
|
86
|
-
def _forget_page(self, page: Page) -> None:
|
|
87
|
-
self._pages.discard(page)
|
|
88
|
-
|
|
89
|
-
async def close(self) -> None:
|
|
90
|
-
if not self._entered:
|
|
91
|
-
return
|
|
92
|
-
pages = list(self._pages)
|
|
93
|
-
self._pages.clear()
|
|
94
|
-
first_error: Exception | None = None
|
|
95
|
-
for page in pages:
|
|
96
|
-
try:
|
|
97
|
-
await page.close()
|
|
98
|
-
except Exception as exc: # noqa: BLE001 - close remaining pages first
|
|
99
|
-
first_error = first_error or exc
|
|
100
|
-
if self._owns_session and self._session is not None:
|
|
101
|
-
await self._session.__aexit__(None, None, None)
|
|
102
|
-
self._session = None
|
|
103
|
-
self._entered = False
|
|
104
|
-
if self.isolation == "persistent" and not self.runtime._closing:
|
|
105
|
-
self.runtime.note_job_complete()
|
|
106
|
-
if first_error is not None:
|
|
107
|
-
raise first_error
|
|
108
|
-
|
|
109
|
-
async def __aexit__(self, exc_type, exc, tb) -> None:
|
|
110
|
-
await self.close()
|
|
1
|
+
"""BrowserContext facade for storage/session boundaries."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import TYPE_CHECKING
|
|
7
|
+
|
|
8
|
+
from ..session import AsyncGeckoWorkerSession, RuntimeConfig
|
|
9
|
+
from .page import Page
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
from .runtime import AsyncGeckoRuntime
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class BrowserContext:
|
|
16
|
+
"""Own a logical Cookie/Storage session and its page.
|
|
17
|
+
|
|
18
|
+
``persistent`` reuses the runtime's Worker/profile. Each page gets a
|
|
19
|
+
native page id, and ``user_context_id``/``private_browsing_id`` are passed
|
|
20
|
+
to Gecko before its first navigation. ``isolated`` remains the explicit
|
|
21
|
+
separate-Worker fallback for callers that require process/profile
|
|
22
|
+
isolation rather than same-Worker OriginAttributes isolation.
|
|
23
|
+
"""
|
|
24
|
+
|
|
25
|
+
def __init__(
|
|
26
|
+
self,
|
|
27
|
+
runtime: "AsyncGeckoRuntime",
|
|
28
|
+
*,
|
|
29
|
+
isolation: str = "persistent",
|
|
30
|
+
config: RuntimeConfig | None = None,
|
|
31
|
+
fpfile: str | Path | None = None,
|
|
32
|
+
user_context_id: int = 0,
|
|
33
|
+
private_browsing_id: int = 0,
|
|
34
|
+
) -> None:
|
|
35
|
+
if isolation not in {"persistent", "isolated"}:
|
|
36
|
+
raise ValueError("isolation must be 'persistent' or 'isolated'")
|
|
37
|
+
self.runtime = runtime
|
|
38
|
+
self.isolation = isolation
|
|
39
|
+
self.config = config or runtime.config
|
|
40
|
+
self.fpfile = fpfile if fpfile is not None else runtime.fpfile
|
|
41
|
+
self.user_context_id = int(user_context_id)
|
|
42
|
+
self.private_browsing_id = int(private_browsing_id)
|
|
43
|
+
self._session: AsyncGeckoWorkerSession | None = None
|
|
44
|
+
self._owns_session = isolation == "isolated"
|
|
45
|
+
self._entered = False
|
|
46
|
+
self._pages: set[Page] = set()
|
|
47
|
+
|
|
48
|
+
@property
|
|
49
|
+
def session(self) -> AsyncGeckoWorkerSession:
|
|
50
|
+
if self._session is None:
|
|
51
|
+
raise RuntimeError("BrowserContext is not open")
|
|
52
|
+
return self._session
|
|
53
|
+
|
|
54
|
+
async def __aenter__(self) -> "BrowserContext":
|
|
55
|
+
if self._entered:
|
|
56
|
+
return self
|
|
57
|
+
if self.isolation == "persistent":
|
|
58
|
+
if self.runtime._session is None:
|
|
59
|
+
raise RuntimeError("AsyncGeckoRuntime is not open")
|
|
60
|
+
self._session = self.runtime._session
|
|
61
|
+
else:
|
|
62
|
+
self._session = AsyncGeckoWorkerSession(
|
|
63
|
+
self.config, self.fpfile, self.runtime.proxy
|
|
64
|
+
)
|
|
65
|
+
await self._session.__aenter__()
|
|
66
|
+
self._entered = True
|
|
67
|
+
return self
|
|
68
|
+
|
|
69
|
+
async def new_page(self) -> Page:
|
|
70
|
+
if not self._entered:
|
|
71
|
+
raise RuntimeError("BrowserContext is not open")
|
|
72
|
+
page = Page(
|
|
73
|
+
self.session,
|
|
74
|
+
user_context_id=self.user_context_id,
|
|
75
|
+
private_browsing_id=self.private_browsing_id,
|
|
76
|
+
owner=self,
|
|
77
|
+
)
|
|
78
|
+
try:
|
|
79
|
+
await page._ensure_created()
|
|
80
|
+
except Exception:
|
|
81
|
+
await page.close()
|
|
82
|
+
raise
|
|
83
|
+
self._pages.add(page)
|
|
84
|
+
return page
|
|
85
|
+
|
|
86
|
+
def _forget_page(self, page: Page) -> None:
|
|
87
|
+
self._pages.discard(page)
|
|
88
|
+
|
|
89
|
+
async def close(self) -> None:
|
|
90
|
+
if not self._entered:
|
|
91
|
+
return
|
|
92
|
+
pages = list(self._pages)
|
|
93
|
+
self._pages.clear()
|
|
94
|
+
first_error: Exception | None = None
|
|
95
|
+
for page in pages:
|
|
96
|
+
try:
|
|
97
|
+
await page.close()
|
|
98
|
+
except Exception as exc: # noqa: BLE001 - close remaining pages first
|
|
99
|
+
first_error = first_error or exc
|
|
100
|
+
if self._owns_session and self._session is not None:
|
|
101
|
+
await self._session.__aexit__(None, None, None)
|
|
102
|
+
self._session = None
|
|
103
|
+
self._entered = False
|
|
104
|
+
if self.isolation == "persistent" and not self.runtime._closing:
|
|
105
|
+
self.runtime.note_job_complete()
|
|
106
|
+
if first_error is not None:
|
|
107
|
+
raise first_error
|
|
108
|
+
|
|
109
|
+
async def __aexit__(self, exc_type, exc, tb) -> None:
|
|
110
|
+
await self.close()
|