Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c06b79cc99 | ||
|
|
4af52c8056 | ||
|
|
c3748be495 |
No files matched your search
@@ -0,0 +1,28 @@
|
||||
# invisible_playwright
|
||||
|
||||
This repository is the Playwright-compatible wrapper of the engine: the Playwright API (a vendored client in
|
||||
`src/invisible_playwright/_pw/`) served in process by our own server (`src/invisible_playwright/_juggler/`), which
|
||||
drives the engine over Juggler through [invisible_core](https://github.com/oss-invisible/core). The engine itself is
|
||||
the patch series in [firefox_antidetect_patch](https://github.com/oss-invisible/firefox_antidetect_patch).
|
||||
|
||||
`docs/` is the source of the published wiki. The rules of the code are in `docs/decisions/`, one file per rule, each
|
||||
naming the test that fails when the code breaks it; the list is `docs/decisions/README.md`.
|
||||
|
||||
## Commands
|
||||
|
||||
```
|
||||
python -m pytest -q # the default suite: no browser (excludes `slow` and `e2e`)
|
||||
python scripts/run_e2e.py <firefox-binary> # the browser suite (or set INVPW_BINARY_PATH)
|
||||
invisible-playwright fetch # check the engine the core's seal names, download it if needed, print where it is
|
||||
invisible-playwright version # the wrapper, core and engine versions
|
||||
git config core.hooksPath .githooks # the pre-push hook (policy in invisible_core)
|
||||
```
|
||||
|
||||
## Every change
|
||||
|
||||
1. A branch, the change and its test. A defect is closed by a test that fails on the old code and passes on the fix.
|
||||
2. `python -m pytest -q`, then a pull request: the `gate` job of `.github/workflows/tests.yml` decides, and the browser
|
||||
suites run in `.github/workflows/e2e.yml`. The suites a candidate engine must pass are listed in
|
||||
`ci/required-suites.json`.
|
||||
3. A behaviour that belongs to the core (the fingerprint, the prefs, the launch, the protocol client) changes in
|
||||
invisible_core, not here.
|
||||
+1
-1
@@ -6,7 +6,7 @@ Thanks for your interest in improving this project. Contributions are welcome vi
|
||||
|
||||
- **Bug or idea?** Open an [issue](https://github.com/oss-invisible/playwright/issues/new/choose).
|
||||
- **Security issue?** Do **not** open a public issue - see [SECURITY.md](SECURITY.md).
|
||||
- **The C++ patches** live in the companion repo [oss-invisible/firefox_antidetect_patch](https://github.com/oss-invisible/firefox_antidetect_patch) (branch `stealth/151`). Bugs in fingerprint spoofing usually belong there.
|
||||
- **The C++ patches** live in the companion repo [oss-invisible/firefox_antidetect_patch](https://github.com/oss-invisible/firefox_antidetect_patch), on `main`: where each kind of change goes is in its [docs/STRUCTURE.md](https://github.com/oss-invisible/firefox_antidetect_patch/blob/main/docs/STRUCTURE.md). Bugs in fingerprint spoofing usually belong there.
|
||||
|
||||
## Scope
|
||||
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
# Decisions
|
||||
|
||||
The rules of the code of this repository, one file per rule. Each says the rule, the test that fails when the code
|
||||
breaks it, why, the files, and what not to do. Read this list first; open a decision only when your change touches it.
|
||||
|
||||
The rules of the core are in [invisible_core](https://github.com/oss-invisible/core) (`docs/decisions/`), and those of
|
||||
the engine in [firefox_antidetect_patch](https://github.com/oss-invisible/firefox_antidetect_patch) (`docs/decisions/`).
|
||||
|
||||
| Id | Rule |
|
||||
|---|---|
|
||||
| [wrapper-01](wrapper-01-playwright-surface-and-named-refusals.md) | The surface is Playwright's, and what is outside it is refused by name. |
|
||||
| [wrapper-02](wrapper-02-vendored-playwright-client.md) | The Playwright client is vendored, pinned to the seal, and Firefox only. |
|
||||
| [wrapper-03](wrapper-03-every-engine-goes-through-the-seal.md) | Every engine goes through the seal check, before and after the launch. |
|
||||
| [wrapper-04](wrapper-04-one-in-process-transport.md) | One transport, the Juggler server runs inside the Python process. |
|
||||
| [wrapper-05](wrapper-05-live-objects-and-one-event-registry.md) | The server keeps only live objects, and one registry holds the event subscribers. |
|
||||
| [wrapper-06](wrapper-06-one-server-operation-per-api-name.md) | One server operation per API name, and action options read in one place. |
|
||||
| [wrapper-07](wrapper-07-identity-before-the-first-launch.md) | The identity is applied before the first launch and at the creation of each context. |
|
||||
| [wrapper-08](wrapper-08-caller-proxy-routed-or-refused.md) | The proxy of the caller is the road of the page, or the launch is refused. |
|
||||
| [wrapper-09](wrapper-09-route-stays-in-the-perimeter.md) | Route stays inside the perimeter, with explicit refusals and ordinary headers. |
|
||||
| [wrapper-10](wrapper-10-cursor-path-drawn-in-python.md) | The path of the cursor is drawn in Python, by the server of the wrapper. |
|
||||
| [wrapper-11](wrapper-11-variability-and-rhythm-from-the-seed.md) | The variability and the rhythm of the hand come from the seed of the session. |
|
||||
| [wrapper-12](wrapper-12-pointer-visible-in-the-window-only.md) | The pointer is visible in the window, never in the page. |
|
||||
| [wrapper-13](wrapper-13-true-headless-only-on-request-and-live-screencast.md) | True headless only on request, and the screencast is live. |
|
||||
| [wrapper-14](wrapper-14-no-timed-wait-the-tab-waits-for-the-event.md) | No timed wait, the tab waits for the event. |
|
||||
| [wrapper-15](wrapper-15-cli-with-two-commands.md) | The CLI has two commands, and no cache management. |
|
||||
| [wrapper-16](wrapper-16-narrow-public-surface-core-is-the-one-implementation.md) | A narrow public surface, and the core is the one implementation. |
|
||||
@@ -0,0 +1,20 @@
|
||||
# wrapper-01: the surface is Playwright's, and what is outside it is refused by name
|
||||
|
||||
**Rule.** The public API is the Playwright API. What the wrapper does not implement is refused by name, never degraded in silence.
|
||||
- The wrapper adds no method and no parameter to the Playwright API.
|
||||
- An operation outside the perimeter is refused with a sentence that names the feature it belongs to. The names are the table `OUTSIDE` in `perimeter.py`.
|
||||
- Objects that the protocol requires and the wrapper does not implement (tracing, the debugger, the request context) are created as `RefusingDispatcher` objects. Every call on them refuses with a reason.
|
||||
- A refusal that is not a whole feature is declared too: `NO_ENGINE_COMMAND`, `FIXED_AT_BUILD`, `NOT_WIRED_YET` and `WITHDRAWN` in `perimeter.py` for whole operations, and `REFUSED_PARAMETERS` for one parameter of a served operation. A refusal that no table names is an error.
|
||||
- The test for leaving an API out is the path of its commands. What the client sends on its own cannot be left out by name. `COURTESY` answers only those few calls, with the minimum, and each entry names the client call that sends it.
|
||||
|
||||
**Enforced by.** `tests/test_juggler_transport.py::test_an_out_of_perimeter_call_NAMES_THE_FEATURE` and `::test_an_out_of_perimeter_object_refuses_with_a_REASON` fail when a refusal stops naming the feature or the reason. `::test_a_GAP_and_a_DECISION_do_not_read_the_same` fails when a missing in-perimeter method reads like a decision. `::test_the_perimeter_and_the_courtesy_list_do_not_OVERLAP_by_accident` and `::test_every_courtesy_entry_says_WHO_calls_it` fail when `COURTESY` answers an operation that is inside the perimeter, or an entry does not name its caller. `tests/test_every_refusal_is_declared.py::test_every_inline_refusal_is_declared_in_the_perimeter`, `::test_every_declared_refusal_is_still_refused`, `::test_every_parameter_refusal_is_declared_in_the_perimeter` and `::test_every_declared_parameter_refusal_is_still_raised` fail when a refusal is written in the server and not declared, or declared and not raised. `tests/test_every_wire_method_is_served_or_refused.py::test_the_wire_method_budget_matches_the_code` and `::test_every_send_of_the_client_has_a_channel` fail when a method the client sends is neither served nor refused.
|
||||
|
||||
**Why.** Code written for Playwright changes only its import. A silent degradation (valid files with empty bodies) raises no error, and a caller cannot tell it from a working feature. A refusal that names the feature tells the caller where the limit is.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/perimeter.py`, `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_juggler/remote.py`.
|
||||
|
||||
**Don't.**
|
||||
- Add a method or a parameter to the wrapper.
|
||||
- Return a no-op, an empty result or an `AttributeError` for an operation that is left out.
|
||||
- Leave out by name an API whose commands the client sends on its own.
|
||||
- Add an entry to `COURTESY` without the name of the client call that sends it.
|
||||
@@ -0,0 +1,22 @@
|
||||
# wrapper-02: the Playwright client is vendored, pinned to the seal, and Firefox only
|
||||
|
||||
**Rule.** One Playwright client talks to the engine. It lives inside the package, it is checked against the seal, and it drives Firefox only.
|
||||
- The Python client sits in `src/invisible_playwright/_pw/`, tracked in git, with its Apache-2.0 `LICENSE`. Playwright is not a dependency of the package. Internal code imports `invisible_playwright._pw`, never `playwright`.
|
||||
- Every change made to the client carries the marker `MODIFIED by invisible_playwright`.
|
||||
- The client reads the browser payload with the key `initializer["firefox"]`. The schema changes only after the protocol is captured again with `scripts/capture_protocol.py`.
|
||||
- The range of clients the engine was tested with travels in the seal, as `playwright.min` and `playwright.max`, from `stealth_playwright_range.txt` in the series repo. `assert_playwright_range()` compares the version of the vendored client with that range. It never reads an installed Playwright. Outside the range it raises, unless `INVISIBLE_PLAYWRIGHT_SKEW=allow` is set, which only warns. The pinned client version is in `scripts/playwright_pin.txt`.
|
||||
- `__init__.py` runs the core pin check, then the range check, before any other import of the package. `_pin.py` records which core modules were already imported before it loads the core. The message of the import filter carries the remedy (a forced reinstall) and no version number: the version is resolved from the requirement the package declares.
|
||||
- The package drives Firefox only. Asking `playwright[...]` for any browser type other than Firefox raises `ValueError`, and the attributes of the other browser types raise `NotImplementedError`, in the sync and in the async client. The vendored client has no module for another browser engine and no object for another platform. The remote server answers every other browser type with a refusal that gives the reason.
|
||||
|
||||
**Enforced by.** `tests/test_fork.py::test_no_one_imports_the_installed_playwright` and `::test_the_vendored_client_is_the_one_imported` fail when code imports `playwright`, or the imported client is not the one inside the package. `::test_the_apache_licence_the_fork_still_owes_is_shipped` fails when the licence is not shipped. `tests/test_seal_playwright_range.py::test_client_above_the_range_is_refused`, `::test_client_below_the_range_is_refused` and `::test_skew_can_be_allowed_explicitly_and_still_warns` fail when the range check stops refusing outside the range or the skew switch stops warning. `::test_the_installed_client_satisfies_the_packaged_seal` fails when the vendored client is outside the range of the packaged seal. `tests/test_core_pin.py::test_the_prelude_is_the_first_thing_the_package_does` fails when another import runs before the pin check. `::test_that_refusal_carries_no_version_literal_and_no_git_install` and `::test_no_source_file_hardcodes_a_core_version_requirement` fail when a version number is written into a message or a source file. `tests/test_the_remote_server_serves_the_protocol.py` fails when the other browser types stop refusing with a reason.
|
||||
|
||||
**Why.** The engine speaks one captured version of the Juggler protocol, and that schema is closed: a client outside the tested range can fail at context creation or lose a feature without a clear error. A vendored client stays in step with the engine, and a Playwright installed next to it cannot enter by mistake. A fork that can be replaced by the stock package without any error is a dead folder.
|
||||
|
||||
**Files.** `src/invisible_playwright/_pw/`, `src/invisible_playwright/THIRD_PARTY_FORK.md`, `src/invisible_playwright/_pw/_impl/_playwright.py`, `src/invisible_playwright/_pw/_repo_version.py`, `src/invisible_playwright/__init__.py`, `src/invisible_playwright/_pin.py`, `src/invisible_playwright/_engine.py`, `scripts/capture_protocol.py`, `scripts/playwright_pin.txt`, `pyproject.toml`, `firefox_antidetect_patch: platform/release/src/browser/config/stealth_playwright_range.txt`.
|
||||
|
||||
**Don't.**
|
||||
- Use the stock `playwright` package in place of `_pw/`, or take `_pw/` out of git.
|
||||
- Widen the range of the client beyond what the tests exercise.
|
||||
- Write a version number in the message of the import filter, or put an import before the two checks in `__init__.py`.
|
||||
- Add another browser engine or another platform.
|
||||
- Rename the `firefox` key of the initializer without capturing the protocol again.
|
||||
@@ -0,0 +1,21 @@
|
||||
# wrapper-03: every engine goes through the seal check, before and after the launch
|
||||
|
||||
**Rule.** No binary starts without being checked against the seal, and a running engine is checked again from outside the process.
|
||||
- Every launch of the wrapper resolves its engine with `_engine.resolve_executable()`. It is called by `launcher.py` (sync), `async_api.py` (async), `CommonLaunch` in `_session.py` and `_juggler/remote.py`. `invisible-playwright fetch` launches nothing: it calls `ensure_binary`, which verifies what it downloads.
|
||||
- Without `binary_path=` it calls `ensure_binary(seal=)`. With `binary_path=` it skips the download but still calls `verify_engine`. The caller then needs an `INVISIBLE_SEAL_FILE` made for that binary; without it the wrapper refuses.
|
||||
- After the launch `assert_wire_version(browser)` compares the version the engine reports over the protocol with the seal. It reads `browser.version`, cached from the initializer, so it costs no round trip. A different version raises `EngineMismatch` and names `python -m invisible_playwright fetch`. A missing or empty version is no evidence and is never read as a match.
|
||||
- The check runs on the `launch()` path and in the remote server. It does not run on the persistent context, which has no `Browser`.
|
||||
- The wrapper downloads the engine at the first launch. `invisible-playwright fetch` does the download in advance, for Docker images and CI caches.
|
||||
- Launching `invisible_core` directly with `binary_path=` does not verify. Whoever does that calls `verify_engine`.
|
||||
|
||||
**Enforced by.** `tests/test_seal_binary_path.py::test_unpatched_engine_via_binary_path_is_refused`, `::test_old_engine_via_binary_path_is_refused` and `::test_foreign_build_of_the_same_version_via_binary_path_is_refused` fail when a binary the seal does not describe is accepted through `binary_path=`. `::test_refusal_names_the_remedy` fails when the refusal stops naming the seal file. `::test_no_binary_path_goes_through_ensure_binary` fails when the path-less call stops passing the resolved seal to `ensure_binary`. `tests/test_a_bundled_stock_firefox_is_refused_by_binary_path.py::test_real_stock_firefox_via_binary_path_is_refused` fails when a stock Firefox passes the check. `tests/test_seal_wire_version.py::test_an_engine_reporting_another_version_is_refused_after_launch` fails when a running engine of another version is accepted. `::test_an_empty_version_is_not_treated_as_a_match` and `::test_no_browser_is_not_an_error` fail when an empty version counts as agreement or a missing `Browser` raises.
|
||||
|
||||
**Why.** A path straight to a binary must not skip version, build id and provenance. A binary that is not verified can claim an identity different from the real one. The version the running engine reports comes from the engine itself, so no pref can forge it, and it is the only check made from outside the process. One place that resolves the executable makes sync and async choose the same binary.
|
||||
|
||||
**Files.** `src/invisible_playwright/_engine.py`, `src/invisible_playwright/launcher.py`, `src/invisible_playwright/async_api.py`, `src/invisible_playwright/_session.py`, `src/invisible_playwright/_juggler/remote.py`, `src/invisible_playwright/cli.py`, `invisible_core: src/invisible_core/seal.py`.
|
||||
|
||||
**Don't.**
|
||||
- Resolve an executable anywhere but `_engine.resolve_executable()`.
|
||||
- Add a background prefetch of the engine to the wrapper.
|
||||
- Pass `binary_path=` to `invisible_core` without `verify_engine`, or use `binary_path` to skip the seal.
|
||||
- Replace the check after the launch with a read from the prefs or from JavaScript.
|
||||
@@ -0,0 +1,19 @@
|
||||
# wrapper-04: one transport, the Juggler server runs inside the Python process
|
||||
|
||||
**Rule.** The Playwright client reaches the engine through a Juggler server that runs in the same Python process, and through nothing else.
|
||||
- The transport is `InProcessTransport`, behind the seam `Transport`, an abstract class with five abstract methods. `make_transport` in `_juggler/transport.py` returns `InProcessTransport`, or `JsonWireTransport` (the same class, passing every message through JSON) when `INVPW_WIRE=json`. No variable selects a driver.
|
||||
- Blocking Juggler operations run on a small pool of worker threads, not on the asyncio loop.
|
||||
- A closed pipe raises `TargetClosedError`. `sync_api` and `async_api` export it. It is a different class from the refusal of a page, so a caller tells a refused page from a dead browser by type.
|
||||
- The arguments of a call travel as protocol parameters, not as text. No value is substituted into the code of the caller, and each value stays data up to the page.
|
||||
|
||||
**Enforced by.** `tests/test_fork.py::test_the_node_driver_is_gone` and `::test_no_module_imports_the_removed_driver` fail when the driver tree, the Node module or a module that imports them comes back. `tests/test_no_legacy_in_the_wrapper.py::test_the_transport_module_has_no_driver_switch` fails when the transport module offers a way to choose a driver. `tests/test_the_wire_is_json.py::test_the_wire_transport_hands_the_server_the_text_s_message` and `::test_the_plain_transport_still_passes_the_object_it_is_given` fail when the two transports change what they hand to the server. `tests/test_a_closed_pipe_is_a_closed_target.py::test_a_pipe_that_closes_while_a_call_waits_is_a_closed_target`, `::test_a_call_on_a_pipe_already_closed_is_a_closed_target`, `::test_the_dispatcher_and_the_connection_raise_the_same_class` and `::test_the_public_api_exports_the_type_a_caller_catches` fail when a closed pipe stops raising `TargetClosedError` or the public API stops exporting it. `tests/test_the_argument_does_not_rewrite_the_expression.py::test_the_script_the_page_evaluates_is_the_callers_text`, `::test_no_placeholder_is_left_anywhere_in_the_package` and `::test_the_callers_text_is_evaluated_in_one_place_and_wrapped_in_none` fail when an argument is merged into the text of the caller's code.
|
||||
|
||||
**Why.** One process to manage, and one bridge between the client and the server. A caller who can tell a closed browser from a refused page by type does not compare error text. A value that is never turned into script text cannot be read as code.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/transport.py`, `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_juggler/_marshal.py`, `src/invisible_playwright/_pw/_impl/_errors.py`, `src/invisible_playwright/sync_api.py`, `src/invisible_playwright/async_api.py`.
|
||||
|
||||
**Don't.**
|
||||
- Bring back `_driver/`, `_node.py`, `PipeTransport` or a Node driver.
|
||||
- Run a blocking Juggler operation on the asyncio loop.
|
||||
- Compare the text of an error to learn the reason, or treat a closed pipe as a generic `Error`.
|
||||
- Build a script by substituting text into the code of the caller.
|
||||
@@ -0,0 +1,22 @@
|
||||
# wrapper-05: the server keeps only live objects, and one registry holds the event subscribers
|
||||
|
||||
**Rule.** The server forgets what is closed, holds events that arrive before their page, and delivers each event once through one registry.
|
||||
- `Server._objects` holds live objects only. When a page closes, its children leave in `Dispatcher.dispose()`. The client drops the children of a disposed object by itself, so the server sends one `__dispose__` and no more.
|
||||
- `BrowserDispatcher` holds up to 256 events per session until a `PageDispatcher` exists for it (`BUFFER_CAP`). After that the page handler `_on_juggler_event` takes the events, and each held event is delivered once, in the order it arrived.
|
||||
- The payload of a console message and of a page error is built once in `server.py` and shared by the log and the live event.
|
||||
- `EventListeners` in the core, `juggler/connection.py`, is the only registry of subscribers. It is a flat list, and delivery iterates it. An error in one subscriber does not take the event from the others. A subscriber registered twice receives the event once. A page that closes removes its subscribers.
|
||||
- A dialog is a `DialogDispatcher`, built by `PageDispatcher._on_juggler_event` on `Page.dialogOpened`. It has a guid and a channel and is announced with `__create__` in its constructor, before the `dialog` event of the context.
|
||||
- Events leave through `Dispatcher.emit` and `Server.send_up`. `InProcessTransport.emit_message` hands them to the client with `call_soon_threadsafe`, and exceptions are translated by `_error_payload` in `transport.py`.
|
||||
|
||||
**Enforced by.** `tests/test_juggler_event_listeners.py::test_many_subscribers_do_not_consume_the_python_stack`, `::test_a_subscriber_that_raises_does_not_cost_the_others_their_event`, `::test_registering_the_same_subscriber_twice_delivers_once` and `::test_the_page_dispatcher_unsubscribes_all_three_when_the_page_closes` fail when delivery nests, one failing subscriber hides an event from the rest, a subscriber is registered twice, or a closed page leaves subscribers behind. `::test_a_long_session_does_not_accumulate_subscribers` fails when forty open-and-close cycles leave subscribers or objects in either registry. `tests/test_a_closed_context_leaves_nothing_in_the_registry.py::test_the_registry_is_what_it_was_after_the_contexts_close` and `::test_the_count_of_objects_is_stable_across_cycles` fail when closed objects stay in `Server._objects`. `tests/test_juggler_event_buffer.py::test_events_of_an_unread_session_are_held_and_replayed_in_order`, `::test_a_session_with_a_reader_is_not_buffered_any_more` and `::test_the_buffer_is_capped` fail when early events are lost, buffered twice, or held without a cap. `tests/test_no_event_of_any_family_is_lost_by_the_hand_over.py::test_one_event_of_each_family_reaches_the_client_once_and_in_order_at_every_point_of_the_hand_over` fails when an event is lost or doubled during the hand over of a page. `tests/test_a_dialog_is_a_protocol_object.py::test_a_dialog_is_announced_with_a_guid_under_its_page_before_the_event` fails when the `dialog` event comes before `__create__`.
|
||||
|
||||
**Why.** The client drops the children of a closed object itself, so a server that keeps them holds dead objects for the life of the browser. Some events arrive before a page exists, and dropping them loses a console message or a dialog. Chained subscribers deepen the stack with every page, and past the recursion limit every event fails without a visible error.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/dispatcher.py`, `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_juggler/transport.py`, `invisible_core: src/invisible_core/juggler/connection.py`.
|
||||
|
||||
**Don't.**
|
||||
- Drop an event because no page exists yet to receive it.
|
||||
- Build the console or page-error payload in two places.
|
||||
- Replace the registry with chained `on_event` closures, which end in `RecursionError`.
|
||||
- Emit the `dialog` event before the `__create__` of the dialog.
|
||||
- Hand events to the client without going through `emit_message`.
|
||||
@@ -0,0 +1,21 @@
|
||||
# wrapper-06: one server operation per API name, and action options read in one place
|
||||
|
||||
**Rule.** The server answers the Playwright API call by call, and each option of an action is read once.
|
||||
- The server has one operation for each API name, not one Juggler command for each call. A name inside the perimeter is served and any other is refused. The names on the wire are the ones the client sends, read from the client, and are not guessed. The actions of an `ElementHandle` (click, hover, fill, type, press, focus, check, uncheck, `selectOption`, `setInputFiles`) go through `actions`, and `selectOption` keeps its camelCase.
|
||||
- `dispatch_event` reads its argument from the envelope `{value, handles}` in one place, `_event_init`.
|
||||
- `drop` with an explicit `DataTransfer` is refused. Juggler has no command that injects that payload, and the server does not emulate it with substitute events.
|
||||
- `trial` runs the actionability checks and does not act. `force` is passed to every action. `strict` is read in one place, `_act_opts`, and every Locator method sends `strict=True`. When the selector matches several elements, the action fails with an explicit error and does not click the first.
|
||||
- `position` is read in one place, `_position`, by the six pointing actions. `button`, `modifiers` and `clickCount` of the pointing actions are read in one place, `_pointer`. `modifiers=["Shift"]` reaches the page as a real Shift. A modifier named by the caller is added to what the keyboard already holds.
|
||||
|
||||
**Enforced by.** `tests/test_every_wire_method_is_served_or_refused.py::test_every_send_of_the_client_has_a_channel` and `::test_the_wire_method_budget_matches_the_code` fail when a method the client sends is neither served nor refused. `tests/test_an_element_handle_serves_every_method_of_the_client.py::test_the_client_s_method_is_on_the_table_and_not_a_gap` and `::test_a_call_of_the_client_is_not_answered_as_a_gap` fail when a method of the client is missing from the handle table. `tests/test_element_handle_actions.py::test_every_action_that_takes_an_element_forwards_it` fails when an action takes an element and does not pass it on. `tests/test_strict_and_force.py::test_only_one_place_in_the_server_names_these_options` fails when `trial`, `strict` or `force` is read outside `_act_opts`. `::test_every_operation_that_can_carry_these_options_does` fails when a new action does not pass the options. `::test_strict_reaches_the_place_that_can_refuse` and `::test_an_ambiguous_selector_under_strict_does_not_retry_until_timeout` fail when an ambiguous selector stops being refused. `::test_force_skips_the_actionability_states` fails when `force` is dropped. `tests/test_trial_does_not_act.py::test_a_trial_performs_the_checks_and_NOT_the_action` and `::test_a_trial_checks_the_hit_target_too` fail when a trial acts, or stops checking. `tests/test_pointer_position.py::test_an_explicit_position_reaches_the_event` fails when `position` is lost on the way to the page. `tests/test_mouse.py::test_click_with_modifier_keys` fails when a modifier does not reach the page. `tests/test_every_refusal_is_declared.py::test_every_declared_refusal_is_still_refused` fails when `drop` stops being refused.
|
||||
|
||||
**Why.** A Playwright call is higher than a Juggler command: one `click` is several commands, and the server has to serve the whole path of an action. A wire name that is guessed breaks the call. An option that is accepted by the API and read by nobody does nothing without an error: a `strict` that nobody reads makes a locator click the first of two buttons, and a lost `position` drops every click on the geometric centre.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_juggler/perimeter.py`, `src/invisible_playwright/_pw/_impl/_locator.py`.
|
||||
|
||||
**Don't.**
|
||||
- Map an API call to a single Juggler command, or guess a name on the wire.
|
||||
- Forward the raw argument of `dispatch_event` without decoding the envelope.
|
||||
- Emulate `drop` with substitute events.
|
||||
- Read `trial`, `strict` or `force` in more than one place, or click the first of several matched elements.
|
||||
- Remove `position` from a pointing action, or read `button` of a pointing action in more than one place.
|
||||
@@ -0,0 +1,23 @@
|
||||
# wrapper-07: the identity is applied before the first launch and at the creation of each context
|
||||
|
||||
**Rule.** The browser starts already configured, and every context gets its identity before its first page exists.
|
||||
- The server writes `user.js` with `write_user_js` before it starts the browser, and launches with `-profile`. `Browser.enable` takes no pref. All prefs of the browser go through the profile.
|
||||
- The session keys that are not prefs (the typing seed and the keyboard layout) are taken out of the prefs before `write_user_js` (`op_launch` in `server.py`). Nothing of them is written to the profile.
|
||||
- `build_prefs` in `_session.py` composes the prefs of a session. The proxy does not go through it.
|
||||
- The `Browser.set*Override` commands run when the context is created, in `_apply_context_options`, before the first page, so the first page already sees them. The timezone is one of them: `timezoneId` goes out as `Browser.setTimezoneOverride` with the other entries of `ENGINE_OPTIONS` in `server.py`.
|
||||
- The persistent context has the same parameters as the default context, locale and timezone included. An empty timezone is left out.
|
||||
- `Browser.setDefaultViewport` carries `viewportSize` and `screenSize`. The screen comes from the `screen` option, which the wrapper takes from the profile with `context_geometry`. `deviceScaleFactor` is sent when present and `isMobile` when true.
|
||||
- `colorScheme`, `reducedMotion` and `forcedColors` of a context go to the engine with `Browser.setColorScheme`, `Browser.setReducedMotion` and `Browser.setForcedColors`. The value `no-override` is not sent, and the context keeps what the identity declares. `emulate_media` forwards only the fields that were asked for, `contrast` included.
|
||||
|
||||
**Enforced by.** `tests/test_session_transport.py::test_the_keys_come_back_out_before_the_profile_is_written` and `::test_without_the_keys_there_is_no_hand_and_nothing_is_lost` fail when a session key stays in the prefs that reach the profile. `::test_the_pref_namespace_is_not_the_binarys` fails when a session key is written under the namespace of the engine. `tests/test_launcher_config.py::test_persistent_context_kwargs_match_default_exactly`, `::test_persistent_context_kwargs_INCLUDES_locale_and_timezone` and `::test_persistent_context_kwargs_omits_timezone_when_empty_string` fail when the persistent context loses locale or timezone, or sends an empty timezone. `tests/test_a_launch_and_a_context_timezone_reach_the_page_e2e.py::test_a_launch_and_a_context_timezone_reach_the_page` fails when a timezone does not reach the first page. `tests/test_no_override_leaves_the_persona_scheme.py::test_no_override_is_not_an_engine_command`, `::test_the_go_clients_whole_option_set_sends_nothing_about_the_scheme`, `::test_an_explicit_scheme_is_still_sent` and `::test_emulate_media_with_nothing_asked_sends_nothing` fail when `no-override` reaches the engine, or an explicit value stops going out. `tests/test_service_worker_options.py::test_block_command_precedes_context_exposure_and_other_options` fails when the context options are applied after the context is exposed.
|
||||
|
||||
**Why.** A configuration applied at the second launch leaves the first launch wrong. A page that sees the defaults of the engine before the override is a page that saw a different machine. A persistent context with another identity would be another profile.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_session.py`, `src/invisible_playwright/launcher.py`, `invisible_core: src/invisible_core/launch.py`.
|
||||
|
||||
**Don't.**
|
||||
- Pass `firefoxUserPrefs` in `Browser.enable`, or discard the prefs.
|
||||
- Apply an override after the first page of the context exists.
|
||||
- Leave locale or timezone out of the persistent context.
|
||||
- Send `no-override` to the engine.
|
||||
- Write a session key to the profile.
|
||||
@@ -0,0 +1,20 @@
|
||||
# wrapper-08: the proxy of the caller is the road of the page, or the launch is refused
|
||||
|
||||
**Rule.** A proxy given by the caller is routed as asked, or the launch fails. It is never dropped and never replaced by a direct connection.
|
||||
- The wrapper calls `configure_proxy` (core, `_proxy.py`) right after `build_prefs`. It validates the proxy with `parse_proxy`, closes with prefs the channels that would leave in clear, and returns the endpoint. It writes no routing pref: the routing is the command to the engine.
|
||||
- `server.py` builds that command with `launch_proxy_command` (core) before the browser starts. A proxy the engine cannot express makes the command fail, and no traffic leaves in clear.
|
||||
- The schemes http, https and socks go through the proxy. Credentials and bypass reach the engine in the form it expects. Empty credentials are not sent.
|
||||
- With or without a proxy, `_build_env` declares the host network to the engine (`STEALTHFOX_WEBRTC_NETWORK`, chosen from the seed). A value already in the environment of the caller wins.
|
||||
- The exit IP is read once at the launch (`_webrtc_egress_ip`). `_assert_uscita_invariata` in `launcher.py` and `async_api.py` checks it again at most every 120 seconds, when a context or a page is created, with three outcomes: it holds, it drifted (refuse at once), it could not be measured (counted, refused only after three in a row). A result that could not be measured is never read as "it holds". Without a proxy the check does not run.
|
||||
|
||||
**Enforced by.** `tests/test_proxy_reaches_the_browser.py::test_the_server_string_becomes_the_fields_the_engine_declares`, `::test_credentials_and_bypass_travel_in_the_shape_the_engine_wants`, `::test_credentials_are_omitted_rather_than_sent_empty` and `::test_a_proxy_that_cannot_be_expressed_raises_rather_than_returning_nothing` fail when the proxy is read, shaped or dropped differently. `::test_a_proxy_that_cannot_be_applied_refuses_the_launch` and `::test_what_the_page_receives_came_through_the_proxy` fail when a launch goes on without its proxy or a page does not leave through it. `tests/test_proxy_http_auth_e2e.py::test_the_page_goes_out_through_an_authenticated_http_proxy` and `tests/test_proxy_socks_auth_e2e.py::test_socks5_auth_creds_sent_and_routed` fail when the credentials of an http or socks proxy are not used. `tests/test_nothing_leaves_but_the_proxy_e2e.py::test_a_kind_of_page_work_leaves_only_through_the_proxy_of_its_context` fails when any kind of page work leaves outside the proxy. `tests/test_the_network_declaration_reaches_the_engine.py::test_a_session_declares_its_seed_network_with_or_without_a_proxy` fails when the network declaration depends on the proxy. `tests/test_launcher_helpers.py::test_build_env_carries_the_declared_network` and `::test_build_env_caller_env_override_wins` fail when the declaration does not reach the engine, or a value already in the environment of the caller stops winning. `tests/test_webrtc_realness.py::test_a_changed_egress_is_detected`, `::test_a_failed_discovery_is_not_a_drift`, `::test_a_dropped_probe_is_not_a_confirmation`, `::test_the_three_outcomes_are_distinct_and_all_reachable`, `::test_without_a_proxy_there_is_nothing_to_betray`, `::test_a_burst_of_silent_probes_rejects_the_session` and `::test_both_classes_are_checked` fail when the exit check changes its verdicts, or either class stops running it.
|
||||
|
||||
**Why.** The proxy is the road of the page, and it belongs to the real connection, not to the fingerprint. A proxy that degrades in silence puts the page on the address of the host while the timezone and the locale were decided through the proxy. A residential proxy does not promise the same exit IP for a long session, and then the timezone and the locale describe another place than the exit.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_session.py`, `src/invisible_playwright/launcher.py`, `src/invisible_playwright/async_api.py`, `invisible_core: src/invisible_core/_proxy.py`.
|
||||
|
||||
**Don't.**
|
||||
- Fall back to a direct connection when the proxy cannot be expressed.
|
||||
- Send empty credentials to the engine.
|
||||
- Read a measurement that could not be made as "the exit holds".
|
||||
- Update the declared timezone and locale on the fly when the exit drifts.
|
||||
@@ -0,0 +1,20 @@
|
||||
# wrapper-09: route stays inside the perimeter, with explicit refusals and ordinary headers
|
||||
|
||||
**Rule.** `page.route` and `context.route` are served, and a configuration that cannot honour them is refused.
|
||||
- `page.route` and `context.route` are inside the perimeter. The handlers of the page run before those of the context.
|
||||
- When the browser was launched with `dom.serviceWorkers.enabled=false`, `route()` refuses (`require_interception` in `server.py`). `dom.serviceWorkers.enabled` stays true: with false, no request reaches `context.route`.
|
||||
- `service_workers="block"` sends `Browser.setServiceWorkersBlocked` to the context, and the requests of the page stay in front of `route()`.
|
||||
- The interception of a context is a boolean on the protocol. The client filters by URL and continues the requests it does not need.
|
||||
- `page.route` sends only `Network.setRequestInterception`. It does not send `Page.setCacheDisabled`. `context.route` sends `Browser.setRequestInterception` and, with the same flag, `Browser.setCacheDisabled` (`op_set_interception` of the context, `server.py`). The wrapper sets no `LOAD_BYPASS_CACHE` for interception.
|
||||
- A route rewrites the request and sends it through another channel. With a route active the order of the headers is the order of a request without a route: the order is read from the original channel and put back on the final channel after internal redirects (`NetworkObserver.js`).
|
||||
|
||||
**Enforced by.** `tests/test_route_e2e.py::test_a_route_without_service_workers_refuses_instead_of_ignoring` fails when a route is accepted in a browser that cannot intercept. `tests/test_service_workers_blocked.py::test_block_rejects_registration_and_keeps_routes` and `::test_block_is_context_local_and_keeps_ordinary_workers` fail when blocking service workers drops the routes or leaks into other contexts. `tests/test_service_worker_options.py::test_block_command_precedes_context_exposure_and_other_options` and `::test_unblocked_contexts_do_not_send_a_worker_command` fail when the block command changes its place or is sent for a context that did not ask for it. `tests/test_a_context_route_disables_the_cache.py::test_a_route_disables_the_cache_of_its_context` and `::test_the_last_route_gone_enables_the_cache_again` fail when the cache command of a context route changes. `tests/test_route_header_order_e2e.py::test_a_route_sends_the_headers_a_request_without_one_sends` and `::test_an_empty_header_survives_a_route` fail when a route changes the headers or their order.
|
||||
|
||||
**Why.** An option that is ignored in silence lies to the caller, and a route that is accepted and never runs is worse than none: a guard that stops no request leaves the caller believing it is protected. A routed request has to look like an ordinary one, so the headers keep the order of a request without a route.
|
||||
|
||||
**Files.** `src/invisible_playwright/_juggler/server.py`, `firefox_antidetect_patch: automation/juggler/src/juggler/NetworkObserver.js`.
|
||||
|
||||
**Don't.**
|
||||
- Take `route` out of the perimeter.
|
||||
- Send `Page.setCacheDisabled`, set `LOAD_BYPASS_CACHE`, or set `dom.serviceWorkers.enabled` to false.
|
||||
- Rebuild the headers in the wrapper.
|
||||
@@ -0,0 +1,20 @@
|
||||
# wrapper-10: the path of the cursor is drawn in Python, by the server of the wrapper
|
||||
|
||||
**Rule.** The pointer moves along a path that the wrapper draws from the seed, and the path is complete before the action runs.
|
||||
- The movement is generated in Python by the server of the wrapper, in `_juggler/pointer.py`, with the generator and the planners of `invisible_core.juggler`. It is never generated in the engine.
|
||||
- The server walks before click, hover, dblclick, tap, check and uncheck (of a Frame and of an ElementHandle), and before `Mouse.click` and `Mouse.dblclick`. It also draws the burst of `Mouse.wheel`. An explicit `Mouse.move` belongs to the caller: the in-process client marks it, so that the server draws the stroke, and a client that does not mark it receives exactly the point it named.
|
||||
- `_cursor.py` decides before the launch who draws, the budget of `humanize`, the motion seed of each page and the opt-out of the off-centre landing.
|
||||
- `INVPW_CURSOR_ENGINE` accepts only `python` (the default) and `off`. Any other value is an error. `off` turns the humanisation off, like `humanize=False`.
|
||||
- The walk ends before the server runs the action (`Pointer.act`). The pointer asks the element, with `Actions.hit_target`, whether the chosen point falls inside it. It adds no listener to the page. The target is the point computed inside the element, not the centre of its box. A point that is not inside the element, or that the action refuses, is not used: the action runs with the arguments of the caller.
|
||||
- The wrapper writes `stealthfox.humanize` as false, so that the engine does not expand the waypoints the server sends into a path of its own.
|
||||
|
||||
**Enforced by.** `tests/test_pointer_server.py::test_a_plain_action_draws_the_walk_the_client_used_to_draw`, `::test_a_click_is_more_than_one_mousemove`, `::test_an_explicit_mouse_move_is_not_walked` and `::test_the_same_seed_and_page_replay_the_walk` fail when a pointer action stops walking, an explicit move is walked, or the walk stops following the seed. `tests/test_a_path_leaves_as_one_stroke.py::test_the_approach_is_one_walk_and_no_single_move` fails when the approach is sent as a jump. `tests/test_cursor_wiring.py::test_python_engine_turns_the_browser_side_expansion_off` fails when `stealthfox.humanize` is not false. `::test_a_value_that_is_not_a_cursor_engine_is_refused`, `::test_the_valid_values_of_the_engine_variable` and `::test_escape_hatch_off_disables_motion_without_touching_the_constructor` fail when the engine variable accepts another value or `off` does not switch the motion off. `::test_the_whole_approach_runs_before_the_action`, `::test_a_point_that_does_not_hit_the_element_is_not_used`, `::test_the_landing_is_checked_by_the_actions_own_hit_test_in_the_boxs_space` and `::test_a_landing_that_is_not_actionable_retries_the_caller_s_own_call` fail when the walk runs after the action, or a point that misses the element reaches the action. `tests/test_no_legacy_in_the_wrapper.py::test_the_cursor_module_has_one_generator_and_two_engines`, `::test_the_generator_is_imported_directly_and_has_no_fallback` and `::test_the_engine_variable_takes_no_alias` fail when a second engine, a fallback or an alias comes back.
|
||||
|
||||
**Why.** A page must see the same motion through every client: the in-process client sends the plain action and the server draws the path where all actions arrive. Drawing the path before the action settles the hit-target check by construction: the check sees only the final point, and the path cannot make the action fail. The centre of a box is wrong for round controls, links over several lines and shadow roots, so the point is chosen inside the element and verified with the same test the action uses.
|
||||
|
||||
**Files.** `src/invisible_playwright/_cursor.py`, `src/invisible_playwright/_juggler/pointer.py`, `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_session.py`, `invisible_core: src/invisible_core/juggler/actions.py`, `invisible_core: src/invisible_core/prefs.py`.
|
||||
|
||||
**Don't.**
|
||||
- Generate the path inside the point where the mouse is sent, or change the order of the approach.
|
||||
- Put trajectory logic in the engine, or write `stealthfox.humanize` as true from the wrapper.
|
||||
- Accept a value of `INVPW_CURSOR_ENGINE` other than `python` and `off`.
|
||||
@@ -0,0 +1,21 @@
|
||||
# wrapper-11: the variability and the rhythm of the hand come from the seed of the session
|
||||
|
||||
**Rule.** The hand has errors and a rhythm of its own, drawn from the seed. No error is always zero, and no rhythm is a fixed number.
|
||||
- The cursor plans drift while it is reading (`plan_idle`), scroll (`plan_scroll`), an approach with overshoot and correction (`plan_approach`) and aimless moves (`plan_aimless_move`). `drift_px` is between 4 and 26 px and `overshoot_bias` between 0.55 and 1.45, both drawn from the seed of the session. Each session has its own drift and its own overshoot rate.
|
||||
- The tremor is Gaussian with mean zero, with a component along the movement and a component across it, independent and with scales of their own. It is applied to the intermediate points of the path and is computed in the core, in the module of the motion engine. A mean other than zero would be a systematic drift on every path.
|
||||
- The pacer is in the core. The wrapper uses it for the drag and for the clicks. Every deadline is measured from one `t0`, with no separate clocks. No two events leave at the same instant. Sampling has a floor of 8 ms. Events on the same physical pixel are collapsed at a rate drawn from the seed. The drag follows the same discipline as the clicks.
|
||||
- The wrapper answers a dialog after a reading pause drawn from the seed of the session: a reaction plus a reading time per word, both log-normal, limited to 350 ms and 8 s. A handler that already took its time does not wait again. Without a seed there is no pause.
|
||||
- A dialog without a handler is answered by the client: `beforeunload` is accepted and any other dialog is dismissed. This lives in the wrapper, not in the core.
|
||||
- The pause before an upload is inside `set_input_files`. The wrapper adds no separate method for it.
|
||||
|
||||
**Enforced by.** `invisible_core: tests/test_motion.py::test_tremor_is_zero_mean_on_both_components` and `::test_the_tremor_is_not_rank_one` fail when the tremor gets a mean other than zero or acts on one axis only. `invisible_core: tests/test_behaviour.py::test_some_approaches_actually_overshoot_and_come_back` fails when the approach stops overshooting. `invisible_core: tests/test_pacing.py::test_two_events_are_never_sent_at_one_instant` and `::test_lateness_does_not_accumulate_because_the_deadlines_are_absolute` fail when two events share an instant or the deadlines drift. `invisible_core: tests/test_behaviour.py::test_duplicate_positions_happen_but_stay_rare` fails when the rate of events on one pixel becomes fixed or common. `tests/test_cursor_dispatch.py::test_no_two_events_are_delivered_in_the_same_instant` fails when the wrapper sends two events at one instant. `tests/test_drag_motion.py::test_a_glide_crosses_the_page_in_many_events_not_one`, `::test_two_drags_in_a_session_do_not_draw_the_same_path` and `::test_the_path_is_the_seeds_and_not_a_constant` fail when a drag jumps, repeats its path, or ignores the seed. `tests/test_click_rhythm.py::test_a_click_is_held_for_as_long_as_a_finger_holds_it` and `::test_two_clicks_in_a_session_are_not_the_same_length` fail when a click has no duration or every click has the same one. `tests/test_a_dialog_is_answered_after_a_pause.py::test_the_pause_is_the_seed_s_and_grows_with_the_words`, `::test_only_the_remainder_is_waited`, `::test_a_slow_handler_is_not_made_slower` and `::test_the_second_dialog_of_a_page_draws_its_own_pause` fail when the pause stops following the seed, the words or the time already spent. `tests/test_juggler_transport.py::test_an_unanswered_dialog_is_dismissed_by_the_client` fails when a dialog is left without an answer. `tests/test_a_field_is_typed_after_a_pause.py::test_files_arrive_after_a_persons_pause_to_pick_them` and `::test_the_package_adds_no_pause_helper_to_playwrights_contract` fail when an upload has no pause, or the package exports a pause helper.
|
||||
|
||||
**Why.** An error that is always zero is an invariant, and an invariant is a signature. A movement that never errs, or always drifts the same way, can be recognised. The rhythm of the events is visible to the page. A dialog closed in the millisecond it opens, or a file attached with no pause, is not the behaviour of a person. A dialog left unanswered stops the content process.
|
||||
|
||||
**Files.** `src/invisible_playwright/_cursor.py`, `src/invisible_playwright/_juggler/dialogs.py`, `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_pw/_impl/_browser_context.py`, `invisible_core: src/invisible_core/juggler/_behaviour.py`, `invisible_core: src/invisible_core/juggler/_motion.py`, `invisible_core: src/invisible_core/juggler/_pacing.py`, `invisible_core: src/invisible_core/juggler/actions.py`.
|
||||
|
||||
**Don't.**
|
||||
- Make the overshoot rate or the drift a fixed number.
|
||||
- Use a mean other than zero for the tremor, or a tremor on one axis only.
|
||||
- Send two events at the same instant, or use a fixed rate of events on the same pixel.
|
||||
- Answer a dialog at once, with a fixed pause, or not at all.
|
||||
@@ -0,0 +1,21 @@
|
||||
# wrapper-12: the pointer is visible in the window, never in the page
|
||||
|
||||
**Rule.** The visible pointer is for a person who watches a session. It is never a surface of the page.
|
||||
- `DEFAULT_SHOW_CURSOR` in the core `prefs.py` is the only default. The wrapper does not import it: it passes `show_cursor=None` to the core (`build_prefs` in `_session.py`), and the core turns `None` into `DEFAULT_SHOW_CURSOR`. The sync and the async entry point have `None` in their signature.
|
||||
- The value is always written as `stealthfox.showcursor`, false included.
|
||||
- The node lives in the chrome document, with `pointer-events: none` and passive listeners. Off means the node is absent. The handlers only record data and ask for a frame, and the style is written once per frame.
|
||||
- The pointer does not show in a screenshot or in the DOM of the page.
|
||||
- The pointer draws the standard Windows arrow: a white body with a dark outline, with the hotspot on the tip. It has one halo colour, green. A click changes the size of the halo, not its colour, because two colours would read as two states of the tool.
|
||||
- The arrow is a `data:image/svg+xml` in which `#` is written as `%23`. An unescaped `#` in the data URI cuts the SVG in silence.
|
||||
|
||||
**Enforced by.** `tests/test_cursor_wiring.py::test_the_show_cursor_kwarg_reaches_the_prefs` fails when `show_cursor` does not reach the prefs, or `None` becomes false on the way. `::test_neither_entry_point_decides_the_cursor_default` fails when a signature of the wrapper gets a default of its own. `::test_the_core_we_resolve_against_decides_the_cursor_default` fails when the core in use does not own `DEFAULT_SHOW_CURSOR` or does not give the pref the value it names. `::test_the_dot_and_the_motion_are_two_switches` fails when the pointer and the humanisation depend on each other.
|
||||
|
||||
**Why.** One default decided in one place keeps the sync and the async API from drifting apart. The pointer exists to watch a session while it runs, so it is drawn where the page cannot see it. The data URI is escaped by hand because a raw `#` makes the pointer invisible with no error.
|
||||
|
||||
**Files.** `src/invisible_playwright/_session.py`, `src/invisible_playwright/launcher.py`, `src/invisible_playwright/async_api.py`, `invisible_core: src/invisible_core/prefs.py`, `firefox_antidetect_patch: automation/juggler/src/juggler/StealthCursor.js`.
|
||||
|
||||
**Don't.**
|
||||
- Copy the default into another place of the wrapper, or turn `None` into a value in the wrapper.
|
||||
- Write synchronously in the path of the input.
|
||||
- Write a bare `#` in the data URI of the arrow.
|
||||
- Give the halo a second colour for the click.
|
||||
@@ -0,0 +1,18 @@
|
||||
# wrapper-13: true headless only on request, and the screencast is live
|
||||
|
||||
**Rule.** The default of a hidden session is a headed browser on a surface nobody looks at. True headless is an explicit choice, and the screencast streams frames and does not write a file.
|
||||
- `INVPW_TRUE_HEADLESS=1` switches a session that asked for `headless` from the hidden headed mode to true headless, in the sync and the async client. Without the variable the session stays headed and hidden. The variable is read in one file, `_session.py`.
|
||||
- `screencastStart` with `record` raises `ProtocolException` (`op_screencast_start` in `server.py`). The engine has no video encoder, so it cannot write a video file.
|
||||
- `screencastStart` and `screencastStop` are inside the perimeter. Live frames come from `page.screencast.start(on_frame=...)`, as JPEG, and show the window of the browser as it is.
|
||||
- The perimeter leaves out only the overlays of a recording: `screencastChapter`, `screencastHideActions`, `screencastRemoveOverlay`, `screencastSetOverlayVisible`, `screencastShowActions` and `screencastShowOverlay` (`perimeter.py`).
|
||||
|
||||
**Enforced by.** `tests/test_async_api.py::test_both_apis_read_the_same_environment_variables` fails when an entry point reads an environment variable of its own, `INVPW_TRUE_HEADLESS` included. `tests/test_virtual_display_start_off_the_loop.py::test_sync_and_async_make_the_same_decision` fails when the two clients decide differently about the hidden display and true headless. `tests/test_screencast.py::test_a_video_file_is_refused_with_the_reason` fails when `record` stops being refused, or `start` without a frame handler is accepted. `::test_start_and_stop_left_the_perimeter_and_the_overlay_did_not` fails when `screencastStart` or `screencastStop` is declared outside the perimeter, or an overlay is served. `::test_start_asks_the_engine_for_the_whole_window` fails when the frames stop being those of the window.
|
||||
|
||||
**Why.** The hidden headed mode is the one that renders as a real browser does, and true headless is a different rendering path that a caller chooses on purpose. A video file cannot be honoured without an encoder, and a file that looks valid and shows nothing is worse than a refusal. Live frames show the window as a person would see it.
|
||||
|
||||
**Files.** `src/invisible_playwright/_session.py`, `src/invisible_playwright/_juggler/server.py`, `src/invisible_playwright/_juggler/perimeter.py`.
|
||||
|
||||
**Don't.**
|
||||
- Make true headless the default.
|
||||
- Read `INVPW_TRUE_HEADLESS` anywhere but `_session.py`.
|
||||
- Implement video to a file without an encoder, or leave `screencastStart` and `screencastStop` out of the perimeter.
|
||||
@@ -0,0 +1,18 @@
|
||||
# wrapper-14: no timed wait, the tab waits for the event
|
||||
|
||||
**Rule.** The creation of a tab waits for an event of the engine and never for a time.
|
||||
- The race of a new tab is closed in the engine. The code that wraps the creation of a page, `_patch_new_context_defaults` in `launcher.py` and in `async_api.py`, contains no sleep. The wrapper waits for the event.
|
||||
- `op_goto` answers with the navigation response of the last hop. A redirect chain produces several responses with the same `navigationId`, and the answer is the last one. The list of requests is emptied on `requestFinished`, so `goto` returns when the document is finished, not at the first hop.
|
||||
- A navigation that created no document answers with no response. `goto` never returns `None` in place of a navigation response that exists.
|
||||
- The pre-seed (`prep_recaptcha`) is an option of the wrapper, not of Playwright. It is applied by `_patch_new_context_defaults` in `launcher.py`, above the public API, and only without `profile_dir`.
|
||||
|
||||
**Enforced by.** `tests/test_new_page_defaults.py::test_no_api_sleeps_after_creating_a_tab` fails when the code that wraps the creation of a tab, in either client, calls `sleep`. `::test_new_page_gets_the_same_defaults_as_new_context` and `::test_the_async_api_wraps_new_page_too` fail when the defaults are not applied to a new page in either client. `tests/test_navigation_response.py::test_op_goto_ANSWERS_WITH_THE_CHANNEL_and_not_with_None`, `::test_a_redirect_chain_answers_with_the_LAST_hop` and `::test_the_answer_SURVIVES_requestFinished_emptying_the_in_flight_map` fail when `goto` answers with `None`, with the first hop, or loses the response when the request finishes. `::test_op_goto_answers_None_when_the_navigation_created_no_document` fails when a navigation with no document answers with a response.
|
||||
|
||||
**Why.** A timed wait hides a race and does not close it. The cause of the race of the new tab was in the engine, and it is fixed there. A second remedy for one cause is a second truth.
|
||||
|
||||
**Files.** `src/invisible_playwright/launcher.py`, `src/invisible_playwright/async_api.py`, `src/invisible_playwright/_juggler/server.py`.
|
||||
|
||||
**Don't.**
|
||||
- Add a sleep or a pause after the creation of a tab.
|
||||
- Return `None` in place of the navigation response of `goto`.
|
||||
- Apply the pre-seed to a persistent profile: the profile owns its own state.
|
||||
@@ -0,0 +1,18 @@
|
||||
# wrapper-15: the CLI has two commands, and no cache management
|
||||
|
||||
**Rule.** The command line has `fetch` and `version`, and says the truth about the engine and the core in use.
|
||||
- The only subcommands are `fetch` and `version`. The CLI has no `--deep` on `fetch`, and no `doctor`, `path`, `clear-cache` or `--force`. A removed subcommand fails with a nonzero exit code and is not ignored.
|
||||
- `fetch` checks every cached engine against the seal and prints the ones that do not match on stderr. It then calls `ensure_binary`, asks the core for a newer security state, and prints the path of the engine as its last line. A failure of the security state is a warning: it changes neither the exit code nor the last line.
|
||||
- `version` prints the version of the wrapper, the version of the core read from the live seal, the tag, the Firefox version, the build id, the digest of the seal, and the two roots on disk, the engines and the state. When the install record of the core differs from the live one, it adds `STALE RECORD`.
|
||||
- The version of the wrapper is the one of the code. A normal install shows the version of the install record. An editable install shows the version of its source tree with the segment `+editable`. The two are told apart by `direct_url.json`, not by `__file__`. The CLI uses the same rule for the version of the wrapper.
|
||||
|
||||
**Enforced by.** `tests/test_cli.py::test_the_cli_offers_exactly_two_commands` and `::test_a_removed_subcommand_is_refused_rather_than_silently_ignored` fail when a command is added, or a removed one is accepted. `::test_fetch_takes_no_arguments` fails when `fetch` gets an argument. `::test_fetch_prints_the_path_as_its_last_line`, `::test_a_failing_security_state_is_a_warning_and_changes_neither_the_exit_nor_the_last_line` and `::test_a_mismatching_cached_tree_is_reported_but_does_not_stop_the_fetch` fail when the output or the exit code of `fetch` changes. `tests/test_version.py::test_version_subcommand_prints_real_version` fails when `version` stops printing the wrapper, the core, the engine and the seal. `tests/test_the_version_describes_the_code.py::test_an_editable_install_reports_what_its_tree_says`, `::test_an_editable_tree_is_never_mistaken_for_the_release` and `::test_a_normal_install_is_not_second_guessed` fail when the version of an install is read from the wrong source. `::test_no_module_in_this_package_types_a_version` fails when a version is typed in a module of the package.
|
||||
|
||||
**Why.** The cache of the engine is shared with other consumers of the core, so the wrapper has no command that prunes it. The version a bug report carries has to describe the code that ran, and an install record freezes at install time while an editable tree keeps moving.
|
||||
|
||||
**Files.** `src/invisible_playwright/cli.py`, `src/invisible_playwright/_version.py`.
|
||||
|
||||
**Don't.**
|
||||
- Add `doctor`, `path`, `clear-cache`, `--force` or a `--deep` option.
|
||||
- Use `__file__` to tell whether an install is editable.
|
||||
- Print a version of the wrapper that comes from the install record of an editable install.
|
||||
@@ -0,0 +1,16 @@
|
||||
# wrapper-16: a narrow public surface, and the core is the one implementation
|
||||
|
||||
**Rule.** The wrapper exports a short list of names, and everything else lives in `invisible_core`.
|
||||
- `__init__.py` re-exports `InvisiblePlaywright`, `launch_server`, `launch_server_async`, `RemoteServer`, `ensure_binary`, `ensure_geoip_mmdb`, `get_default_stealth_prefs`, `get_default_args`, `GeoTimezoneError`, `BINARY_VERSION`, `FIREFOX_UPSTREAM_VERSION`, `__version__` and `__install_record_version__`.
|
||||
- The rest of the geo and language surface is imported from `invisible_core`.
|
||||
- The modules `_geo`, `_headless`, `_proxy`, `_webgl_personas`, `config`, `constants`, `download` and `prefs` do not exist in the wrapper. They are imported from `invisible_core`, so there is one implementation. Copying the bindings would duplicate the classes and break `isinstance`.
|
||||
|
||||
**Enforced by.** `tests/test_no_legacy_in_the_wrapper.py::test_a_module_that_only_forwarded_to_the_core_is_not_back` fails when one of those modules comes back. `::test_no_module_of_the_package_hands_its_name_to_another_module` fails when a module of the wrapper replaces itself with a module of the core. `::test_the_package_root_does_not_re_export_what_the_core_dropped` fails when the root of the package exports `resolve_session_timezone`, a name the core dropped. `::test_no_file_of_the_wrapper_imports_a_name_the_core_removed` fails when a file of the wrapper imports such a name. `tests/test_imports.py::test_dunder_all_is_complete` fails when a name of `__all__` is missing from the package.
|
||||
|
||||
**Why.** Whoever needs the full geo surface imports the core directly. Geo and language functions stay in one place, the core. A second copy of a class in the wrapper is a different class, so `isinstance` against the one of the core fails.
|
||||
|
||||
**Files.** `src/invisible_playwright/__init__.py`.
|
||||
|
||||
**Don't.**
|
||||
- Add a geo or a language symbol to the wrapper.
|
||||
- Recreate the removed modules in the wrapper, or copy the bindings of `invisible_core`.
|
||||
Reference in new issue
Block a user