dsh-web-fetch-playwright 0.2.13 → 0.2.15

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/README.md CHANGED
@@ -12,7 +12,7 @@ A [DeepSeek Harness](https://github.com/deepseek-ai/deepseek-harness) (DSH) plug
12
12
  - **Denoise pipeline** — Mozilla Readability extracts the article, DOMPurify removes layout/noise tags (nav, sidebar, footer, ads, forms), and Turndown with the GFM plugin converts to Markdown with the same style options as the shipped `tool-web` renderer. Inline `data:` images (build tools like Docusaurus embed screenshots as base64) are elided to size placeholders such as `![alt](data:image/png;base64,...8.9KB)` so they cannot flood the body.
13
13
  - **Two backends** — launch a local Playwright browser, or drive an already-running browser over its DevTools Protocol (CDP) endpoint.
14
14
  - **Browser resolution** — a configured path, a `playwright` CLI on `$PATH`, or the bundled `playwright-core`; CDP needs no local browser at all.
15
- - **Isolated or profile sessions (CDP)** — every fetch is scoped to exactly one tab. Local launches close their browser per fetch; the CDP backend keeps **one shared connection** to the remote browser and each fetch opens a tab inside it, closed when done. By default that tab lives in the remote browser's **real profile** (its cookies, localStorage, and persistent logins apply — like `playwright-cli open`); unchecking *Share the browser context* switches to a throwaway isolated context per fetch.
15
+ - **Shared profile or reusable isolation (CDP)** — each fetch opens and closes its own tab; session isolation uses a dedicated CDP connection per DSH session, while global/profile modes share one connection. By default it uses the browser's existing default context and logins (`connectOverCDP` → `browser.contexts()[0]`, like CLI CDP attach with isolation disabled, not `playwright-cli open`). Session isolation creates an in-memory context on demand and shares it only while same-session fetches or other tabs keep it in use; global isolation retains one fixed isolated context across all sessions within the same plugin instance. Local launches still close their browser per fetch.
16
16
  - **Live configuration** — the Plugins page (侧边栏 → 插件 → *dsh-web-fetch-playwright*, dsh ≥ 0.1.7) shows the full form right on the plugin's package page (and on the row's own page via its configure control); it edits the backend, context mode, denoise toggle, and concurrency, and a committed change reaches the next fetch without a restart.
17
17
  - **Budget-aware** — per-fetch deadline (45s); concurrency is backend-priced (`maxConcurrency`, default 4 local browsers / **50 CDP tabs**; queued fetches fail fast with a retry hint after 20s instead of hanging); image/font/media subrequests aborted; body capped at 100k chars.
18
18
  - **Bounded Cloudflare-challenge wait** — when a navigation lands on a challenge interstitial ("Just a moment…" and its localized siblings, recognized via the documented `cf-mitigated: challenge` response header plus structural page markers), the fetch keeps the **same tab and context** and waits for the browser's own verification to clear it — tracking the *last* main-frame response (the real page reloads in) and watching the live DOM so SPA-style clears are caught too. Bounded and configurable (`challengeWaitMs`, default 15s; 0 restores the legacy first-response behavior), with a bounded same-tab retry (`challengeRetries`, default 1). When the budget runs out, the fetch fails with the distinct `WEB_FETCH_CHALLENGE` error code instead of returning the interstitial as content. It never clicks, never injects CAPTCHA answers, never fakes browser state, and never exports or copies cookies.
@@ -29,13 +29,15 @@ web_fetch (tool-web)
29
29
  └─ ctx.web.fetchProvider = playwright
30
30
  ├─ local: resolve (path → $PATH → bundled playwright-core) → chromium.launch
31
31
  ├─ cdp: connectOverCDP(endpoint)
32
- ├─ page.goto → settle (networkidle, best-effort) → page.content()
32
+ ├─ page.goto → settle (networkidle, best-effort) → strip scripting subtrees in the live DOM → page.content()
33
33
  ├─ denoise: jsdom → elide data-URI images → Readability → DOMPurify → Turndown(GFM)
34
34
  └─ Markdown (or raw HTML when denoise is off)
35
35
  ```
36
36
 
37
37
  **Non-2xx statuses are results, not errors** — the web seam's contract (`@deepseek-ai/dsh-web`): a fetched 404/418/500 comes back with its status code, exactly what `dsh-web-fetch-http` does. Chromium complicates this for *status-only* responses — an error status with an empty body (httpbin's `/status/404`) fails the whole navigation with `net::ERR_HTTP_RESPONSE_CODE_FAILURE`, and a 204/205 is aborted (`net::ERR_ABORTED`) because nothing is renderable. The provider therefore tracks the last main-frame response on every fetch (that response arrives before Chromium fails the navigation) and recovers such failures into the status-bearing result, so `web_fetch` reports `Fetched … (HTTP 404)` instead of a `WEB_PROVIDER_ERROR` throw. The same recovery covers *download* responses — a body served with `Content-Disposition: attachment` (publish.twitter.com's oembed endpoint, the URL agents use to read a tweet, serves its JSON exactly that way) never commits a document: `goto` rejects with `Download is starting` and the body is gone from the network stack, so the provider refetches it through the page's API request context and returns the decodable content; undecodable downloads (a PDF, a ZIP) still fail with `WEB_UNSUPPORTED_CONTENT_TYPE`. A recovered response that is itself a Cloudflare challenge edge still fails with `WEB_FETCH_CHALLENGE`; transport errors and cancellations stay errors.
38
38
 
39
+ **Non-content scripting subtrees are removed in the live DOM before the document is read back — output-neutral by construction.** The denoise pipeline (and the tool layer's own renderer on the raw-HTML path) re-parses `page.content()` with jsdom, and a script's *text* is the one thing that round-trip cannot trust: a page's runtime JS may rewrite a data script's text with a literal `</script>` embedded — measured on techcommunity.microsoft.com (Khoros/Aurora), whose client writes its whole Apollo cache back into `script#__NEXT_DATA__` via `JSON.stringify`, un-escaping the wire's 712 `\u003c` sequences into raw `<` — and browsers serialize script text verbatim, so the flattened HTML string ends that script at the *first* embedded end tag and parses the remaining ~270KB of JSON *as markup*. The phantom elements that survive (unknown tags like `<id>`, anchors full of CSS and i18n strings) are exactly what Readability's scorer reads as article mass (measured: 126 points vs the real body's 45), so the badcase fetch of the RDP 10 AVC/H.264 article returned CSS rules and `CachedAsset` strings instead of the post. No string-level patch can disambiguate that serialization after the fact — only the browser's own parse holds the document's true structure — so ordinary `script` and `template` subtrees are stripped inside the live page (`page.evaluate`, best-effort) before `page.content()`. This changes nothing the pipeline ever returned: Readability deletes script/noscript nodes before extraction and scoring anyway, DOMPurify's allowlist drops script, and the tool layer's renderer removes SCRIPT/TEMPLATE wholesale — differential A/B over a real-page corpus (Wikipedia, MDN, Hacker News, the badcase page's wire HTML, plus noscript/JSON-LD/template edge cases) came back **byte-identical on every page**. Two deliberate carve-outs keep even the indirect consumers intact: `script[type="application/ld+json"]` is *defused* rather than deleted (`</` rewritten to `<\/` — still valid JSON, so Readability's metadata pass reads the same object and keeps the site-suffix-free article title, e.g. "Remote Desktop Protocol" instead of "… - Wikipedia"), and `noscript` is kept entirely because Readability's `_unwrapNoscriptImages` salvages the real image out of lazy-load `<noscript><img …>` wrappers. The strip also applies with `denoise` off, keeps the raw HTML serialization-safe for the tool layer's renderer, and shrinks what the pipeline parses (~70% on the badcase page).
40
+
39
41
  ## Requirements
