dsh-web-fetch-playwright 0.2.13 → 0.2.14

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.
@@ -71,7 +71,8 @@ The Plugins page (侧边栏 → 插件) opens the form one click from the list:
71
71
  | `backend` | `local` | Radio: *Local Playwright* or *Remote CDP endpoint*, each with its own nested input. |
72
72
  | `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
73
  | `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. |
74
+ | `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. |
75
+ | `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
76
  | `denoise` | `true` | Run the denoise pipeline; off returns the full rendered HTML for the tool layer to convert. |
76
77
  | `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
78
  | `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 +90,16 @@ CDP mode needs no local browser: the provider holds **one shared connection** fo
89
90
 
90
91
  ### The CDP context modes (share the browser's profile or not)
91
92
 
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.
93
+ 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.
94
+
95
+ Choose **Isolate from the browser profile**, then select:
96
+
97
+ - **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.
98
+ - **Global reuse across DSH sessions** (default): all DSH sessions within this plugin instance reuse one fixed isolated context.
99
+
100
+ 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.
101
+
102
+ 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
103
 
94
104
  **Profile-mode risk notes** — it upgrades `web_fetch` from "anonymous read" to "acts as the browser's logged-in user":
95
105
 
@@ -116,7 +126,7 @@ With the wait on (default):
116
126
  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
127
  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
128
 
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.
129
+ 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
130
 
121
131
  ## Development
122
132
 
@@ -127,6 +137,20 @@ pnpm test # vitest run (browser smoke self-skips without a browser)
127
137
  pnpm build # tsc declarations + tsdown (host ESM + client module-registration bundle)
128
138
  ```
129
139
 
140
+ 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):
141
+
142
+ ```sh
143
+ PLAYWRIGHT_TEST_EXECUTABLE_PATH=/path/to/chromium pnpm exec vitest run tests/cdp-recovery.browser.spec.ts
144
+ ```
145
+
146
+ 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.
147
+
148
+ 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.
149
+
150
+ ```sh
151
+ PLAYWRIGHT_TEST_CDP_ENDPOINT=http://your-gateway:9222 pnpm exec vitest run tests/cdp-gateway.browser.spec.ts
152
+ ```
153
+
130
154
  Repository layout:
131
155
 
132
156
  ```
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。
@@ -71,7 +71,8 @@ bundle 插件加入 profile 层栈后需**重启 `dsh web`** 生效;卸载用
71
71
  | `backend` | `local` | radio:本地 Playwright / 远端 CDP 地址,每个选项内嵌各自的填空。 |
72
72
  | `playwrightPath` | 空 | 本地后端:`playwright` 可执行文件或 Chromium 系浏览器二进制路径;留空按 `$PATH` 查找,再回退到内置 `playwright-core`。 |
73
73
  | `cdpEndpoint` | `127.0.0.1:9222` | 远端后端:`host:port`、`http(s)://…` 或 `ws(s)://…`。 |
74
- | `shareBrowserContext` | `true` | 仅 CDP 后端。**勾选(profile 模式)**:每次抓取是远端浏览器默认 context(真实 profile)里的一个标签页,cookie/localStorage 与之互通、已登录会话直接生效,抓取结束只关标签页;**取消勾选(隔离模式)**:每次抓取使用全新隐身式 context,互不共享。本地后端忽略此字段。 |
74
+ | `shareBrowserContext` | `true` | 仅 CDP:单选共享 / 隔离。`true` 复用远端默认 context 与登录态;`false` 使用独立 context,生命周期由下方范围决定。本地后端忽略。 |
75
+ | `contextIsolationScope` | `global` | 仅 CDP 隔离模式:`session` 按 DSH 会话按需创建 context,无活动/待处理抓取且无打开的标签页后关闭(下次抓取使用全新状态);`global` 在同一插件实例内跨DSH会话复用一个固定的隔离上下文。 |
75
76
  | `denoise` | `true` | 是否启用降噪;关闭时返回整页渲染 HTML,交由工具层转换。 |
