cdp-toolkit 3.0.2 → 3.1.0
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.
- package/CHANGELOG.md +25 -0
- package/CONTRACT.md +2 -2
- package/README.md +85 -2
- package/dist/bidi/mux-daemon.js +316 -10
- package/dist/cli.js +615 -94
- package/dist/index.js +440 -41
- package/dist/mcp.js +667 -133
- package/package.json +1 -1
- package/src/cdp/driver.ts +71 -11
- package/src/cli.ts +17 -4
- package/src/client.ts +22 -6
- package/src/endpoints.ts +428 -0
- package/src/install/browser.ts +9 -3
- package/src/install/wizard.ts +8 -8
- package/src/leases-tools.ts +6 -3
- package/src/leases.ts +28 -4
- package/src/manifest.ts +54 -42
- package/src/mcp.ts +52 -8
- package/src/origins.ts +5 -2
- package/src/policy.ts +163 -0
- package/src/reap.ts +14 -0
- package/src/shared-tools.ts +72 -4
- package/src/toolDocs.ts +39 -36
- package/src/tools/browser-session.ts +26 -12
- package/src/tools/dispatch-mouse.ts +2 -1
- package/src/tools/focus-emulation.ts +5 -3
- package/src/tools/lighthouse.ts +4 -2
- package/src/version.ts +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,31 @@ All notable changes to cdp-toolkit are documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project follows [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [Unreleased]
|
|
9
|
+
|
|
10
|
+
## [3.1.0] - 2026-11-10
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Named endpoints (#15): one server drives several DevTools ports, e.g. a browser and an Electron or WebView2 app such as the Microsoft Teams desktop app. Configure them with `CDP_ENDPOINTS="browser=http://127.0.0.1:9222,teams=http://127.0.0.1:9333?mode=read"` or a JSON file named by `CDP_ENDPOINTS_FILE`. Pick one per call with a `endpoint:<name>/<selector>` target prefix or an `endpoint` argument. A `chrome@<name>:` lease token also selects its own endpoint, and if the token and a prefix disagree the call is an error. Leases and origins are namespaced per endpoint. `list_pages {allEndpoints:true}` lists every endpoint, and a down one shows as `down:true`. An endpoint that is down at startup works once it comes up, with no restart. This supersedes item 5 of #12. (`src/endpoints.ts`, `src/mcp.ts`, `src/cli.ts`, `src/leases.ts`)
|
|
15
|
+
- Read-only endpoints (`?mode=read`, or `"readOnly": true` in the file): only read tools run there (snapshot, screenshot, lists, `evaluate_script`, waits). A mutating tool, or a read tool with an argument that changes the page (`reload`, `renderWidth`/`renderHeight`, a body fetch that re-requests), is refused before any CDP message goes out, with error code `read_only_endpoint`. `call_tool` can't get around this, because the inner tool is checked again. Strict-lease reaping never closes tabs on a read-only endpoint. (`src/policy.ts`, `src/reap.ts`)
|
|
16
|
+
- `tools/list` now carries `annotations.readOnlyHint` on every tool.
|
|
17
|
+
- Existing single-`CDP_BASE` setups behave as before: same lease and origin filenames, same `chrome:` tokens, and no endpoint fields in output.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- A tool whose result was `undefined` (e.g. `evaluate_script` on `void 0`) sent a reply with no text, and the MCP SDK rejected it with JSON-RPC -32602. It now answers `null`. The CLI prints `null` too.
|
|
22
|
+
|
|
23
|
+
## [3.0.3] - 2026-10-29
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
|
|
27
|
+
- `new_page` (and `claim_page` opening a fresh tab) wedged the tab in Vivaldi: blank content, an empty URL, a renderer that never answered again, and a 15 s `new_page` timeout under `claim:true`, until a person reloaded it. Vivaldi breaks any tab that something attaches to in its first few milliseconds, and the activity beacon attached straight after `Target.createTarget`. `newPage` now waits for the tab's first `Target.targetInfoChanged` (capped at 2 s) before returning. Verified live on Vivaldi 8.2 (Chromium 152) through `new_page {claim:true}`: on 3.0.2 two of two Fidelity tabs hung; with the fix three of three loaded in 230 to 390 ms with the beacon installed. (`src/cdp/driver.ts` `createSettledTarget`, `test/new-page-settle.test.ts`)
|
|
28
|
+
|
|
29
|
+
### Added
|
|
30
|
+
|
|
31
|
+
- `vivaldi` is now a supported `cdp install --browser` choice, wired like `arc`: binary detection (`VIVALDI_BIN`, `/Applications/Vivaldi.app/Contents/MacOS/Vivaldi`, `vivaldi` on PATH, `/usr/bin/vivaldi`), the `cdp-vivaldi` alias, the CLI choice list and help text, and the README. Vivaldi is Chromium, so it takes the same launch flags and the server env is the same as chrome and arc. (`src/install/browser.ts`, `src/install/wizard.ts`, `test/install-browser.test.ts`, `test/install-wizard.test.ts`)
|
|
32
|
+
|
|
8
33
|
## [3.0.2] - 2026-10-03
|
|
9
34
|
|
|
10
35
|
### Fixed
|
package/CONTRACT.md
CHANGED
|
@@ -12,7 +12,7 @@ writing a module.
|
|
|
12
12
|
3. **TypeScript strict.** `tsc --noEmit` must pass with `strict`, `noUncheckedIndexedAccess`, `verbatimModuleSyntax`. Import types with `import type`. Use `.ts` extensions in imports (e.g. `import { withPage } from "../client.ts"`).
|
|
13
13
|
4. **One module per assigned bundle.** Write only the files you are assigned. Never edit `client.ts`, `types.ts`, or another agent's file.
|
|
14
14
|
5. **Tool fn naming = camelCase of the MCP tool name.** `take_snapshot` → `export async function takeSnapshot(...)`. `list_network_requests` → `listNetworkRequests`. The integration step maps mechanically, so the names must be exact.
|
|
15
|
-
6. **Never re-resolve a target outside a choke point.** There are exactly three functions that turn a `TargetSelector` into a concrete tab, and all three call `assertLeaseOk`: `resolveTarget` (`src/client.ts`, Chrome), `resolveContext` (`src/bidi/driver.ts`, Firefox), and `resolvePage` (`src/shared-tools.ts`, used by `close_page`, `select_page`, and `release_page`'s `target` argument). A new tool must go through one of them. If you add a fourth resolution path, it must call `assertLeaseOk` too, or every tool on that path silently loses lease protection. Do NOT add a lease check to an individual tool: that puts the burden on every future contributor to remember it, and one forgotten tool defeats the feature for that tool. A lease conflict throws `LeaseConflictError` rather than being modelled as a capability gap under ADR-001. That departure is deliberate and reviewed: a runtime ownership collision between two agents is not a missing backend capability, so it cannot be discovered at `tools/list` time and must surface at call time. If you touch any of those three choke points, or the error handling above them, re-run `bun run lease:smoke` (`test/lease-smoke.ts`): `bun test` cannot reach this, because a lease is keyed on the claiming pid and only a second live OS process can collide with the first. That harness spawns one, drives a real browser, and asserts the refusal keeps its type, its `targetId` and its `holder` and actually blocks the side effect. It is safe against a browser with real tabs open: one throwaway tab, addressed and closed by its own id, with a runtime-captured baseline diffed at the end.
|
|
15
|
+
6. **Never re-resolve a target outside a choke point.** There are exactly three functions that turn a `TargetSelector` into a concrete tab, and all three call `assertLeaseOk`: `resolveTarget` (`src/client.ts`, Chrome), `resolveContext` (`src/bidi/driver.ts`, Firefox), and `resolvePage` (`src/shared-tools.ts`, used by `close_page`, `select_page`, and `release_page`'s `target` argument). A new tool must go through one of them. If you add a fourth resolution path, it must call `assertLeaseOk` too, or every tool on that path silently loses lease protection. Do NOT add a lease check to an individual tool: that puts the burden on every future contributor to remember it, and one forgotten tool defeats the feature for that tool. A lease conflict throws `LeaseConflictError` rather than being modelled as a capability gap under ADR-001. That departure is deliberate and reviewed: a runtime ownership collision between two agents is not a missing backend capability, so it cannot be discovered at `tools/list` time and must surface at call time. The named-endpoint prefix (`endpoint:<name>/`, issue #15) is NOT a fourth grammar arm in these pickers: `runTool` (`src/mcp.ts`) and the CLI dispatch strip it ONCE, before any of them run, and set the endpoint scope (`withEndpointScope`, `src/endpoints.ts`) that `listTargets`/`browserWsUrl` and the lease key (`chromeLeaseBackend`) read. Never parse it inside a picker. If you touch any of those three choke points, or the error handling above them, re-run `bun run lease:smoke` (`test/lease-smoke.ts`): `bun test` cannot reach this, because a lease is keyed on the claiming pid and only a second live OS process can collide with the first. That harness spawns one, drives a real browser, and asserts the refusal keeps its type, its `targetId` and its `holder` and actually blocks the side effect. It is safe against a browser with real tabs open: one throwaway tab, addressed and closed by its own id, with a runtime-captured baseline diffed at the end.
|
|
16
16
|
|
|
17
17
|
**Under `CDP_REQUIRE_LEASE` the gate does not only check, it can ACQUIRE.** `assertLeaseOk` calls `claimLease` itself when the resolved tab is unheld and strict mode is on (see `requireLease()` and the `auto` tier in `src/leases.ts`). A fourth resolution path that skipped the choke point used to lose only enforcement; under strict mode it also loses acquisition, so a tab reached that way is silently never protected even after the flag is on. `lease:smoke`'s strict-mode phase (`CDP_REQUIRE_LEASE=1`, run as a second live process) is what actually exercises this; `bun test` cannot, since acquisition is keyed on the calling pid the same way enforcement is.
|
|
18
18
|
|
|
@@ -27,7 +27,7 @@ writing a module.
|
|
|
27
27
|
## Core client API (from `src/client.ts`)
|
|
28
28
|
|
|
29
29
|
```ts
|
|
30
|
-
const BASE: string; // http://127.0.0.1:9222 (env CDP_BASE)
|
|
30
|
+
const BASE: string; // the DEFAULT endpoint's base, fixed at import: http://127.0.0.1:9222 (env CDP_BASE). Requests resolve per call via currentEndpoint() (src/endpoints.ts)
|
|
31
31
|
const DEFAULT_TIMEOUT_MS: number; // 15000 (env CDP_TIMEOUT_MS)
|
|
32
32
|
class CdpError extends Error {}
|
|
33
33
|
|
package/README.md
CHANGED
|
@@ -76,7 +76,7 @@ One honest caveat the benchmark also reports: while a navigation to a dead endpo
|
|
|
76
76
|
npx -y --package cdp-toolkit cdp install # or `cdp install` from a clone / after a global install
|
|
77
77
|
```
|
|
78
78
|
|
|
79
|
-
It asks for a harness (`claude` | `codex` | `opencode`), a debug port, and a browser (`arc` | `chrome` | `firefox`), then writes an idempotent marker block into your `~/.zshrc`/`~/.bashrc`. The same flags drive it non-interactively: `--harness --browser --port --name --no-alias --yes`. The Firefox alias it writes includes `--marionette` (required for cdp-toolkit's orphaned-session auto-recovery — see [Firefox](#firefox-webdriver-bidi)). It is a CLI subcommand, **not** a 49th tool: `cdp --list` still shows 48.
|
|
79
|
+
It asks for a harness (`claude` | `codex` | `opencode`), a debug port, and a browser (`arc` | `chrome` | `firefox` | `vivaldi`), then writes an idempotent marker block into your `~/.zshrc`/`~/.bashrc`. The same flags drive it non-interactively: `--harness --browser --port --name --no-alias --yes`. The Firefox alias it writes includes `--marionette` (required for cdp-toolkit's orphaned-session auto-recovery — see [Firefox](#firefox-webdriver-bidi)). It is a CLI subcommand, **not** a 49th tool: `cdp --list` still shows 48.
|
|
80
80
|
|
|
81
81
|
Prefer to wire it by hand? The manual path is three steps:
|
|
82
82
|
|
|
@@ -235,7 +235,9 @@ await TOOLS.navigate_page({ target: "index:0", url: "https://example.com" });
|
|
|
235
235
|
|
|
236
236
|
| Env var | Default | Purpose |
|
|
237
237
|
|---|---|---|
|
|
238
|
-
| `CDP_BASE` | `http://127.0.0.1:9222` | DevTools HTTP origin (drives discovery + the lighthouse `--port`). |
|
|
238
|
+
| `CDP_BASE` | `http://127.0.0.1:9222` | DevTools HTTP origin (drives discovery + the lighthouse `--port`). The endpoint named `default` when named endpoints are configured. |
|
|
239
|
+
| `CDP_ENDPOINTS` | unset | Chrome only. Extra named endpoints, `name=url` comma-separated, e.g. `browser=http://127.0.0.1:9222,teams=http://127.0.0.1:9333?mode=read`. See "Named endpoints" below. |
|
|
240
|
+
| `CDP_ENDPOINTS_FILE` | unset | Chrome only. Path to a JSON file defining named endpoints (same meaning as `CDP_ENDPOINTS`, merged with it). See "Named endpoints" below. |
|
|
239
241
|
| `CDP_TIMEOUT_MS` | `15000` | Per-command timeout. |
|
|
240
242
|
| `CDP_ARTIFACT_DIR` | `/tmp/cdp-toolkit` | Screenshots, traces, heap snapshots, lighthouse reports, recorder buffers. |
|
|
241
243
|
| `CDP_STATE_DIR` | `/tmp/cdp-toolkit` | `select_page` selected-target file, in-flight trace state. |
|
|
@@ -661,6 +663,87 @@ So every tab this toolkit creates is written to a creation ledger, and `list_pag
|
|
|
661
663
|
- No protection from humans. The lease is enforced against cdp-toolkit's own tool calls. It cannot stop someone clicking into the tab.
|
|
662
664
|
- Not for the CLI. A CLI invocation is one process per call, so a lease it claimed would be reclaimable immediately by the dead-pid rule. `claim_page` is refused there. CLI calls can still present a token minted by the MCP server with `--lease`. Strict mode (`CDP_REQUIRE_LEASE`) is likewise MCP-only and for the same underlying reason, doubled: an auto-acquired lease would be reclaimable on arrival, worse than no lease at all, and reap would then be free to read that instantly-dead-pid record as an abandoned tab and close it on the next listing.
|
|
663
665
|
|
|
666
|
+
## Named endpoints: several browsers or apps from one server
|
|
667
|
+
|
|
668
|
+
One server can drive more than one DevTools port: your browser on `9222` and, say, the Microsoft Teams desktop app (WebView2, launched with `WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9333`) or an Electron app. Chrome backend only.
|
|
669
|
+
|
|
670
|
+
```bash
|
|
671
|
+
CDP_ENDPOINTS="browser=http://127.0.0.1:9222,teams=http://127.0.0.1:9333?mode=read"
|
|
672
|
+
# or
|
|
673
|
+
CDP_ENDPOINTS_FILE=~/.config/cdp-endpoints.json
|
|
674
|
+
```
|
|
675
|
+
|
|
676
|
+
```json
|
|
677
|
+
{ "default": "browser",
|
|
678
|
+
"endpoints": {
|
|
679
|
+
"browser": { "base": "http://127.0.0.1:9222" },
|
|
680
|
+
"teams": { "base": "http://127.0.0.1:9333", "readOnly": true } } }
|
|
681
|
+
```
|
|
682
|
+
|
|
683
|
+
- **Selecting one:** prefix any target selector with `endpoint:<name>/`, e.g. `endpoint:teams/title:Chat` or `endpoint:teams/<targetId>`. `endpoint:teams` alone means that endpoint's active page. No prefix means the default endpoint. Tools without a `target` (`new_page`, `list_pages`) take an `endpoint` argument instead; giving both, naming different endpoints, is an error.
|
|
684
|
+
- **Discovery:** `list_pages { endpoint: "teams" }` lists one endpoint; `list_pages { allEndpoints: true }` lists all of them, tags each page row with `endpoint`, and adds an `endpoints` array where an unreachable endpoint shows as `{ endpoint, down: true, error }` instead of failing the call. Every row from a non-default endpoint carries `endpoint`.
|
|
685
|
+
- **App endpoints** often list an empty host page first (the Teams app's first `page` target has 3 accessibility nodes); the real window is the page whose title names it, so use `title:`.
|
|
686
|
+
- **The default endpoint** is the file's `"default"` key if set, else the endpoint named `default`. `CDP_BASE` is the endpoint named `default`; with neither it is `http://127.0.0.1:9222`. With only `CDP_BASE` (or nothing) set, behavior is exactly what it was before named endpoints.
|
|
687
|
+
- **Precedence:** `CDP_ENDPOINTS` and the file are merged, not shadowed: a name defined in both must be defined identically, or startup fails naming it. Listing order is env string, then file.
|
|
688
|
+
- **Errors:** a bad URL, duplicate name, unknown `mode` (only `read` / `write`), unknown key, or an unreadable or invalid file is a startup error for the MCP server (it prints the problem and exits 1) and a first-use error for the CLI. Names are letters, digits and `_`.
|
|
689
|
+
- **Late starters:** endpoints are tried on every call, never at startup, so an app launched after the server is reachable as soon as it is up.
|
|
690
|
+
- **Leases and origins** are kept per endpoint: the default endpoint's files keep their names (`lease-chrome-<id>.json`), a named one gets `lease-chrome@<name>-<id>.json`, and reap only ever compares an endpoint's leases against that endpoint's own live targets. An endpoint whose base equals the default's shares the default's lease space (two names, one browser).
|
|
691
|
+
- **Lease tokens carry their endpoint.** A token minted on a named endpoint starts `chrome@<name>:`, so `release_page { lease }` (or any call that passes only a `lease`) acts on that endpoint with no prefix needed. A prefix or `endpoint` argument that names a different endpoint than the token is an error.
|
|
692
|
+
|
|
693
|
+
### Read-only endpoints
|
|
694
|
+
|
|
695
|
+
Mark an endpoint read-only with `?mode=read` in `CDP_ENDPOINTS`, or `"readOnly": true` (or `"mode": "read"`) in the file. On a read-only endpoint, every tool that can change page or browser state is refused **before any HTTP request or CDP message is sent**, with an error naming the tool and the endpoint:
|
|
696
|
+
|
|
697
|
+
```
|
|
698
|
+
Error: 'click' is not allowed on endpoint 'teams': the endpoint is read-only (tools that change state are refused before any CDP message is sent)
|
|
699
|
+
```
|
|
700
|
+
|
|
701
|
+
The classes live in `src/policy.ts`, and a test fails if a new tool is added without being classified. A tool that is in neither class is refused (default-deny).
|
|
702
|
+
|
|
703
|
+
| Class | Tools |
|
|
704
|
+
|---|---|
|
|
705
|
+
| **Read** (allowed) | `list_pages`, `list_leases`, `take_snapshot`, `take_screenshot`, `wait_for`, `evaluate_script`, `extract_page`, `list_cookies`, `list_console_messages`, `get_console_message`, `list_network_requests`, `get_network_request`, `performance_analyze_insight`, `take_heapsnapshot`, `list_mocks` |
|
|
706
|
+
| **Mutating** (refused) | everything else: clicks, typing, fill, drag, scroll, hover, navigation, new/close/select page, emulation and resize, dialogs, cookie writes, uploads, downloads, permissions, mocks, traces, recording, Lighthouse, `claim_page` / `release_page` |
|
|
707
|
+
|
|
708
|
+
- **Argument escalation.** Some read tools change state with certain arguments, and those calls are refused too: `take_screenshot` with `renderWidth`/`renderHeight` (applies a device-metrics override), `list_console_messages` / `list_network_requests` with `reload: true`, and `get_network_request` with `includeBody` plus `url` (drives a reload capture).
|
|
709
|
+
- **`evaluate_script` is allowed.** This is a deliberate choice: the script can do anything, and the agent is responsible for running only reads on a read-only endpoint. Use it to read app state that the accessibility tree misses.
|
|
710
|
+
- **No reap.** Under `CDP_REQUIRE_LEASE`, `list_pages` and `list_leases` normally close abandoned agent tabs. On a read-only endpoint that reap is skipped entirely, so those reads never close a tab there.
|
|
711
|
+
- **`call_tool` is checked too.** `call_tool { name: "click", arguments: { target: "endpoint:teams/..." } }` is refused exactly like a direct `click`.
|
|
712
|
+
- **`tools/list` hints.** Every listed tool carries `annotations.readOnlyHint`, `true` exactly for the read class, so a client can tell which tools a read-only endpoint will accept.
|
|
713
|
+
- The CLI enforces the same policy: a refused call prints `{"error": ...}` and exits 1.
|
|
714
|
+
|
|
715
|
+
### Example: the Microsoft Teams desktop app, read-only
|
|
716
|
+
|
|
717
|
+
The macOS Teams app is built on Edge WebView2 and opens a DevTools port when launched with an extra browser argument. Quit Teams fully first, then:
|
|
718
|
+
|
|
719
|
+
```bash
|
|
720
|
+
open -a "Microsoft Teams" --env WEBVIEW2_ADDITIONAL_BROWSER_ARGUMENTS=--remote-debugging-port=9333
|
|
721
|
+
curl -s http://127.0.0.1:9333/json/version # reports an Edg/ browser
|
|
722
|
+
```
|
|
723
|
+
|
|
724
|
+
Configure it next to your browser, read-only:
|
|
725
|
+
|
|
726
|
+
```bash
|
|
727
|
+
CDP_ENDPOINTS="teams=http://127.0.0.1:9333?mode=read" # CDP_BASE (or 9222) stays the default
|
|
728
|
+
```
|
|
729
|
+
|
|
730
|
+
```json
|
|
731
|
+
{ "mcpServers": { "cdp-toolkit": {
|
|
732
|
+
"command": "npx", "args": ["-y", "cdp-toolkit"],
|
|
733
|
+
"env": { "CDP_ENDPOINTS": "teams=http://127.0.0.1:9333?mode=read" } } } }
|
|
734
|
+
```
|
|
735
|
+
|
|
736
|
+
Then read the open chat. The app's first page is an empty host page, so select the chat window by title:
|
|
737
|
+
|
|
738
|
+
```
|
|
739
|
+
list_pages { endpoint: "teams" }
|
|
740
|
+
take_snapshot { target: "endpoint:teams/title:Chat" }
|
|
741
|
+
take_screenshot { target: "endpoint:teams/title:Chat" }
|
|
742
|
+
click { target: "endpoint:teams/title:Chat", uid: "..." } # refused: read-only
|
|
743
|
+
```
|
|
744
|
+
|
|
745
|
+
If Teams is not running when the server starts, `teams` just shows as down in `list_pages { allEndpoints: true }` until you launch it; no restart needed.
|
|
746
|
+
|
|
664
747
|
## How it's built
|
|
665
748
|
|
|
666
749
|
```
|
package/dist/bidi/mux-daemon.js
CHANGED
|
@@ -10,11 +10,308 @@ var __esm = (fn, res, err) => () => {
|
|
|
10
10
|
return res;
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
// src/
|
|
13
|
+
// src/endpoints.ts
|
|
14
14
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
16
|
+
function checkName(name, where) {
|
|
17
|
+
if (!NAME_RE.test(name)) {
|
|
18
|
+
throw new EndpointConfigError(`${where}: endpoint name '${name}' is invalid; names are letters, digits and '_' only (no '-', '/', ':' or spaces)`);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function sameBase(a, b) {
|
|
22
|
+
return a.replace(/\/+$/, "") === b.replace(/\/+$/, "");
|
|
23
|
+
}
|
|
24
|
+
function parseBase(raw, where) {
|
|
25
|
+
let url;
|
|
26
|
+
try {
|
|
27
|
+
url = new URL(raw);
|
|
28
|
+
} catch {
|
|
29
|
+
throw new EndpointConfigError(`${where}: '${raw}' is not a valid URL (expected e.g. http://127.0.0.1:9222)`);
|
|
30
|
+
}
|
|
31
|
+
if (url.protocol !== "http:" && url.protocol !== "https:") {
|
|
32
|
+
throw new EndpointConfigError(`${where}: '${raw}' must be an http:// or https:// DevTools origin, not ${url.protocol}`);
|
|
33
|
+
}
|
|
34
|
+
if (url.hash)
|
|
35
|
+
throw new EndpointConfigError(`${where}: '${raw}' must not carry a #fragment`);
|
|
36
|
+
let mode;
|
|
37
|
+
for (const [key, value] of url.searchParams) {
|
|
38
|
+
if (key !== "mode") {
|
|
39
|
+
throw new EndpointConfigError(`${where}: unknown query parameter '${key}' in '${raw}' (only ?mode=read or ?mode=write is understood)`);
|
|
40
|
+
}
|
|
41
|
+
if (value !== "read" && value !== "write") {
|
|
42
|
+
throw new EndpointConfigError(`${where}: unknown mode '${value}' in '${raw}' (use mode=read or mode=write)`);
|
|
43
|
+
}
|
|
44
|
+
mode = value;
|
|
45
|
+
}
|
|
46
|
+
const path = url.pathname.replace(/\/+$/, "");
|
|
47
|
+
return { base: `${url.protocol}//${url.host}${path}`, mode };
|
|
48
|
+
}
|
|
49
|
+
function parseEnvString(spec) {
|
|
50
|
+
const out = [];
|
|
51
|
+
const seen = new Set;
|
|
52
|
+
for (const part of spec.split(",")) {
|
|
53
|
+
const entry = part.trim();
|
|
54
|
+
if (!entry)
|
|
55
|
+
continue;
|
|
56
|
+
const eq = entry.indexOf("=");
|
|
57
|
+
if (eq <= 0) {
|
|
58
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS: entry '${entry}' is not name=url (e.g. teams=http://127.0.0.1:9333)`);
|
|
59
|
+
}
|
|
60
|
+
const name = entry.slice(0, eq).trim();
|
|
61
|
+
checkName(name, "CDP_ENDPOINTS");
|
|
62
|
+
if (seen.has(name))
|
|
63
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS: duplicate endpoint name '${name}'`);
|
|
64
|
+
seen.add(name);
|
|
65
|
+
const { base, mode } = parseBase(entry.slice(eq + 1).trim(), `CDP_ENDPOINTS endpoint '${name}'`);
|
|
66
|
+
out.push({ name, base, readOnly: mode === "read" });
|
|
67
|
+
}
|
|
68
|
+
return out;
|
|
69
|
+
}
|
|
70
|
+
function parseFile(path) {
|
|
71
|
+
let text;
|
|
72
|
+
try {
|
|
73
|
+
text = readFileSync(path, "utf8");
|
|
74
|
+
} catch (err) {
|
|
75
|
+
const code = err.code ?? String(err);
|
|
76
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS_FILE: cannot read '${path}' (${code})`);
|
|
77
|
+
}
|
|
78
|
+
let json;
|
|
79
|
+
try {
|
|
80
|
+
json = JSON.parse(text);
|
|
81
|
+
} catch (err) {
|
|
82
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS_FILE: '${path}' is not valid JSON (${err instanceof Error ? err.message : String(err)})`);
|
|
83
|
+
}
|
|
84
|
+
const where = `CDP_ENDPOINTS_FILE '${path}'`;
|
|
85
|
+
if (!json || typeof json !== "object" || Array.isArray(json)) {
|
|
86
|
+
throw new EndpointConfigError(`${where}: top level must be an object {"default"?, "endpoints": {...}}`);
|
|
87
|
+
}
|
|
88
|
+
const top = json;
|
|
89
|
+
for (const key of Object.keys(top)) {
|
|
90
|
+
if (key !== "default" && key !== "endpoints")
|
|
91
|
+
throw new EndpointConfigError(`${where}: unknown top-level key '${key}'`);
|
|
92
|
+
}
|
|
93
|
+
if (top.default !== undefined && typeof top.default !== "string") {
|
|
94
|
+
throw new EndpointConfigError(`${where}: "default" must be an endpoint name string`);
|
|
95
|
+
}
|
|
96
|
+
const raw = top.endpoints ?? {};
|
|
97
|
+
if (!raw || typeof raw !== "object" || Array.isArray(raw)) {
|
|
98
|
+
throw new EndpointConfigError(`${where}: "endpoints" must be an object keyed by endpoint name`);
|
|
99
|
+
}
|
|
100
|
+
const endpoints = [];
|
|
101
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
102
|
+
checkName(name, where);
|
|
103
|
+
const at = `${where} endpoint '${name}'`;
|
|
104
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
105
|
+
throw new EndpointConfigError(`${at}: must be an object like {"base":"http://127.0.0.1:9333"}`);
|
|
106
|
+
}
|
|
107
|
+
const v = value;
|
|
108
|
+
for (const key of Object.keys(v)) {
|
|
109
|
+
if (key !== "base" && key !== "readOnly" && key !== "mode") {
|
|
110
|
+
throw new EndpointConfigError(`${at}: unknown key '${key}' (known: base, readOnly, mode)`);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
if (typeof v.base !== "string")
|
|
114
|
+
throw new EndpointConfigError(`${at}: "base" is required and must be a URL string`);
|
|
115
|
+
if (v.readOnly !== undefined && typeof v.readOnly !== "boolean")
|
|
116
|
+
throw new EndpointConfigError(`${at}: "readOnly" must be a boolean`);
|
|
117
|
+
if (v.mode !== undefined && v.mode !== "read" && v.mode !== "write") {
|
|
118
|
+
throw new EndpointConfigError(`${at}: unknown mode '${String(v.mode)}' (use "read" or "write")`);
|
|
119
|
+
}
|
|
120
|
+
const parsed = parseBase(v.base, at);
|
|
121
|
+
const votes = [parsed.mode, v.mode, v.readOnly === undefined ? undefined : v.readOnly ? "read" : "write"].filter((x) => x !== undefined);
|
|
122
|
+
if (new Set(votes).size > 1)
|
|
123
|
+
throw new EndpointConfigError(`${at}: readOnly / mode settings contradict each other`);
|
|
124
|
+
endpoints.push({ name, base: parsed.base, readOnly: votes[0] === "read" });
|
|
125
|
+
}
|
|
126
|
+
return { endpoints, defaultName: top.default };
|
|
127
|
+
}
|
|
128
|
+
function loadEndpoints(env = process.env) {
|
|
129
|
+
const fromEnv = env.CDP_ENDPOINTS !== undefined ? parseEnvString(env.CDP_ENDPOINTS) : [];
|
|
130
|
+
const file = env.CDP_ENDPOINTS_FILE ? parseFile(env.CDP_ENDPOINTS_FILE) : { endpoints: [], defaultName: undefined };
|
|
131
|
+
const merged = new Map;
|
|
132
|
+
for (const ep of fromEnv)
|
|
133
|
+
merged.set(ep.name, ep);
|
|
134
|
+
for (const ep of file.endpoints) {
|
|
135
|
+
const prior = merged.get(ep.name);
|
|
136
|
+
if (prior && (prior.base !== ep.base || prior.readOnly !== ep.readOnly)) {
|
|
137
|
+
throw new EndpointConfigError(`endpoint '${ep.name}' is defined differently in CDP_ENDPOINTS (${prior.base}${prior.readOnly ? " read-only" : ""}) and CDP_ENDPOINTS_FILE (${ep.base}${ep.readOnly ? " read-only" : ""})`);
|
|
138
|
+
}
|
|
139
|
+
if (!prior)
|
|
140
|
+
merged.set(ep.name, ep);
|
|
141
|
+
}
|
|
142
|
+
const cdpBase = env.CDP_BASE;
|
|
143
|
+
if (cdpBase !== undefined) {
|
|
144
|
+
const configured = merged.get("default");
|
|
145
|
+
if (configured && !sameBase(configured.base, cdpBase)) {
|
|
146
|
+
throw new EndpointConfigError(`CDP_BASE (${cdpBase}) and the configured endpoint 'default' (${configured.base}) disagree; drop one or make them match`);
|
|
147
|
+
}
|
|
148
|
+
merged.set("default", { name: "default", base: cdpBase, readOnly: configured?.readOnly ?? false });
|
|
149
|
+
}
|
|
150
|
+
const defaultName = file.defaultName ?? "default";
|
|
151
|
+
if (!merged.has(defaultName)) {
|
|
152
|
+
if (file.defaultName !== undefined) {
|
|
153
|
+
throw new EndpointConfigError(`CDP_ENDPOINTS_FILE names default endpoint '${file.defaultName}', which is not defined (known: ${[...merged.keys()].join(", ") || "none"})`);
|
|
154
|
+
}
|
|
155
|
+
merged.set("default", { name: "default", base: DEFAULT_CDP_BASE, readOnly: false });
|
|
156
|
+
}
|
|
157
|
+
const def = merged.get(defaultName);
|
|
158
|
+
const byName = new Map([[def.name, def]]);
|
|
159
|
+
for (const [name, ep] of merged)
|
|
160
|
+
if (name !== def.name)
|
|
161
|
+
byName.set(name, ep);
|
|
162
|
+
return { default: def, byName };
|
|
163
|
+
}
|
|
164
|
+
function signature(env) {
|
|
165
|
+
return JSON.stringify([env.CDP_BASE ?? null, env.CDP_ENDPOINTS ?? null, env.CDP_ENDPOINTS_FILE ?? null]);
|
|
166
|
+
}
|
|
167
|
+
function endpointConfig() {
|
|
168
|
+
const sig = signature(process.env);
|
|
169
|
+
if (cache?.sig === sig)
|
|
170
|
+
return cache.config;
|
|
171
|
+
const config = loadEndpoints(process.env);
|
|
172
|
+
cache = { sig, config };
|
|
173
|
+
return config;
|
|
174
|
+
}
|
|
175
|
+
function defaultEndpoint() {
|
|
176
|
+
return endpointConfig().default;
|
|
177
|
+
}
|
|
178
|
+
function allEndpoints() {
|
|
179
|
+
return [...endpointConfig().byName.values()];
|
|
180
|
+
}
|
|
181
|
+
function getEndpoint(name) {
|
|
182
|
+
const { byName } = endpointConfig();
|
|
183
|
+
const ep = byName.get(name);
|
|
184
|
+
if (!ep) {
|
|
185
|
+
throw new EndpointConfigError(`unknown endpoint '${name}' (known: ${[...byName.keys()].join(", ")}). Configure it with CDP_ENDPOINTS or CDP_ENDPOINTS_FILE.`);
|
|
186
|
+
}
|
|
187
|
+
return ep;
|
|
188
|
+
}
|
|
189
|
+
function leaseNamespace(ep) {
|
|
190
|
+
const { default: def, byName } = endpointConfig();
|
|
191
|
+
if (sameBase(ep.base, def.base))
|
|
192
|
+
return;
|
|
193
|
+
for (const other of byName.values())
|
|
194
|
+
if (sameBase(other.base, ep.base))
|
|
195
|
+
return other.name;
|
|
196
|
+
return ep.name;
|
|
197
|
+
}
|
|
198
|
+
function hasEndpointPrefix(target) {
|
|
199
|
+
return typeof target === "string" && target.startsWith(ENDPOINT_PREFIX);
|
|
200
|
+
}
|
|
201
|
+
function splitEndpointSelector(target) {
|
|
202
|
+
if (!hasEndpointPrefix(target))
|
|
203
|
+
return { endpoint: defaultEndpoint(), rest: target };
|
|
204
|
+
const body = target.slice(ENDPOINT_PREFIX.length);
|
|
205
|
+
const slash = body.indexOf("/");
|
|
206
|
+
const name = slash < 0 ? body : body.slice(0, slash);
|
|
207
|
+
if (!name)
|
|
208
|
+
throw new EndpointConfigError(`selector '${target}' has an empty endpoint name; use endpoint:<name>/<selector>`);
|
|
209
|
+
const rest = slash < 0 ? undefined : body.slice(slash + 1);
|
|
210
|
+
return { endpoint: getEndpoint(name), rest: rest === "" ? undefined : rest };
|
|
211
|
+
}
|
|
212
|
+
function usesEndpointArgs(args) {
|
|
213
|
+
if (!args || typeof args !== "object")
|
|
214
|
+
return false;
|
|
215
|
+
const a = args;
|
|
216
|
+
return SELECTOR_KEYS.some((k) => hasEndpointPrefix(a[k])) || a.endpoint !== undefined || a.allEndpoints === true;
|
|
217
|
+
}
|
|
218
|
+
function stripEndpointArgs(args) {
|
|
219
|
+
if (!args || typeof args !== "object" || Array.isArray(args))
|
|
220
|
+
return { endpoint: defaultEndpoint(), args };
|
|
221
|
+
const a = args;
|
|
222
|
+
const picks = [];
|
|
223
|
+
let out;
|
|
224
|
+
for (const key of SELECTOR_KEYS) {
|
|
225
|
+
const v = a[key];
|
|
226
|
+
if (!hasEndpointPrefix(v))
|
|
227
|
+
continue;
|
|
228
|
+
const { endpoint, rest } = splitEndpointSelector(v);
|
|
229
|
+
picks.push({ from: `${key} '${v}'`, endpoint });
|
|
230
|
+
out ??= { ...a };
|
|
231
|
+
if (rest === undefined)
|
|
232
|
+
delete out[key];
|
|
233
|
+
else
|
|
234
|
+
out[key] = rest;
|
|
235
|
+
}
|
|
236
|
+
if (a.endpoint !== undefined) {
|
|
237
|
+
if (typeof a.endpoint !== "string" || a.endpoint === "") {
|
|
238
|
+
throw new EndpointConfigError("`endpoint` must be a non-empty endpoint name string");
|
|
239
|
+
}
|
|
240
|
+
picks.push({ from: `endpoint '${a.endpoint}'`, endpoint: getEndpoint(a.endpoint) });
|
|
241
|
+
out ??= { ...a };
|
|
242
|
+
delete out.endpoint;
|
|
243
|
+
}
|
|
244
|
+
const token = leaseTokenNamespace(a.lease);
|
|
245
|
+
if (!picks.length) {
|
|
246
|
+
if (token?.ns === undefined)
|
|
247
|
+
return { endpoint: defaultEndpoint(), args };
|
|
248
|
+
return { endpoint: endpointForNamespace(token.ns), args };
|
|
249
|
+
}
|
|
250
|
+
const first = picks[0];
|
|
251
|
+
for (const p of picks.slice(1)) {
|
|
252
|
+
if (p.endpoint.name !== first.endpoint.name) {
|
|
253
|
+
throw new EndpointConfigError(`conflicting endpoints: ${first.from} vs ${p.from}; name one endpoint per call`);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
if (token && leaseNamespace(first.endpoint) !== token.ns) {
|
|
257
|
+
throw new EndpointConfigError(`conflicting endpoints: ${first.from} vs the lease token, which belongs to ${token.ns === undefined ? "the default endpoint" : `endpoint '${token.ns}'`}; name one endpoint per call`);
|
|
258
|
+
}
|
|
259
|
+
return { endpoint: first.endpoint, args: out ?? a };
|
|
260
|
+
}
|
|
261
|
+
function leaseTokenNamespace(lease) {
|
|
262
|
+
if (typeof lease !== "string")
|
|
263
|
+
return null;
|
|
264
|
+
const colon = lease.indexOf(":");
|
|
265
|
+
if (colon <= 0)
|
|
266
|
+
return null;
|
|
267
|
+
const head = lease.slice(0, colon);
|
|
268
|
+
if (head === "chrome")
|
|
269
|
+
return { ns: undefined };
|
|
270
|
+
if (!head.startsWith("chrome@"))
|
|
271
|
+
return null;
|
|
272
|
+
const ns = head.slice("chrome@".length);
|
|
273
|
+
return NAME_RE.test(ns) ? { ns } : null;
|
|
274
|
+
}
|
|
275
|
+
function endpointForNamespace(ns) {
|
|
276
|
+
for (const ep of endpointConfig().byName.values())
|
|
277
|
+
if (leaseNamespace(ep) === ns)
|
|
278
|
+
return ep;
|
|
279
|
+
throw new EndpointConfigError(`the lease token belongs to endpoint '${ns}', which is not configured (known: ${[...endpointConfig().byName.keys()].join(", ")})`);
|
|
280
|
+
}
|
|
281
|
+
function currentEndpoint() {
|
|
282
|
+
return endpointScope.getStore() ?? defaultEndpoint();
|
|
283
|
+
}
|
|
284
|
+
function isDefaultEndpoint(ep) {
|
|
285
|
+
return ep.name === defaultEndpoint().name;
|
|
286
|
+
}
|
|
287
|
+
function withEndpointScope(ep, fn) {
|
|
288
|
+
return endpointScope.run(ep, fn);
|
|
289
|
+
}
|
|
290
|
+
var EndpointConfigError, DEFAULT_CDP_BASE = "http://127.0.0.1:9222", ENDPOINT_PREFIX = "endpoint:", NAME_RE, cache, SELECTOR_KEYS, ENDPOINTS_FIREFOX_MESSAGE = "named CDP endpoints (an 'endpoint:<name>/' selector prefix, the endpoint arg, list_pages allEndpoints) need the Chrome backend; the Firefox BiDi backend has one session and no endpoints", endpointScope;
|
|
291
|
+
var init_endpoints = __esm(() => {
|
|
292
|
+
EndpointConfigError = class EndpointConfigError extends Error {
|
|
293
|
+
constructor(message) {
|
|
294
|
+
super(message);
|
|
295
|
+
this.name = "EndpointConfigError";
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
NAME_RE = /^[A-Za-z0-9_]+$/;
|
|
299
|
+
SELECTOR_KEYS = ["target", "targetId"];
|
|
300
|
+
endpointScope = new AsyncLocalStorage;
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
// src/leases.ts
|
|
304
|
+
import { AsyncLocalStorage as AsyncLocalStorage2 } from "node:async_hooks";
|
|
15
305
|
import { randomBytes } from "node:crypto";
|
|
16
306
|
import { mkdir, readFile, readdir, unlink, writeFile } from "node:fs/promises";
|
|
17
307
|
import { join } from "node:path";
|
|
308
|
+
function chromeLeaseBackend(ep = currentEndpoint()) {
|
|
309
|
+
const ns = leaseNamespace(ep);
|
|
310
|
+
return ns === undefined ? "chrome" : `chrome@${ns}`;
|
|
311
|
+
}
|
|
312
|
+
function isLeaseBackend(value) {
|
|
313
|
+
return BACKEND_KEY_RE.test(value);
|
|
314
|
+
}
|
|
18
315
|
function leaseDir() {
|
|
19
316
|
return process.env.CDP_ARTIFACT_DIR ?? "/tmp/cdp-toolkit";
|
|
20
317
|
}
|
|
@@ -51,7 +348,7 @@ function tokenParts(token) {
|
|
|
51
348
|
if (first <= 0 || last <= first)
|
|
52
349
|
return;
|
|
53
350
|
const backend = token.slice(0, first);
|
|
54
|
-
if (backend
|
|
351
|
+
if (!isLeaseBackend(backend))
|
|
55
352
|
return;
|
|
56
353
|
const targetId = token.slice(first + 1, last);
|
|
57
354
|
const nonce = token.slice(last + 1);
|
|
@@ -272,8 +569,10 @@ async function listLeases(opts = {}) {
|
|
|
272
569
|
}
|
|
273
570
|
return out;
|
|
274
571
|
}
|
|
275
|
-
var DEFAULT_LEASE_TTL_MS = 900000, longLived = false, LeaseConflictError, leaseScope, LEASE_FILE_RE;
|
|
572
|
+
var BACKEND_KEY_SOURCE = "chrome@[A-Za-z0-9_]+|chrome|firefox", BACKEND_KEY_RE, DEFAULT_LEASE_TTL_MS = 900000, longLived = false, LeaseConflictError, leaseScope, LEASE_FILE_RE;
|
|
276
573
|
var init_leases = __esm(() => {
|
|
574
|
+
init_endpoints();
|
|
575
|
+
BACKEND_KEY_RE = new RegExp(`^(?:${BACKEND_KEY_SOURCE})$`);
|
|
277
576
|
LeaseConflictError = class LeaseConflictError extends Error {
|
|
278
577
|
targetId;
|
|
279
578
|
holder;
|
|
@@ -284,8 +583,8 @@ var init_leases = __esm(() => {
|
|
|
284
583
|
this.name = "LeaseConflictError";
|
|
285
584
|
}
|
|
286
585
|
};
|
|
287
|
-
leaseScope = new
|
|
288
|
-
LEASE_FILE_RE =
|
|
586
|
+
leaseScope = new AsyncLocalStorage2;
|
|
587
|
+
LEASE_FILE_RE = new RegExp(`^lease-(${BACKEND_KEY_SOURCE})-(.+)\\.json$`);
|
|
289
588
|
});
|
|
290
589
|
|
|
291
590
|
// src/bidi/session-lease.ts
|
|
@@ -632,7 +931,7 @@ async function resolveLiveLabel(backend, label, liveIds) {
|
|
|
632
931
|
var ORIGIN_FILE_RE;
|
|
633
932
|
var init_origins = __esm(() => {
|
|
634
933
|
init_leases();
|
|
635
|
-
ORIGIN_FILE_RE =
|
|
934
|
+
ORIGIN_FILE_RE = new RegExp(`^origin-(${BACKEND_KEY_SOURCE})-(.+)\\.json$`);
|
|
636
935
|
});
|
|
637
936
|
|
|
638
937
|
// src/workers.ts
|
|
@@ -2087,7 +2386,7 @@ class CdpConnection {
|
|
|
2087
2386
|
}
|
|
2088
2387
|
}
|
|
2089
2388
|
async function httpJson(path) {
|
|
2090
|
-
const res = await fetch(`${
|
|
2389
|
+
const res = await fetch(`${currentEndpoint().base}${path}`);
|
|
2091
2390
|
if (!res.ok)
|
|
2092
2391
|
throw new CdpError(`${path} -> HTTP ${res.status}`);
|
|
2093
2392
|
return await res.json();
|
|
@@ -2104,7 +2403,7 @@ async function resolveTarget(selector, opts = {}) {
|
|
|
2104
2403
|
const hit = await pickTarget(targets, selector);
|
|
2105
2404
|
if (isWorkerTargetType(hit.type))
|
|
2106
2405
|
return hit;
|
|
2107
|
-
await assertLeaseOk(
|
|
2406
|
+
await assertLeaseOk(chromeLeaseBackend(), hit.id, { lease: opts.lease, url: hit.url, title: hit.title });
|
|
2108
2407
|
return hit;
|
|
2109
2408
|
}
|
|
2110
2409
|
async function pickTarget(targets, selector) {
|
|
@@ -2136,7 +2435,7 @@ async function pickTarget(targets, selector) {
|
|
|
2136
2435
|
}
|
|
2137
2436
|
if (selector.startsWith("label:")) {
|
|
2138
2437
|
const label = selector.slice(6);
|
|
2139
|
-
const { matchIds, knownLabels } = await resolveLiveLabel(
|
|
2438
|
+
const { matchIds, knownLabels } = await resolveLiveLabel(chromeLeaseBackend(), label, pages.map((t) => t.id));
|
|
2140
2439
|
if (matchIds.length > 1) {
|
|
2141
2440
|
throw new CdpError(`label 'label:${label}' matches more than one live target: ${matchIds.join(", ")}. Resolve by target id instead.`);
|
|
2142
2441
|
}
|
|
@@ -2194,9 +2493,16 @@ var BASE, DEFAULT_TIMEOUT_MS3, CdpError;
|
|
|
2194
2493
|
var init_client2 = __esm(() => {
|
|
2195
2494
|
init_leases();
|
|
2196
2495
|
init_origins();
|
|
2496
|
+
init_endpoints();
|
|
2197
2497
|
init_workers();
|
|
2198
2498
|
init_frames();
|
|
2199
|
-
BASE =
|
|
2499
|
+
BASE = (() => {
|
|
2500
|
+
try {
|
|
2501
|
+
return defaultEndpoint().base;
|
|
2502
|
+
} catch {
|
|
2503
|
+
return process.env.CDP_BASE ?? DEFAULT_CDP_BASE;
|
|
2504
|
+
}
|
|
2505
|
+
})();
|
|
2200
2506
|
DEFAULT_TIMEOUT_MS3 = Number(process.env.CDP_TIMEOUT_MS ?? 15000);
|
|
2201
2507
|
CdpError = class CdpError extends Error {
|
|
2202
2508
|
code;
|