40
42
 
41
43
  - DSH web profile (`dsh web`), Node.js ≥ 20.
@@ -71,7 +73,8 @@ The Plugins page (侧边栏 → 插件) opens the form one click from the list:
71
73
  | `backend` | `local` | Radio: *Local Playwright* or *Remote CDP endpoint*, each with its own nested input. |
72
74
  | `playwrightPath` | (blank) | Local backend: path to a `playwright` executable or a Chromium-family browser binary. Blank = discover on `$PATH`, then fall back to the bundled `playwright-core`. |
73
75
  | `cdpEndpoint` | `127.0.0.1:9222` | Remote backend: `host:port`, `http(s)://…` or `ws(s)://…`. |
74
- | `shareBrowserContext` | `true` | CDP backend only. **Checked (profile mode)**: each fetch is a tab in the remote browser's default context — its real profile — so cookies/localStorage are shared and its persistent logins apply; only the tab closes when the fetch ends. **Unchecked (isolated mode)**: a fresh incognito-like context per fetch, nothing shared. Local backend ignores this field. |
76
+ | `shareBrowserContext` | `true` | CDP only: Share / Isolate radio. `true` uses the remote default context and logins; `false` uses a separate context with the lifecycle determined by the scope below. Ignored locally. |
77
+ | `contextIsolationScope` | `global` | CDP isolation only: `session` creates a context on demand per DSH session and closes it when no active/pending fetches or open tabs remain (next fetch starts fresh); `global` reuses one fixed isolated context across all DSH sessions within this plugin instance. |
75
78
  | `denoise` | `true` | Run the denoise pipeline; off returns the full rendered HTML for the tool layer to convert. |
76
79
  | `maxConcurrency` | *(auto)* | How many fetches may render at once (1–200). Blank = backend default: **4** for local (each slot launches a browser) / **50** for CDP (each slot is just a tab in the already-running remote browser). Beyond the limit, fetches wait briefly; if no slot frees within 20s they fail with `WEB_FETCH_TIMEOUT` and a hint to retry or raise this setting, rather than hanging until the tool budget aborts. |
77
80
  | `challengeWaitMs` | `15000` | Bounded wait (ms, 0–60000) for a Cloudflare challenge to clear naturally in the same tab. `0` disables the whole challenge path — the first response is returned as-is (the pre-0.2.5 behavior). |
@@ -89,7 +92,16 @@ CDP mode needs no local browser: the provider holds **one shared connection** fo
89
92
 
90
93
  ### The CDP context modes (share the browser's profile or not)
91
94
 
92
- With *Share the browser context* **checked** (default, profile mode), each fetch is a tab in the remote browser's default context — the real profile. Cookies and localStorage come from and are written back to that profile, so sites the browser is logged into are fetched logged-in, exactly like a tab you open by hand. The shared context is never closed; resource filtering and popup guards attach to the fetch's tab only, so your other tabs are untouched. With it **unchecked** (isolated mode), every fetch gets a fresh incognito-like context — anonymous reads, nothing persists.
95
+ Choose **Share the browser context** (default) to open tabs in the remote browser's existing default context. Cookies and localStorage come from and are written back to that profile; the plugin never closes it. Resource filters and popup guards apply only to the fetch-owned tab.
96
+
97
+ Choose **Isolate from the browser profile**, then select:
98
+
99
+ - **Per DSH session**: create a dedicated CDP connection, isolated context and dedicated browser window on demand per DSH session ID. This also separates gateway implementations that map each connection's first context to a distinct Chromium process; different sessions never become nested contexts on one gateway connection. Concurrent fetches in the same session share that context/window in separate tabs; each fetch closes only its own tab. Context creation, tab creation, and tab-close/empty-check/context-close are serialized by a per-session FIFO mutex; fetching content stays concurrent and different sessions do not block each other. Once no fetch-owned or other open tabs remain, the context closes. A queued acquisition waits for that close before opening a fresh context. Cookies/localStorage reset after idle cleanup. The plugin verifies real CDP context and window IDs, matches newly created targets by ID, and fails explicitly if the endpoint cannot provide the isolation guarantees or the call lacks a session ID; it never falls back to the default profile.
100
+ - **Global reuse across DSH sessions** (default): all DSH sessions within this plugin instance reuse one fixed isolated context.
101
+
102
+ The plugin creates its own isolated contexts; it does not discover contexts created by other tools. Global isolation remains retained between fetches: completion closes only the fetch-owned tab, so cookies/localStorage survive subsequent fetches. Session isolation instead releases its context once no active/pending fetches or open tabs remain, as described above. This is in-memory reuse, not persistent storage across browser/plugin restarts; changing the context configuration retires old contexts, and teardown or connection loss/replacement discards them. Global isolation separates you from the browser profile, **not from other DSH sessions** within the same plugin instance.
103
+
104
+ If another CDP client deletes a plugin-owned isolated context, Chromium may not emit a Playwright context `close` event. On the explicit `Target.createTarget` “Failed to find browser context with id …” error, the plugin invalidates only that cached context and retries opening a tab once in a fresh context. Concurrent requests share the replacement; the deleted context's cookies/localStorage are lost. Other contexts and the default profile are untouched. Generic page errors are not retried by this recovery, and it never replays navigation or falls back to the default profile.
93
105
 
94
106
  **Profile-mode risk notes** — it upgrades `web_fetch` from "anonymous read" to "acts as the browser's logged-in user":