76
77
  | `maxConcurrency` | *(自动)* | 同时渲染的页面上限(1–200)。留空按后端取默认:本地 **4**(每个槽位启动一个浏览器)/ CDP **50**(远端浏览器已就位,每个槽位只是一个标签页)。超出的请求短暂排队;20s 内等不到空位则以 `WEB_FETCH_TIMEOUT` 尽快失败并提示重试或调大该值,而不是一直挂起直到工具层预算中止。 |
77
78
  | `challengeWaitMs` | `15000` | Cloudflare 挑战的**有界**自然等待上限(毫秒,0–60000),在同一标签页内等待浏览器自行通过验证。`0` 关闭整条挑战处理链路——直接返回首次响应(0.2.5 之前的旧行为)。 |
@@ -89,7 +90,16 @@ CDP 模式不需要本地浏览器:插件在生命周期内对远端浏览器
89
90
 
90
91
  ### CDP 上下文模式(是否共享浏览器 profile)
91
92
 
92
- 「共享浏览器上下文」**勾选**(默认,profile 模式)时,每次抓取是远端浏览器默认 context——真实 profile——里的一个标签页:cookie 与 localStorage 双向互通,浏览器里已登录的站点会以登录态被抓取,和你手动开标签页一样。共享 context 永不关闭;资源过滤与弹窗守卫只挂在本次抓取自己的标签页上,不会干扰你人工打开的其他标签页。**取消勾选**(隔离模式)时,每次抓取使用全新隐身式 context——匿名读取,什么都不保留。
93
+ 选择**共享浏览器上下文**(默认)时,在远端浏览器已有的默认 context 内开标签页,双向共享 cookie / localStorage 并复用登录态;插件永不关闭这个默认 context。资源过滤与弹窗守卫只作用于本次抓取自己的标签页。
94
+
95
+ 选择**隔离浏览器上下文**后,再选择复用范围:
96
+
97
+ - **按 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。
98
+ - **跨DSH会话全局复用**(默认):本插件实例内所有 DSH 会话复用一个固定的隔离 context。
99
+
100
+ 插件自行创建隔离 context,不查找其他工具创建的 context。全局隔离仍在抓取之间保留 context:抓取结束仅关自己的标签页,因此后续抓取可沿用 cookie / localStorage。会话隔离则按上述规则,在没有活动/待处理抓取且没有打开的标签页后释放 context。这是内存复用,不保证浏览器或插件重启后保留;上下文配置变更会退役旧 context,卸载、断连或连接替换也会清理。全局隔离仅与浏览器 profile 隔离,**不隔离同一插件实例内的其他 DSH 会话**。
101
+
102
+ 如果其他 CDP 客户端删除了插件拥有的隔离 context,Chromium 不一定触发 Playwright 的 context `close` 事件。遇到明确的 `Target.createTarget` “Failed to find browser context with id …” 错误时,插件只让对应缓存失效,并在新的 context 中最多重试一次开标签页。并发请求复用同一个替代 context;被删除 context 的 cookie / localStorage 不会恢复。其他 context 与默认 profile 不受影响。该恢复机制不会重试普通页面错误、重放网页导航或回退到默认 profile。
93
103
 
94
104
  **profile 模式风险须知** —— 它把 `web_fetch` 从"匿名读网页"升级为"以浏览器登录身份行动":
95
105
 
@@ -116,7 +126,7 @@ google-chrome --remote-debugging-port=9222 --user-data-dir="$HOME/.config/chrome
116
126
  3. **有界重试** —— 窗口耗尽后,同一标签页默认再导航一次(`challengeRetries`),上下文里已有的通关 cookie 继续生效。
117
127
  4. **明确失败** —— 返回独立的 `WEB_FETCH_CHALLENGE` 错误码(web seam 的 `code` 是开放字符串,允许 provider 专属码),消息中写明站点、等待预算与最后一次挑战响应的状态。
118
128
 