95
107
 
@@ -116,7 +128,7 @@ With the wait on (default):
116
128
  3. **Bounded retry** — when a window runs out, the same tab re-navigates once (default; `challengeRetries`) with whatever clearance cookies the context already holds.
117
129
  4. **Clear failure** — `WEB_FETCH_CHALLENGE` (a provider-specific code the web seam's open-string `code` allows) naming the site, the budget spent, and the last challenge status.
118
130
 
119
- Security boundary (deliberate): no clicking through Turnstile, no CAPTCHA solving or token injection, no fingerprint/UA spoofing, no proxy rotation, and no cookie export — in isolated mode the clearance a fetch's browser earns dies with that fetch's context; in profile mode it stays in the remote browser's own profile, which this plugin never copies or cleans. The wait is always bounded by `challengeWaitMs` and the 45s per-fetch deadline; nothing blocks forever.
131
+ Security boundary (deliberate): no clicking through Turnstile, no CAPTCHA solving or token injection, no fingerprint/UA spoofing, no proxy rotation, and no cookie export — in CDP isolated mode clearance remains within its session/global context until that context is discarded (local contexts still end with each fetch); in profile mode it stays in the remote browser's own profile, which this plugin never copies or cleans. The wait is always bounded by `challengeWaitMs` and the 45s per-fetch deadline; nothing blocks forever.
120
132
 
121
133
  ## Development
122
134
 
@@ -127,6 +139,20 @@ pnpm test # vitest run (browser smoke self-skips without a browser)
127
139
  pnpm build # tsc declarations + tsdown (host ESM + client module-registration bundle)
128
140
  ```
129
141
 
142
+ Run the real context/window isolation, cookie/localStorage separation, concurrent provider identity, create/close race, and external-context-deletion regressions (the tests launch their own browser and local server, never the configured user browser):
143
+
144
+ ```sh
145
+ PLAYWRIGHT_TEST_EXECUTABLE_PATH=/path/to/chromium pnpm exec vitest run tests/cdp-recovery.browser.spec.ts
146
+ ```
147
+
148
+ Without an override it uses Playwright's default executable and reports skipped tests when that binary is absent; an explicit invalid path or a launch failure fails the test. Set `PLAYWRIGHT_TEST_HEADED=1` with a working `DISPLAY` to verify real headed windows as well. A source build does not reload an already running DSH server: restart/reload the plugin host before judging the new behavior.
149
+
150
+ For an explicitly authorized connection-scoped gateway, run the opt-in regression below. It creates only test-owned contexts, fulfills a `.invalid` probe locally, checks cookies/localStorage and idle disconnect, then cleans up its resources. Numeric window IDs are process-local and may repeat across cloned Chromium processes; they must not be compared across gateway connections.
151
+
152
+ ```sh
153
+ PLAYWRIGHT_TEST_CDP_ENDPOINT=http://your-gateway:9222 pnpm exec vitest run tests/cdp-gateway.browser.spec.ts
154
+ ```
155
+
130
156
  Repository layout:
131
157
 
132
158
  ```
package/README.zh-CN.md CHANGED
@@ -12,7 +12,7 @@
12
12
  - **降噪管线** —— Mozilla Readability 提取正文,DOMPurify 移除布局/噪音标签(导航、侧边栏、页脚、广告、表单),Turndown + GFM 插件按与内置 `tool-web` 渲染器一致的风格转成 Markdown。内联 `data:` 图片(Docusaurus 等构建工具会把截图以 base64 内嵌进 HTML)会被替换为带大小的占位符,如 `![alt](data:image/png;base64,...8.9KB)`,避免 base64 字符流刷屏。
13
13
  - **两种后端** —— 本地启动 Playwright 浏览器,或通过 DevTools 协议(CDP)驱动一个已在运行的浏览器。
14
14
  - **浏览器解析** —— 配置路径 → `$PATH` 上的 `playwright` CLI → 插件自带的 `playwright-core`;CDP 模式完全不需要本地浏览器。
15
- - **共享或隔离会话(CDP)** —— 每次抓取严格限定为一个标签页。本地后端每次抓取启动并关闭自己的浏览器;CDP 后端对远端浏览器保持**一条共享连接**,每次抓取只在其里开一个标签页、用完即关。默认该标签页位于远端浏览器的**真实 profile**(沿用其 cookie、localStorage 与已登录会话,效果类似 `playwright-cli open`);取消勾选「共享浏览器上下文」则切换为每次抓取全新隔离 context。
15
+ - **共享 profile 或复用隔离上下文(CDP)** —— 每次抓取通过共享 CDP 连接创建自己的标签页,用完即关。默认复用浏览器已有默认 context 与登录态(`connectOverCDP` → `browser.contexts()[0]`,类似关闭隔离后的 CLI CDP attach,而不是 `playwright-cli open`)。会话隔离按需创建独立的内存 context,仅在同一会话的抓取或其他标签页仍在使用时复用;全局隔离则在同一插件实例内跨会话保留并复用一个固定的隔离 context。本地后端仍每次抓取启动并关闭浏览器。
16
16
  - **热配置** —— 插件页(侧边栏 → 插件 → *dsh-web-fetch-playwright*,dsh ≥ 0.1.7)在插件自己的包页面直接展示完整表单(也可通过该行的「配置」入口进入同一表单);可随时切换后端、上下文模式、降噪开关与并发数,提交的改动对下一次抓取即时生效,无需重启。
17
17
  - **预算控制** —— 单次抓取 45s 超时;并发按后端定价(`maxConcurrency`,默认本地 4 个浏览器 / **CDP 50 个标签页**;排队的抓取等不到空位会在 20s 内尽快报错并提示重试,而不是一直挂到被工具层中止);拦截图片/字体/媒体子请求;返回体 10 万字符封顶。
18
18
  - **Cloudflare 挑战有界等待** —— 导航落到验证中间页("Just a moment…" 及其多语言同族,通过官方 `cf-mitigated: challenge` 响应头 + 结构性页面标记识别)时,抓取保持**同一标签页与上下文**,等待浏览器自行通过验证:跟踪*最后一次*主 frame 响应(真实页面随后重载进来),并轮询活 DOM 以捕获 SPA 式清除。有界且可配置(`challengeWaitMs`,默认 15s;`0` 恢复旧版首响应行为),附带同标签页有界重试(`challengeRetries`,默认 1)。预算耗尽时以独立的 `WEB_FETCH_CHALLENGE` 错误码明确失败,而不是把中间页当正文返回。全程不点击、不注入验证码答案、不伪造浏览器状态、不导出或复制 cookie。
@@ -29,13 +29,15 @@ web_fetch (tool-web)
29
29
  └─ ctx.web.fetchProvider = playwright
30
30
  ├─ local: 解析(路径 → $PATH → 内置 playwright-core)→ chromium.launch
31
31
  ├─ cdp: connectOverCDP(endpoint)
32
- ├─ page.goto → 等待稳定(networkidle,尽力而为)→ page.content()
32
+ ├─ page.goto → 等待稳定(networkidle,尽力而为)→ 在活 DOM 中剥离脚本子树 → page.content()
33
33
  ├─ 降噪:jsdom → 内联 data: 图片改占位符 → Readability → DOMPurify → Turndown(GFM)
34
34
  └─ Markdown(关闭降噪时返回原始 HTML)
35
35
  ```
36
36
 
37
37
  **非 2xx 状态码是结果而非错误** —— 这是 web seam 的契约(`@deepseek-ai/dsh-web`):抓取到的 404/418/500 会连同状态码一起正常返回,与 `dsh-web-fetch-http` 的行为一致。但对*仅有状态*的响应 Chromium 会把事情搞砸 —— 空 body 的错误状态(httpbin 的 `/status/404`)会让整个导航以 `net::ERR_HTTP_RESPONSE_CODE_FAILURE` 失败,204/205 则因无可渲染内容被中止(`net::ERR_ABORTED`)。因此 provider 在每次抓取中都跟踪最后一个主框架响应(该响应先于 Chromium 判定导航失败到达),并把这类失败恢复成带状态码的正常结果,`web_fetch` 会报告 `Fetched … (HTTP 404)` 而不是抛出 `WEB_PROVIDER_ERROR`。同样的恢复也覆盖*下载型*响应 —— 带 `Content-Disposition: attachment` 的 body(publish.twitter.com 的 oembed 端点——agent 读取推文常用的替代 URL——返回的 JSON 正是如此)永远不会被提交为文档:`goto` 以 `Download is starting` 拒绝,且 body 已从网络栈中流失,provider 因此通过页面的 API request context 重新拉取并返回可解码内容;不可解码的下载(PDF、ZIP)仍以 `WEB_UNSUPPORTED_CONTENT_TYPE` 失败。若恢复出的响应本身来自 Cloudflare 挑战边缘,仍以 `WEB_FETCH_CHALLENGE` 失败;传输错误与取消也依旧按错误处理。
38
38
 
39
+ **回读文档前,先在活 DOM 中剥离非内容脚本子树 —— 构造上即输出中性。** 降噪管线(以及关闭降噪时工具层自己的渲染器)会用 jsdom 重新解析 `page.content()`,而脚本的*文本内容*是这条往返链路中唯一无法信任的东西:页面自身的运行时 JS 可能把内嵌 `</script>` 的文本写回某个数据脚本的 textContent —— 实测于 techcommunity.microsoft.com(Khoros/Aurora 平台),其客户端把整个 Apollo 缓存经 `JSON.stringify` 写回 `script#__NEXT_DATA__`,把线上响应里 712 处 `\u003c` 转义还原成了裸 `<` —— 而浏览器序列化脚本文本时原样输出,于是这份扁平化的 HTML 字符串会在*第一个*内嵌结束标签处终止脚本,把余下约 270KB 的 JSON *当作标记语言*解析。解析出的幽灵元素(`<id>` 之类的未知标签、塞满 CSS 与 i18n 字符串的锚点)恰好是 Readability 评分器眼里的"正文质量"(实测 126 分对真实正文的 45 分),于是抓取 RDP 10 AVC/H.264 一文时返回的是 CSS 规则和 `CachedAsset` 字符串而不是文章本体。事后再对字符串做补丁无法消除这种歧义 —— 只有浏览器自己的解析持有文档的真实结构 —— 因此普通的 `script` 与 `template` 子树在 `page.content()` 之前先在活页面里剥掉(`page.evaluate`,尽力而为)。这不会改变管线以往的任何输出:Readability 本就在抽取与评分前删除 script/noscript 节点,DOMPurify 的白名单本就丢弃 script,工具层渲染器也整体移除 SCRIPT/TEMPLATE —— 在真实页面语料(Wikipedia、MDN、Hacker News、坏例页 wire 版,加上 noscript/JSON-LD/template 边界用例)上的差分 A/B **每一页都字节级一致**。两个刻意的保留让间接消费方也不受损:`script[type="application/ld+json"]` 只做*消险*而非删除(`</` 改写为 `<\/` —— 仍是合法 JSON,Readability 的元数据读取解析到同一对象,文章标题保持无站点后缀的干净形态,如 "Remote Desktop Protocol" 而非 "… - Wikipedia");`noscript` 完整保留,因为 Readability 的 `_unwrapNoscriptImages` 会从懒加载的 `<noscript><img …>` 包裹中抢救出真实图片。该剥离在关闭降噪时同样生效,让返回给工具层渲染器的原始 HTML 也是序列化安全的,并把管线要解析的体积压缩约 70%(以该坏例页计)。
40
+
39
41
  ## 环境要求
40
42
 
41
43
  - DSH web profile(`dsh web`),Node.js ≥ 20。
@@ -71,7 +73,8 @@ bundle 插件加入 profile 层栈后需**重启 `dsh web`** 生效;卸载用
71
73
  | `backend` | `local` | radio:本地 Playwright / 远端 CDP 地址,每个选项内嵌各自的填空。 |
72
74
  | `playwrightPath` | 空 | 本地后端:`playwright` 可执行文件或 Chromium 系浏览器二进制路径;留空按 `$PATH` 查找,再回退到内置 `playwright-core`。 |
73
75
  | `cdpEndpoint` | `127.0.0.1:9222` | 远端后端:`host:port`、`http(s)://…` 或 `ws(s)://…`。 |
74
- | `shareBrowserContext` | `true` | 仅 CDP 后端。**勾选(profile 模式)**:每次抓取是远端浏览器默认 context(真实 profile)里的一个标签页,cookie/localStorage 与之互通、已登录会话直接生效,抓取结束只关标签页;**取消勾选(隔离模式)**:每次抓取使用全新隐身式 context,互不共享。本地后端忽略此字段。 |
76
+ | `shareBrowserContext` | `true` | 仅 CDP:单选共享 / 隔离。`true` 复用远端默认 context 与登录态;`false` 使用独立 context,生命周期由下方范围决定。本地后端忽略。 |
77
+ | `contextIsolationScope` | `global` | 仅 CDP 隔离模式:`session` 按 DSH 会话按需创建 context,无活动/待处理抓取且无打开的标签页后关闭(下次抓取使用全新状态);`global` 在同一插件实例内跨DSH会话复用一个固定的隔离上下文。 |
75
78
  | `denoise` | `true` | 是否启用降噪;关闭时返回整页渲染 HTML,交由工具层转换。 |
76
79
  | `maxConcurrency` | *(自动)* | 同时渲染的页面上限(1–200)。留空按后端取默认:本地 **4**(每个槽位启动一个浏览器)/ CDP **50**(远端浏览器已就位,每个槽位只是一个标签页)。超出的请求短暂排队;20s 内等不到空位则以 `WEB_FETCH_TIMEOUT` 尽快失败并提示重试或调大该值,而不是一直挂起直到工具层预算中止。 |
77
80
  | `challengeWaitMs` | `15000` | Cloudflare 挑战的**有界**自然等待上限(毫秒,0–60000),在同一标签页内等待浏览器自行通过验证。`0` 关闭整条挑战处理链路——直接返回首次响应(0.2.5 之前的旧行为)。 |
@@ -89,7 +92,16 @@ CDP 模式不需要本地浏览器:插件在生命周期内对远端浏览器
89
92
 
90
93
  ### CDP 上下文模式(是否共享浏览器 profile)
91
94
 
92
- 「共享浏览器上下文」**勾选**(默认,profile 模式)时,每次抓取是远端浏览器默认 context——真实 profile——里的一个标签页:cookie 与 localStorage 双向互通,浏览器里已登录的站点会以登录态被抓取,和你手动开标签页一样。共享 context 永不关闭;资源过滤与弹窗守卫只挂在本次抓取自己的标签页上,不会干扰你人工打开的其他标签页。**取消勾选**(隔离模式)时,每次抓取使用全新隐身式 context——匿名读取,什么都不保留。
95
+ 选择**共享浏览器上下文**(默认)时,在远端浏览器已有的默认 context 内开标签页,双向共享 cookie / localStorage 并复用登录态;插件永不关闭这个默认 context。资源过滤与弹窗守卫只作用于本次抓取自己的标签页。
96
+
97
+ 选择**隔离浏览器上下文**后,再选择复用范围:
98
+
99
+ - **按 DSH 会话隔离**:按 DSH 会话 ID 按需创建独立 CDP 连接、独立 context 和专属浏览器窗口。即便 CDP 网关把每条连接的第一个 context 映射为独立 Chromium,不同会话也不会落入同一连接下的嵌套 context;空闲回收时连同该会话的连接一起释放。同一会话的并发抓取在自己的 context/窗口内各开一个标签页,每次只关闭自己的标签页。创建 context、创建标签页,以及“关标签页→检查是否为空→关 context”都在同一把按会话键划分的 FIFO 锁内执行;网页抓取仍可并发,不同会话互不阻塞。没有抓取标签页或其他打开的标签页后关闭 context;排队的新建请求须等待关闭完成,再创建新的 context。回收后 cookie / localStorage 重置。实现校验真实 CDP context ID 和 window ID,按 target ID 匹配新页面;端点不支持这些隔离保证或调用缺少会话 ID 时明确失败,绝不回退到默认 profile。
100
+ - **跨DSH会话全局复用**(默认):本插件实例内所有 DSH 会话复用一个固定的隔离 context。
101
+
102
+ 插件自行创建隔离 context,不查找其他工具创建的 context。全局隔离仍在抓取之间保留 context:抓取结束仅关自己的标签页,因此后续抓取可沿用 cookie / localStorage。会话隔离则按上述规则,在没有活动/待处理抓取且没有打开的标签页后释放 context。这是内存复用,不保证浏览器或插件重启后保留;上下文配置变更会退役旧 context,卸载、断连或连接替换也会清理。全局隔离仅与浏览器 profile 隔离,**不隔离同一插件实例内的其他 DSH 会话**。
103
+
104
+ 如果其他 CDP 客户端删除了插件拥有的隔离 context,Chromium 不一定触发 Playwright 的 context `close` 事件。遇到明确的 `Target.createTarget` “Failed to find browser context with id …” 错误时,插件只让对应缓存失效,并在新的 context 中最多重试一次开标签页。并发请求复用同一个替代 context;被删除 context 的 cookie / localStorage 不会恢复。其他 context 与默认 profile 不受影响。该恢复机制不会重试普通页面错误、重放网页导航或回退到默认 profile。
93
105
 
94
106
  **profile 模式风险须知** —— 它把 `web_fetch` 从"匿名读网页"升级为"以浏览器登录身份行动":
95
107
 
@@ -116,7 +128,7 @@ google-chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.config/chrome
116
128
  3. **有界重试** —— 窗口耗尽后,同一标签页默认再导航一次(`challengeRetries`),上下文里已有的通关 cookie 继续生效。
117
129
  4. **明确失败** —— 返回独立的 `WEB_FETCH_CHALLENGE` 错误码(web seam 的 `code` 是开放字符串,允许 provider 专属码),消息中写明站点、等待预算与最后一次挑战响应的状态。
118
130
 
119
- 安全边界(刻意为之):不点击 Turnstile、不解验证码、不注入 token、不伪装指纹/UA、不轮换代理、不导出 cookie——隔离模式下本次抓取挣到的通关态随其 context 一起销毁;profile 模式下它留在远端浏览器自己的 profile 里,插件从不复制或清理。等待始终受 `challengeWaitMs` 与 45s 单次抓取预算双重约束,永不无限阻塞。
131
+ 安全边界(刻意为之):不点击 Turnstile、不解验证码、不注入 token、不伪装指纹/UA、不轮换代理、不导出 cookie——CDP 隔离模式下通关态保留在对应会话 / 全局 context 中,直到该 context 被清理(本地 context 仍随每次抓取结束);profile 模式下它留在远端浏览器自己的 profile 里,插件从不复制或清理。等待始终受 `challengeWaitMs` 与 45s 单次抓取预算双重约束,永不无限阻塞。
120
132
 
121
133
  ## 开发
122
134
 
@@ -127,6 +139,14 @@ pnpm test # vitest run(无浏览器时浏览器集成用例自动跳过
127
139
  pnpm build # tsc 声明 + tsdown(宿主 ESM + 客户端 module-registration bundle)
128
140
  ```
129
141
 
142
+ 用真实 Chromium 执行外部删除 context 的回归测试(测试自行启动浏览器和本地站点,不连接配置中的用户浏览器):
143
+
144
+ ```sh
145
+ PLAYWRIGHT_TEST_EXECUTABLE_PATH=/path/to/chromium pnpm exec vitest run tests/cdp-recovery.browser.spec.ts
146
+ ```
147
+
148
+ 未指定路径时使用 Playwright 默认浏览器;默认二进制不存在会明确报告跳过。显式路径错误或启动失败则使测试失败。
149
+
130
150
  仓库结构:
131
151
 
132
152
  ```
package/lib/client.js CHANGED
@@ -5,6 +5,7 @@ window.__ModuleLoader__.load({
5
5
  var exports = module.exports;
6
6
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
7
  let react_jsx_runtime = require("react/jsx-runtime");
8
+ let react = require("react");
8
9
  //#region \0@oxc-project+runtime@0.146.0/helpers/esm/typeof.js
9
10
  function _typeof(o) {
10
11
  "@babel/helpers - typeof";
@@ -367,6 +368,7 @@ window.__ModuleLoader__.load({
367
368
  textField("playwrightPath"),
368
369
  textField("cdpEndpoint"),
369
370
  checkboxField("shareBrowserContext"),
371
+ radioField("contextIsolationScope", ["session", "global"]),
370
372
  checkboxField("denoise"),
371
373
  numberField("maxConcurrency", 1, 200),
372
374
  numberField("challengeWaitMs", 0, 6e4)
@@ -380,6 +382,7 @@ window.__ModuleLoader__.load({
380
382
  playwrightPath: this.form.field("playwrightPath"),
381
383
  cdpEndpoint: this.form.field("cdpEndpoint"),
382
384
  shareBrowserContext: this.form.field("shareBrowserContext"),
385
+ contextIsolationScope: this.form.field("contextIsolationScope"),
383
386
  denoise: this.form.field("denoise"),
384
387
  maxConcurrency: this.form.field("maxConcurrency"),
385
388
  challengeWaitMs: this.form.field("challengeWaitMs")
@@ -412,12 +415,12 @@ window.__ModuleLoader__.load({
412
415
  document.head.appendChild(tag);
413
416
  }
414
417
  var PluginCard_module_css_default = {
415
- "failed": "UM8-Rq_failed",
416
418
  "footer": "UM8-Rq_footer",
417
- "discard": "UM8-Rq_discard",
418
- "save": "UM8-Rq_save",
419
419
  "form": "UM8-Rq_form",
420
- "readOnly": "UM8-Rq_readOnly"
420
+ "failed": "UM8-Rq_failed",
421
+ "save": "UM8-Rq_save",
422
+ "readOnly": "UM8-Rq_readOnly",
423
+ "discard": "UM8-Rq_discard"
421
424
  };
422
425
  //#endregion
423
426
  //#region src/client/PluginCard.tsx
@@ -467,7 +470,7 @@ window.__ModuleLoader__.load({
467
470
  }
468
471
  //#endregion
469
472
  //#region \0dsh-web-fetch-playwright-css:/opt/dsh/plugins/dsh-web-fetch-playwright/src/client/fields.module.css.mjs
470
- const css = ".CFSaVG_field{border:0;border-top:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:6px;margin:0;padding:12px 0;display:flex}.CFSaVG_field:first-child{border-top:0}.CFSaVG_fieldEmbedded{border:0;flex-direction:column;gap:6px;margin:0;padding:0;display:flex}.CFSaVG_head{align-items:center;gap:8px;display:flex}.CFSaVG_label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}.CFSaVG_badges{align-items:center;gap:8px;display:inline-flex}.CFSaVG_badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}.CFSaVG_reset{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;padding:0;font-size:12px;line-height:1.5}.CFSaVG_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}.CFSaVG_reset:disabled{cursor:default}.CFSaVG_input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}.CFSaVG_input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}.CFSaVG_input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}.CFSaVG_inputInvalid{border:1px solid var(--dsw-alias-label-error);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}.CFSaVG_invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}.CFSaVG_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}.CFSaVG_hintIndented{margin-left:26px}.CFSaVG_radioGroup{flex-direction:column;gap:8px;display:flex}.CFSaVG_radioOption{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:8px;flex-direction:column;gap:8px;padding:10px 12px;display:flex}.CFSaVG_radioOption:has(input[type=radio]:checked){border-color:var(--dsw-alias-brand-primary)}.CFSaVG_radioPick{cursor:pointer;align-items:flex-start;gap:10px;display:flex}.CFSaVG_radioPick input[type=radio]{width:14px;height:14px;accent-color:var(--dsw-alias-brand-primary);flex:none;margin-top:2px}.CFSaVG_radioPick input[type=radio]:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}.CFSaVG_radioText{flex-direction:column;gap:2px;min-width:0;display:flex}.CFSaVG_radioLabel{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:1.5}.CFSaVG_radioHint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1.5}.CFSaVG_radioContent{margin-left:24px}.CFSaVG_radioContent>*+*{margin-top:12px}.CFSaVG_radioContent input[type=text]:enabled{cursor:text}.CFSaVG_checkboxRow{align-items:center;gap:10px;display:flex}.CFSaVG_checkboxRow input[type=checkbox]{width:16px;height:16px;accent-color:var(--dsw-alias-brand-primary);flex:none;margin:0}.CFSaVG_checkboxRow input[type=checkbox]:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}";
473
+ const css = ".CFSaVG_field{border:0;border-top:1px solid var(--dsw-alias-border-l2);flex-direction:column;gap:6px;margin:0;padding:12px 0;display:flex}.CFSaVG_field:first-child{border-top:0}.CFSaVG_fieldEmbedded{border:0;flex-direction:column;gap:6px;margin:0;padding:0;display:flex}.CFSaVG_head{align-items:center;gap:8px;display:flex}.CFSaVG_label{min-width:0;color:var(--dsw-alias-label-primary);flex:1;font-size:13px;font-weight:500;line-height:1.5}.CFSaVG_badges{align-items:center;gap:8px;display:inline-flex}.CFSaVG_badge{white-space:nowrap;background:var(--dsw-alias-bg-module-platform);color:var(--dsw-alias-label-secondary);border-radius:999px;padding:1px 8px;font-size:11px;font-weight:500;line-height:17px}.CFSaVG_reset{font:inherit;color:var(--dsw-alias-label-secondary);cursor:pointer;background:0 0;border:none;padding:0;font-size:12px;line-height:1.5}.CFSaVG_reset:hover:not(:disabled){color:var(--dsw-alias-label-primary)}.CFSaVG_reset:disabled{cursor:default}.CFSaVG_input{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}.CFSaVG_input:focus-visible{border-color:var(--dsw-alias-brand-primary);outline:none}.CFSaVG_input:disabled{color:var(--dsw-alias-label-tertiary);cursor:default}.CFSaVG_inputInvalid{border:1px solid var(--dsw-alias-label-error);background:var(--dsw-alias-bg-layer-3);height:34px;font:inherit;color:var(--dsw-alias-label-primary);border-radius:8px;padding:0 12px;font-size:13px;line-height:1.5}.CFSaVG_invalid{color:var(--dsw-alias-label-error);margin:0;font-size:12px;line-height:1.5}.CFSaVG_hint{color:var(--dsw-alias-label-tertiary);margin:0;font-size:12px;line-height:1.5}.CFSaVG_hintIndented{margin-left:26px}.CFSaVG_radioGroup{flex-direction:column;gap:8px;display:flex}.CFSaVG_radioOption{border:1px solid var(--dsw-alias-border-l2);background:var(--dsw-alias-bg-layer-3);border-radius:8px;flex-direction:column;gap:8px;padding:10px 12px;display:flex}.CFSaVG_radioOptionPlain{background:0 0;border:0;flex-direction:column;gap:8px;padding:4px 0;display:flex}.CFSaVG_radioOption:has(>.CFSaVG_radioPick>input[type=radio]:checked){border-color:var(--dsw-alias-brand-primary)}.CFSaVG_radioPick{cursor:pointer;align-items:flex-start;gap:10px;display:flex}.CFSaVG_radioPick input[type=radio]{width:14px;height:14px;accent-color:var(--dsw-alias-brand-primary);flex:none;margin-top:2px}.CFSaVG_radioPick input[type=radio]:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}.CFSaVG_radioText{flex-direction:column;gap:2px;min-width:0;display:flex}.CFSaVG_radioLabel{color:var(--dsw-alias-label-primary);font-size:13px;font-weight:500;line-height:1.5}.CFSaVG_radioHint{color:var(--dsw-alias-label-tertiary);font-size:12px;line-height:1.5}.CFSaVG_radioContent{margin-left:24px}.CFSaVG_radioContent>*+*{margin-top:12px}.CFSaVG_radioContent input[type=text]:enabled{cursor:text}.CFSaVG_checkboxRow{align-items:center;gap:10px;display:flex}.CFSaVG_checkboxRow input[type=checkbox]{width:16px;height:16px;accent-color:var(--dsw-alias-brand-primary);flex:none;margin:0}.CFSaVG_checkboxRow input[type=checkbox]:focus-visible{outline:2px solid var(--dsw-alias-brand-primary);outline-offset:1px}";
471
474
  const tagId = "dsh-web-fetch-playwright/fields.module.css";
472
475
  if (typeof document !== "undefined" && document.querySelector("style[data-plugin-css=" + JSON.stringify(tagId) + "]") === null) {
473
476
  const tag = document.createElement("style");
@@ -477,29 +480,39 @@ window.__ModuleLoader__.load({
477
480
  document.head.appendChild(tag);
478
481
  }
479
482
  var fields_module_css_default = {
480
- "hint": "CFSaVG_hint",
483
+ "radioHint": "CFSaVG_radioHint",
484
+ "checkboxRow": "CFSaVG_checkboxRow",
481
485
  "label": "CFSaVG_label",
482
- "badges": "CFSaVG_badges",
486
+ "field": "CFSaVG_field",
487
+ "hint": "CFSaVG_hint",
488
+ "radioGroup": "CFSaVG_radioGroup",
489
+ "radioContent": "CFSaVG_radioContent",
483
490
  "head": "CFSaVG_head",
484
- "input": "CFSaVG_input",
491
+ "badges": "CFSaVG_badges",
492
+ "radioText": "CFSaVG_radioText",
485
493
  "badge": "CFSaVG_badge",
494
+ "radioOptionPlain": "CFSaVG_radioOptionPlain",
495
+ "radioPick": "CFSaVG_radioPick",
496
+ "fieldEmbedded": "CFSaVG_fieldEmbedded",
497
+ "input": "CFSaVG_input",
486
498
  "inputInvalid": "CFSaVG_inputInvalid",
487
- "hintIndented": "CFSaVG_hintIndented",
488
- "radioText": "CFSaVG_radioText",
489
- "radioContent": "CFSaVG_radioContent",
490
- "checkboxRow": "CFSaVG_checkboxRow",
491
- "invalid": "CFSaVG_invalid",
492
- "field": "CFSaVG_field",
493
- "radioLabel": "CFSaVG_radioLabel",
494
- "radioGroup": "CFSaVG_radioGroup",
495
499
  "radioOption": "CFSaVG_radioOption",
496
- "radioHint": "CFSaVG_radioHint",
500
+ "invalid": "CFSaVG_invalid",
501
+ "hintIndented": "CFSaVG_hintIndented",
497
502
  "reset": "CFSaVG_reset",
498
- "fieldEmbedded": "CFSaVG_fieldEmbedded",
499
- "radioPick": "CFSaVG_radioPick"
503
+ "radioLabel": "CFSaVG_radioLabel"
500
504
  };
501
505
  //#endregion
502
506
  //#region src/client/fields.tsx
507
+ /**
508
+ * The Playwright card's controls: the shipped ValueField (text input with
509
+ * override badge and reset) plus the two this card adds — a two-option radio
510
+ * group for the backend (each option carrying its backend-specific input
511
+ * nested inside) and a checkbox for the denoise toggle — styled on the same
512
+ * tokens and rhythm as the built-in plugin-configuration fields.
513
+ *
514
+ * @module dsh-web-fetch-playwright/client/fields
515
+ */
503
516
  /** A staged text field (copy of the shipped ValueField). */
504
517
  function ValueField(props) {
505
518
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
@@ -547,8 +560,9 @@ window.__ModuleLoader__.load({
547
560
  }
548
561
  /** A staged radio group: the backend selector. */
549
562
  function RadioGroupField(props) {
563
+ const name = (0, react.useId)();
550
564
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("fieldset", {
551
- className: fields_module_css_default.field,
565
+ className: props.embedded ? fields_module_css_default.fieldEmbedded : fields_module_css_default.field,
552
566
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
553
567
  className: fields_module_css_default.head,
554
568
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
@@ -572,12 +586,12 @@ window.__ModuleLoader__.load({
572
586
  role: "radiogroup",
573
587
  "aria-label": props.label,
574
588
  children: props.options.map((option) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
575
- className: fields_module_css_default.radioOption,
589
+ className: props.plainOptions ? fields_module_css_default.radioOptionPlain : fields_module_css_default.radioOption,
576
590
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", {
577
591
  className: fields_module_css_default.radioPick,
578
592
  children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
579
593
  type: "radio",
580
- name: "playwright-backend",
594
+ name,
581
595
  value: option.value,
582
596
  checked: props.text === option.value,
583
597
  disabled: props.disabled,
@@ -661,6 +675,8 @@ window.__ModuleLoader__.load({
661
675
  const state = props.usePlaywrightCard((snapshot) => snapshot);
662
676
  if (!state.available) return null;
663
677
  const disabled = !state.writable;
678
+ const isolated = state.shareBrowserContext.text === "false";
679
+ const scope = state.contextIsolationScope.text === "session" ? "session" : "global";
664
680
  const backend = state.backend.text === "cdp" ? "cdp" : "local";
665
681
  return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(CardForm, {
666
682
  copy: {
@@ -719,12 +735,44 @@ window.__ModuleLoader__.load({
719
735
  onReset: () => {
720
736
  props.resetField("cdpEndpoint");
721
737
  }
722
- }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(CheckboxField, {
738
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RadioGroupField, {
723
739
  embedded: true,
724
- id: "plugin-config-playwright-share-context",
725
- label: t("shareBrowserContext"),
726
- hint: t("shareBrowserContextHint"),
727
- checked: state.shareBrowserContext.text !== "false",
740
+ label: t("contextMode"),
741
+ text: isolated ? "false" : "true",
742
+ options: [{
743
+ value: "true",
744
+ label: t("shareBrowserContext"),
745
+ hint: t("shareBrowserContextHint")
746
+ }, {
747
+ value: "false",
748
+ label: t("isolateBrowserContext"),
749
+ hint: t("isolateBrowserContextHint"),
750
+ content: isolated ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(RadioGroupField, {
751
+ embedded: true,
752
+ plainOptions: true,
753
+ label: t("contextIsolationScope"),
754
+ text: scope,
755
+ options: [{
756
+ value: "global",
757
+ label: t("contextScopeGlobal"),
758
+ hint: t("contextScopeGlobalHint")
759
+ }, {
760
+ value: "session",
761
+ label: t("contextScopeSession"),
762
+ hint: t("contextScopeSessionHint")
763
+ }],
764
+ overridden: state.contextIsolationScope.overridden,
765
+ overriddenLabel: t("overridden"),
766
+ resetLabel: t("reset"),
767
+ disabled: disabled || backend !== "cdp",
768
+ onEdit: (text) => {
769
+ props.edit("contextIsolationScope", text);
770
+ },
771
+ onReset: () => {
772
+ props.resetField("contextIsolationScope");
773
+ }
774
+ }) : void 0
775
+ }],
728
776
  overridden: state.shareBrowserContext.overridden,
729
777
  overriddenLabel: t("overridden"),
730
778
  resetLabel: t("reset"),
@@ -737,7 +785,7 @@ window.__ModuleLoader__.load({
737
785
  }
738
786
  })] })
739
787
  }],
740
- text: state.backend.text,
788
+ text: backend,
741
789
  overridden: state.backend.overridden,
742
790
  overriddenLabel: t("overridden"),
743
791
  resetLabel: t("reset"),
@@ -818,7 +866,15 @@ window.__ModuleLoader__.load({
818
866
  cdpEndpoint: "CDP endpoint",
819
867
  cdpEndpointHint: "host:port or http(s)/ws URL. Leave blank for 127.0.0.1:9222.",
820
868
  shareBrowserContext: "Share the browser context (profile logins)",
821
- shareBrowserContextHint: "Each fetch opens a tab in the remote browser’s real profile — cookies and localStorage are shared and its persistent logins apply. Unchecked: every fetch uses a fresh isolated context.",
869
+ shareBrowserContextHint: "Each fetch opens a tab in the remote browser’s real profile — cookies and localStorage are shared and its persistent logins apply.",
870
+ contextMode: "Browser context",
871
+ isolateBrowserContext: "Isolate from the browser profile",
872
+ isolateBrowserContextHint: "Use a separate in-memory context with the lifecycle chosen below; no access to the browser profile’s logins.",
873
+ contextIsolationScope: "Reuse isolated context",
874
+ contextScopeSession: "Per DSH session",
875
+ contextScopeSessionHint: "Created on demand per DSH session. Concurrent fetches share the context in separate tabs, each closing its own tab. The context closes when no active or pending fetches and no other open tabs remain; the next fetch starts with fresh cookies. Different sessions keep separate site data.",
876
+ contextScopeGlobal: "Global reuse across DSH sessions",
877
+ contextScopeGlobalHint: "All DSH sessions share cookies and localStorage within this plugin instance.",
822
878
  denoise: "Enable the denoise algorithm",
823
879
  denoiseHint: "Readability + DOMPurify strip nav bars, sidebars, footers, and ads before converting to markdown.",
824
880
  maxConcurrency: "Max concurrent fetches",
@@ -850,7 +906,15 @@ window.__ModuleLoader__.load({
850
906
  cdpEndpoint: "CDP 地址",
851
907
  cdpEndpointHint: "host:port 或 http(s)/ws 地址;留空默认 127.0.0.1:9222。",
852
908
  shareBrowserContext: "共享浏览器上下文(复用登录态)",
853
- shareBrowserContextHint: "每次抓取在远端浏览器的真实 profile 里开一个标签页:共享 cookie 与 localStorage、复用已登录会话,页面会看到你的登录身份;取消勾选则每次抓取使用全新隔离上下文。",
909
+ shareBrowserContextHint: "每次抓取在远端浏览器的真实 profile 里开一个标签页:共享 cookie 与 localStorage、复用已登录会话,页面会看到你的登录身份。",
910
+ contextMode: "浏览器上下文",
911
+ isolateBrowserContext: "隔离浏览器上下文",
912
+ isolateBrowserContextHint: "使用独立的内存上下文,生命周期由下方范围决定,不使用远端浏览器 profile 的登录态。",
913
+ contextIsolationScope: "隔离上下文复用范围",
914
+ contextScopeSession: "按 DSH 会话隔离",
915
+ contextScopeSessionHint: "按 DSH 会话按需创建上下文;并发抓取共享上下文,各用独立标签页并各自关闭。没有活动或待处理抓取,且没有其他打开的标签页时关闭上下文;下次抓取使用全新 cookie。不同会话的站点数据互不共享。",
916
+ contextScopeGlobal: "跨 DSH 会话全局复用",
917
+ contextScopeGlobalHint: "本插件实例内,所有 DSH 会话共享 cookie 与 localStorage。",
854
918
  denoise: "启用降噪算法",
855
919
  denoiseHint: "使用 Readability + DOMPurify 清洗导航栏、侧边栏、页脚与贴片广告后再转为 Markdown。",
856
920
  maxConcurrency: "最大并发抓取数",