119
- 安全边界(刻意为之):不点击 Turnstile、不解验证码、不注入 token、不伪装指纹/UA、不轮换代理、不导出 cookie——隔离模式下本次抓取挣到的通关态随其 context 一起销毁;profile 模式下它留在远端浏览器自己的 profile 里,插件从不复制或清理。等待始终受 `challengeWaitMs` 与 45s 单次抓取预算双重约束,永不无限阻塞。
129
+ 安全边界(刻意为之):不点击 Turnstile、不解验证码、不注入 token、不伪装指纹/UA、不轮换代理、不导出 cookie——CDP 隔离模式下通关态保留在对应会话 / 全局 context 中,直到该 context 被清理(本地 context 仍随每次抓取结束);profile 模式下它留在远端浏览器自己的 profile 里,插件从不复制或清理。等待始终受 `challengeWaitMs` 与 45s 单次抓取预算双重约束,永不无限阻塞。
120
130
 
121
131
  ## 开发
122
132
 
@@ -127,6 +137,14 @@ pnpm test # vitest run(无浏览器时浏览器集成用例自动跳过
127
137
  pnpm build # tsc 声明 + tsdown(宿主 ESM + 客户端 module-registration bundle)
128
138
  ```
129
139
 
140
+ 用真实 Chromium 执行外部删除 context 的回归测试(测试自行启动浏览器和本地站点,不连接配置中的用户浏览器):
141
+
142
+ ```sh
143
+ PLAYWRIGHT_TEST_EXECUTABLE_PATH=/path/to/chromium pnpm exec vitest run tests/cdp-recovery.browser.spec.ts
144
+ ```
145
+
146
+ 未指定路径时使用 Playwright 默认浏览器;默认二进制不存在会明确报告跳过。显式路径错误或启动失败则使测试失败。
147
+
130
148
  仓库结构:
131
149
 
132
150
  ```
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
- "footer": "UM8-Rq_footer",
417
418
  "discard": "UM8-Rq_discard",
418
419
  "save": "UM8-Rq_save",
420
+ "readOnly": "UM8-Rq_readOnly",
419
421
  "form": "UM8-Rq_form",
420
- "readOnly": "UM8-Rq_readOnly"
422
+ "failed": "UM8-Rq_failed",
423
+ "footer": "UM8-Rq_footer"
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",
481
- "label": "CFSaVG_label",
482
- "badges": "CFSaVG_badges",
483
483
  "head": "CFSaVG_head",
484
+ "fieldEmbedded": "CFSaVG_fieldEmbedded",
485
+ "radioLabel": "CFSaVG_radioLabel",
486
+ "radioOption": "CFSaVG_radioOption",
484
487
  "input": "CFSaVG_input",
488
+ "field": "CFSaVG_field",
489
+ "reset": "CFSaVG_reset",
485
490
  "badge": "CFSaVG_badge",
491
+ "invalid": "CFSaVG_invalid",
492
+ "hint": "CFSaVG_hint",
493
+ "radioPick": "CFSaVG_radioPick",
494
+ "radioContent": "CFSaVG_radioContent",
495
+ "label": "CFSaVG_label",
486
496
  "inputInvalid": "CFSaVG_inputInvalid",
487
497
  "hintIndented": "CFSaVG_hintIndented",
488
- "radioText": "CFSaVG_radioText",
489
- "radioContent": "CFSaVG_radioContent",
498
+ "radioOptionPlain": "CFSaVG_radioOptionPlain",
490
499
  "checkboxRow": "CFSaVG_checkboxRow",
491
- "invalid": "CFSaVG_invalid",
492
- "field": "CFSaVG_field",
493
- "radioLabel": "CFSaVG_radioLabel",
494
500
  "radioGroup": "CFSaVG_radioGroup",
495
- "radioOption": "CFSaVG_radioOption",
496
- "radioHint": "CFSaVG_radioHint",
497
- "reset": "CFSaVG_reset",
498
- "fieldEmbedded": "CFSaVG_fieldEmbedded",
499
- "radioPick": "CFSaVG_radioPick"
501
+ "badges": "CFSaVG_badges",
502
+ "radioText": "CFSaVG_radioText",
503
+ "radioHint": "CFSaVG_radioHint"
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: "最大并发抓取数",