dsh-web-fetch-playwright 0.2.7 → 0.2.9

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.
@@ -1,21 +1,34 @@
1
1
  /**
2
- * Browser half of `dsh-web-fetch-playwright`: registers the locale dictionary
3
- * and the plugin-configuration card keyed by the `web-fetch-playwright`
4
- * settings namespace, so the card pairs with the Host section the plugin half
5
- * registers — the shipped configurable-plugins tab dispatches it with no
6
- * changes.
2
+ * Browser half of `dsh-web-fetch-playwright`: registers the locale
3
+ * dictionary and the plugin-configuration card keyed by the
4
+ * `web-fetch-playwright` settings namespace (the composition entry id the
5
+ * host's settings service derives from the plugin's Config schema).
6
+ *
7
+ * Since dsh 0.1.7 the Plugins page owns a plugin's configuration, and its
8
+ * slot contract offers a bundle two seats: the bundle's own form on its
9
+ * package page (`plugins.bundle.config`, keyed by package name — what the
10
+ * user opens straight from the plugin list) and one row's page
11
+ * (`plugins.row.config`, keyed `<package name>#<row id>` — the row's
12
+ * configure control). This bundle is one plugin with one config, so BOTH
13
+ * seats inject the SAME card and controller: whichever way the user arrives,
14
+ * the form is on the first page they land on, and one staging area follows
15
+ * them between the two. The mounts ride `configForms.whileServed`, so a
16
+ * deployment that never composed the host entry shows no trace of the card.
7
17
  *
8
18
  * @module dsh-web-fetch-playwright/client
9
19
  */
10
20
 
11
21
  import type { Context } from 'cordis'
12
- // Type-only: pulls the ctx.locale / ctx.slots / ctx.settingsScope Context
13
- // merges, and the 'settings.plugin.item' SlotMap declaration from the
14
- // ui-settings-plugins package that owns the slot contract.
22
+ // Type-only: pulls the ctx.configForms Context merge (the shared forms
23
+ // service) from the owning client package, the ctx.slots merge from the
24
+ // renderer, and the 'plugins.bundle.config' / 'plugins.row.config' SlotMap
25
+ // declarations from the Plugins page (type-only imports are erased before
26
+ // the purity gate).
15
27
  import type {} from '@deepseek-ai/dsh-client-locale/client'
16
28
  import type {} from '@deepseek-ai/dsh-client-ui-slots'
29
+ import type {} from '@deepseek-ai/dsh-client-ui-renderer/client'
17
30
  import type {} from '@deepseek-ai/dsh-client-ui-settings/client'
18
- import type {} from '@deepseek-ai/dsh-client-ui-settings-plugins/client'
31
+ import type {} from '@deepseek-ai/dsh-client-ui-plugin-manager/client'
19
32
  import { PlaywrightCardController, WEB_FETCH_PLAYWRIGHT_NS } from './controller.ts'
20
33
  import { PlaywrightCard } from './card.tsx'
21
34
  import { en, zh } from './locales.ts'
@@ -23,23 +36,56 @@ import { en, zh } from './locales.ts'
23
36
  /** Dictionary namespace owned by this plugin. */
24
37
  const NS = 'web-fetch-playwright'
25
38
 
39
+ /**
40
+ * This bundle's package name — the Plugins page keys a bundle's own
41
+ * configuration by it. Spelled here rather than read from any manifest:
42
+ * this bundle must stay self-contained.
43
+ */
44
+ const PACKAGE_NAME = 'dsh-web-fetch-playwright'
45
+
46
+ /**
47
+ * The row's configuration key `<package name>#<row id>` with the row id as
48
+ * the bundle's patch declares it.
49
+ */
50
+ const ROW_CONFIG_KEY = `${PACKAGE_NAME}#web-fetch-playwright`
51
+
26
52
  /** Required services (cordis fiber inject). */
27
- export const inject = ['slots', 'locale', 'settingsScope']
53
+ export const inject = ['slots', 'locale', 'configForms']
28
54
 
29
55
  /**
30
- * Mount the Playwright plugin-configuration card.
56
+ * Mount the Playwright plugin-configuration card while the Host serves the
57
+ * `web-fetch-playwright` namespace.
31
58
  * @param ctx - the browser plugin context.
32
59
  */
33
60
  export function apply(ctx: Context): void {
34
61
  ctx.effect(() => ctx.locale.register(NS, { zh, en }), 'web-fetch-playwright: card dictionary')
35
62
 
36
63
  const controller = new PlaywrightCardController(
37
- ctx.settingsScope.bind({ namespace: WEB_FETCH_PLAYWRIGHT_NS }),
64
+ ctx.configForms.get(WEB_FETCH_PLAYWRIGHT_NS),
65
+ )
66
+ ctx.effect(() => () => { controller.dispose() }, 'web-fetch-playwright: form subscription')
67
+
68
+ // The card's two seats on the Plugins page, one shared controller behind
69
+ // both: the bundle's own page shows the form between its description and
70
+ // its rows, and the row keeps its configure control opening the same form
71
+ // under the plugin's own title. `whileServed` owns both mounts, so a host
72
+ // without the entry never renders an empty section.
73
+ ctx.effect(
74
+ () => ctx.configForms.whileServed([WEB_FETCH_PLAYWRIGHT_NS], () => {
75
+ const offBundle = ctx.slots.inject('plugins.bundle.config', () => ctx.slots.register({
76
+ name: 'plugins.bundle.config',
77
+ key: PACKAGE_NAME,
78
+ locale: NS,
79
+ inject: () => controller.inject(),
80
+ }, PlaywrightCard))
81
+ const offRow = ctx.slots.inject('plugins.row.config', () => ctx.slots.register({
82
+ name: 'plugins.row.config',
83
+ key: ROW_CONFIG_KEY,
84
+ locale: NS,
85
+ inject: () => controller.inject(),
86
+ }, PlaywrightCard))
87
+ return () => { offBundle(); offRow() }
88
+ }),
89
+ 'web-fetch-playwright: plugins-page card',
38
90
  )
39
- ctx.slots.inject('settings.plugin.item', () => ctx.slots.register({
40
- name: 'settings.plugin.item',
41
- key: WEB_FETCH_PLAYWRIGHT_NS,
42
- locale: NS,
43
- inject: () => controller.inject(),
44
- }, PlaywrightCard))
45
91
  }
@@ -7,7 +7,7 @@
7
7
 
8
8
  /** Locale keys this card renders. */
9
9
  export type PlaywrightCardLocaleKey =
10
- | 'title' | 'description'
10
+ | 'description'
11
11
  | 'backendLabel' | 'backendLocal' | 'backendLocalHint' | 'backendCdp' | 'backendCdpHint'
12
12
  | 'playwrightPath' | 'playwrightPathHint' | 'playwrightPathPlaceholder'
13
13
  | 'cdpEndpoint' | 'cdpEndpointHint'
@@ -15,8 +15,8 @@ export type PlaywrightCardLocaleKey =
15
15
  | 'denoise' | 'denoiseHint'
16
16
  | 'maxConcurrency' | 'maxConcurrencyHint' | 'maxConcurrencyPlaceholder'
17
17
  | 'challengeWaitMs' | 'challengeWaitMsHint' | 'challengeWaitMsPlaceholder'
18
- | 'overridden' | 'reset' | 'readOnly' | 'expand' | 'collapse'
19
- | 'save' | 'saving' | 'discard' | 'unsaved' | 'saveFailed' | 'invalidText'
18
+ | 'overridden' | 'reset' | 'readOnly'
19
+ | 'save' | 'saving' | 'discard' | 'saveFailed' | 'invalidText'
20
20
 
21
21
  /** This plugin's dictionary namespace, merged into the locale key map. */
22
22
  declare module '@deepseek-ai/dsh-client-ui-slots' {
@@ -27,7 +27,6 @@ declare module '@deepseek-ai/dsh-client-ui-slots' {
27
27
 
28
28
  /** English copy. */
29
29
  export const en: Record<PlaywrightCardLocaleKey, string> = {
30
- title: 'Playwright web fetch',
31
30
  description: 'Fetches pages with a real browser (local Playwright or CDP) and returns denoised markdown.',
32
31
  backendLabel: 'Playwright backend',
33
32
  backendLocal: 'Local Playwright',
@@ -52,19 +51,15 @@ export const en: Record<PlaywrightCardLocaleKey, string> = {
52
51
  overridden: 'Overridden',
53
52
  reset: 'Reset to default',
54
53
  readOnly: 'This deployment stores settings read-only.',
55
- expand: 'Show settings',
56
- collapse: 'Hide settings',
57
54
  save: 'Save',
58
55
  saving: 'Saving…',
59
56
  discard: 'Discard',
60
- unsaved: 'Unsaved',
61
57
  saveFailed: 'The deployment did not accept these values; they were left for you to correct.',
62
58
  invalidText: 'This value is not accepted here.',
63
59
  }
64
60
 
65
61
  /** Simplified Chinese copy. */
66
62
  export const zh: Record<PlaywrightCardLocaleKey, string> = {
67
- title: 'Playwright 网页爬取',
68
63
  description: '用真实浏览器(本地 Playwright 或 CDP)抓取网页,降噪后转为 Markdown。',
69
64
  backendLabel: 'Playwright 后端',
70
65
  backendLocal: '本地 Playwright',
@@ -89,12 +84,9 @@ export const zh: Record<PlaywrightCardLocaleKey, string> = {
89
84
  overridden: '已覆盖',
90
85
  reset: '恢复默认',
91
86
  readOnly: '本部署的设置为只读。',
92
- expand: '展开设置',
93
- collapse: '收起设置',
94
87
  save: '保存',
95
88
  saving: '保存中…',
96
89
  discard: '放弃修改',
97
- unsaved: '未保存',
98
90
  saveFailed: '本部署没有接受这些值,已保留供你修改。',
99
91
  invalidText: '该值不被此设置项接受。',
100
92
  }
package/src/config.ts CHANGED
@@ -4,9 +4,16 @@
4
4
  * resolved shape, and the small pure normalizers the provider applies per
5
5
  * fetch (CDP endpoint shaping) — kept network-free for unit tests.
6
6
  *
7
+ * Since dsh 0.1.7 the settings service derives a plugin's configuration page
8
+ * from its composition entry's `Config` schema: every field marked
9
+ * `.volatile()` is editable live (Settings → Plugins), and a committed edit
10
+ * is pushed into the running plugin's volatile references without a remount —
11
+ * this schema IS the `web-fetch-playwright` settings section.
12
+ *
7
13
  * @module dsh-web-fetch-playwright/config
8
14
  */
9
15
 
16
+ import type { Volatile } from '@deepseek-ai/cordis'
10
17
  import z from '@deepseek-ai/schemastery'
11
18
 
12
19
  /** Default CDP endpoint when the settings section leaves it blank. */
@@ -99,23 +106,98 @@ export interface Config {
99
106
  maxConcurrency?: number
100
107
  }
101
108
 
102
- export const Config: z<Config> = z.object({
103
- // union-of-consts rather than z.enum: the profile's published schemastery
104
- // build does not expose `.enum`, and this schema executes at runtime
105
- // against that copy.
106
- backend: z.union([z.const('local'), z.const('cdp')]).default('local'),
107
- playwrightPath: z.string().default(''),
108
- cdpEndpoint: z.string().default(''),
109
- shareBrowserContext: z.boolean().default(true),
110
- denoise: z.boolean().default(true),
109
+ // union-of-consts rather than z.enum: the profile's published schemastery
110
+ // build does not expose `.enum`, and this schema executes at runtime
111
+ // against that copy. Every field is `.volatile()`: the whole section is
112
+ // live-editable from the Plugins page and a commit reaches the running
113
+ // provider without a remount.
114
+ export const Config = z.object({
115
+ backend: z.union([z.const('local'), z.const('cdp')]).default('local').volatile(),
116
+ playwrightPath: z.string().default('').volatile(),
117
+ cdpEndpoint: z.string().default('').volatile(),
118
+ shareBrowserContext: z.boolean().default(true).volatile(),
119
+ denoise: z.boolean().default(true).volatile(),
111
120
  // Optional on purpose: the effective default depends on `backend`, which a
112
121
  // static schema default cannot express.
113
- maxConcurrency: z.number().step(1).min(1).max(MAX_CONCURRENCY_CEILING),
122
+ maxConcurrency: z.number().step(1).min(1).max(MAX_CONCURRENCY_CEILING).volatile(),
114
123
  // The bounded natural-wait knobs; 0 disables the whole challenge path.
115
- challengeWaitMs: z.number().step(100).min(0).max(MAX_CHALLENGE_WAIT_MS).default(DEFAULT_CHALLENGE_WAIT_MS),
116
- challengeRetries: z.number().step(1).min(0).max(MAX_CHALLENGE_RETRIES).default(DEFAULT_CHALLENGE_RETRIES),
124
+ challengeWaitMs: z.number().step(100).min(0).max(MAX_CHALLENGE_WAIT_MS).default(DEFAULT_CHALLENGE_WAIT_MS).volatile(),
125
+ challengeRetries: z.number().step(1).min(0).max(MAX_CHALLENGE_RETRIES).default(DEFAULT_CHALLENGE_RETRIES).volatile(),
117
126
  })
118
127
 
128
+ /**
129
+ * The config `apply` receives once the schema resolves: every volatile field
130
+ * arrives as a live reference whose snapshot a settings commit replaces in
131
+ * place, so the provider re-reads them per fetch (the plugin never remounts
132
+ * for an edit).
133
+ */
134
+ export interface PlaywrightPluginConfig {
135
+ /** Backend selector as a live reference. */
136
+ backend: Volatile<PlaywrightBackend>
137
+ /** Local backend executable path as a live reference. */
138
+ playwrightPath: Volatile<string>
139
+ /** CDP endpoint as a live reference. */
140
+ cdpEndpoint: Volatile<string>
141
+ /** Shared-context toggle as a live reference. */
142
+ shareBrowserContext: Volatile<boolean>
143
+ /** Denoise toggle as a live reference. */
144
+ denoise: Volatile<boolean>
145
+ /**
146
+ * Concurrency limit as a live reference; `undefined` while unset (the
147
+ * field owns no default — the backend resolves one).
148
+ */
149
+ maxConcurrency: Volatile<number | undefined>
150
+ /** Challenge wait budget (ms) as a live reference. */
151
+ challengeWaitMs: Volatile<number>
152
+ /** Challenge retry count as a live reference. */
153
+ challengeRetries: Volatile<number>
154
+ }
155
+
156
+ /**
157
+ * Read the live references `apply` holds into one plain input for
158
+ * {@link resolveConfig}; a settings commit has usually replaced the
159
+ * snapshots since the last call, which is the whole point.
160
+ *
161
+ * @param config - the plugin config as the loader resolved it.
162
+ * @returns the current snapshots, ready for resolution.
163
+ */
164
+ export function snapshotsOf(config: PlaywrightPluginConfig): Config {
165
+ return {
166
+ backend: config.backend.get(),
167
+ playwrightPath: config.playwrightPath.get(),
168
+ cdpEndpoint: config.cdpEndpoint.get(),
169
+ shareBrowserContext: config.shareBrowserContext.get(),
170
+ denoise: config.denoise.get(),
171
+ maxConcurrency: config.maxConcurrency.get(),
172
+ challengeWaitMs: config.challengeWaitMs.get(),
173
+ challengeRetries: config.challengeRetries.get(),
174
+ }
175
+ }
176
+
177
+ /**
178
+ * Resolve any accepted config input into the fully-defaulted, plain form the
179
+ * provider consumes per fetch. Validation goes through the schema, so the
180
+ * volatile wrappers that produces are unwrapped immediately — the provider
181
+ * consumes plain values. The input face is `Partial` by design (composition
182
+ * entries and volatile snapshots both omit fields; defaults supply them).
183
+ *
184
+ * @param config - composition entry, settings-section value, or volatile snapshots.
185
+ * @returns the resolved config.
186
+ */
187
+ export function resolveConfig(config: Partial<Config>): ResolvedConfig {
188
+ const resolved = Config(config as never) as PlaywrightPluginConfig
189
+ return {
190
+ backend: resolved.backend.get(),
191
+ playwrightPath: resolved.playwrightPath.get(),
192
+ cdpEndpoint: resolved.cdpEndpoint.get(),
193
+ shareBrowserContext: resolved.shareBrowserContext.get(),
194
+ denoise: resolved.denoise.get(),
195
+ maxConcurrency: resolved.maxConcurrency.get(),
196
+ challengeWaitMs: resolved.challengeWaitMs.get(),
197
+ challengeRetries: resolved.challengeRetries.get(),
198
+ }
199
+ }
200
+
119
201
  /**
120
202
  * Complete config after schemastery applies the field defaults it owns.
121
203
  * `maxConcurrency` stays optional — {@link effectiveMaxConcurrency} resolves
@@ -0,0 +1,102 @@
1
+ /**
2
+ * Host resolve compat for the `punycode/` builtin-slash idiom.
3
+ *
4
+ * dsh web (runtime resolution in `dsh-app-boot`) intercepts Node's CommonJS
5
+ * resolver for every package installed in a profile. Its router classifies a
6
+ * bare request by stripping one trailing path segment, which turns tr46's
7
+ * `require("punycode/")` — the standard npm-package-over-deprecated-builtin
8
+ * idiom — into the builtin name `punycode`, and `require.resolve.paths()` of a
9
+ * builtin returns `null`; the unguarded iteration then throws
10
+ * `TypeError: createRequire.resolve.paths is not a function or its return
11
+ * value is not iterable`, killing the whole `jsdom` import chain (jsdom →
12
+ * whatwg-url → tr46) and with it this plugin's activation.
13
+ *
14
+ * The shim below is installed lazily, immediately before the first `jsdom`
15
+ * load, and only when the running resolver actually exhibits the failure
16
+ * (probed with the very request that breaks). It wraps the public
17
+ * `Module._resolveFilename` — whatever it currently is, native or already
18
+ * host-intercepted — and re-dispatches exactly the affected request shape
19
+ * (`<deprecated builtin>/`) with an explicit `paths` list. An explicit
20
+ * `options.paths` is the documented bypass of every resolution interceptor in
21
+ * the chain (the host wrapper delegates straight to the native resolver for
22
+ * it), so the request lands on the real npm package — the same file plain
23
+ * Node would have found. Hosts without the bug never see the wrapper at all;
24
+ * the probe itself changes nothing.
25
+ *
26
+ * The ESM flavor of the same router path exists in theory (`import
27
+ * 'punycode/'`), but nothing in this plugin's tree imports it that way —
28
+ * tr46 is CommonJS — so the CommonJS hook is the complete fix here.
29
+ *
30
+ * @module dsh-web-fetch-playwright/host-resolve-compat
31
+ */
32
+
33
+ import { createRequire, isBuiltin } from 'node:module'
34
+ import { fileURLToPath } from 'node:url'
35
+
36
+ /** `createRequire` anchored at this module, wherever the bundle is installed. */
37
+ const require_ = createRequire(import.meta.url)
38
+
39
+ /** This file's own path, the anchor the probe resolves from. */
40
+ const SELF_FILENAME = fileURLToPath(import.meta.url)
41
+
42
+ /**
43
+ * Whether a request is the npm-over-builtin idiom: one bare package name with
44
+ * a single trailing slash, whose stem is a Node builtin (today, in practice:
45
+ * `punycode/`).
46
+ * @param request - the module request seen by `Module._resolveFilename`.
47
+ * @returns `true` for `punycode/`-shaped requests; relative paths, scoped
48
+ * names, subpaths, and ordinary packages all answer `false`.
49
+ */
50
+ function isBuiltinSlashRequest(request: string): boolean {
51
+ if (request.length < 2 || !request.endsWith('/')) return false
52
+ const first = request.charAt(0)
53
+ if (first === '' || './#@'.includes(first)) return false
54
+ const stem = request.slice(0, -1)
55
+ return stem !== '' && !stem.includes('/') && isBuiltin(stem)
56
+ }
57
+
58
+ /** Probe outcome once known: `true` = shim installed or verified unneeded. */
59
+ let settled = false
60
+
61
+ /**
62
+ * Make `require("<deprecated builtin>/")` resolvable under hosts whose
63
+ * profile-scope resolution interceptor mishandles it. Idempotent, synchronous,
64
+ * and a no-op on healthy resolvers (the probe resolves successfully and no
65
+ * wrapper is installed). Must run before the first `require('jsdom')`.
66
+ */
67
+ export function installBuiltinSlashResolveCompat(): void {
68
+ if (settled) return
69
+ settled = true
70
+ const ModuleClass = require_('node:module').Module as {
71
+ _resolveFilename?: (request: string, parent: unknown, main?: boolean, options?: { paths?: string[] }) => string
72
+ }
73
+ const original = ModuleClass._resolveFilename
74
+ if (typeof original !== 'function') return
75
+
76
+ // Probe with the exact request that breaks. Resolving it (or failing with
77
+ // plain MODULE_NOT_FOUND on a tree that lacks the npm twin — where a
78
+ // wrapper could not help either) means the host needs no help.
79
+ try {
80
+ original.call(ModuleClass, 'punycode/', { filename: SELF_FILENAME })
81
+ return
82
+ } catch (error) {
83
+ if (!(error instanceof TypeError)) return
84
+ /* the compat case: install the wrapper below */
85
+ }
86
+
87
+ // The anchor list a native lookup would use from this module's position:
88
+ // this plugin's nested node_modules first, then the profile's hoisted root
89
+ // where `punycode` actually lives in a pnpm install.
90
+ const searchPaths = require_.resolve.paths('jsdom') ?? []
91
+
92
+ ModuleClass._resolveFilename = function patchedResolveFilename(
93
+ this: unknown, request: string, parent: unknown, main?: boolean, options?: { paths?: string[] },
94
+ ): string {
95
+ if (options?.paths === undefined && typeof request === 'string' && isBuiltinSlashRequest(request)) {
96
+ // `paths` set → every layer in the chain (including the host's) defers
97
+ // to the native resolver against exactly these anchors.
98
+ return original.call(ModuleClass, request, parent, main, { ...options, paths: searchPaths })
99
+ }
100
+ return original.call(ModuleClass, request, parent, main, options)
101
+ }
102
+ }
package/src/index.ts CHANGED
@@ -1,24 +1,44 @@
1
1
  /**
2
2
  * `dsh-web-fetch-playwright`: registers the Playwright/CDP
3
- * {@link PlaywrightFetchProvider} with `ctx.web` and exposes its settings
4
- * section ('web-fetch-playwright') so the web client's plugin-configuration
5
- * card can edit it live.
3
+ * {@link PlaywrightFetchProvider} with `ctx.web`.
4
+ *
5
+ * The `web-fetch-playwright` settings section is derived from this plugin's
6
+ * `Config` schema (dsh ≥ 0.1.7): its volatile fields are editable live on
7
+ * the Plugins page, and a committed change is pushed into the running
8
+ * config's volatile references — the provider re-reads them per fetch, so an
9
+ * edit reaches the next request without a restart or re-registration.
6
10
  *
7
11
  * A function plugin (NOT a default-export service): like the shipped search
8
- * providers, it registers INTO the seam's fetch registry.
12
+ * providers, it registers INTO the web seam's fetch registry.
9
13
  *
10
14
  * @module dsh-web-fetch-playwright
11
15
  */
12
16
 
13
17
  import type { Context } from '@deepseek-ai/cordis'
14
- import type {} from '@deepseek-ai/dsh-settings'
15
18
  import type {} from '@deepseek-ai/dsh-web'
16
- import { Config } from './config.ts'
17
- import type { ResolvedConfig } from './config.ts'
19
+ import { resolveConfig, snapshotsOf } from './config.ts'
20
+ import type { PlaywrightPluginConfig } from './config.ts'
18
21
  import { PlaywrightFetchProvider } from './provider.ts'
19
22
 
20
- export { Config, DEFAULT_CDP_ENDPOINT, DEFAULT_CHALLENGE_RETRIES, DEFAULT_CHALLENGE_WAIT_MS, effectiveChallengeRetries, effectiveChallengeWaitMs, effectiveContextMode, normalizeCdpEndpoint } from './config.ts'
21
- export type { Config as PlaywrightFetchConfig, CdpContextMode, PlaywrightBackend, ResolvedConfig } from './config.ts'
23
+ export {
24
+ Config,
25
+ DEFAULT_CDP_ENDPOINT,
26
+ DEFAULT_CHALLENGE_RETRIES,
27
+ DEFAULT_CHALLENGE_WAIT_MS,
28
+ effectiveChallengeRetries,
29
+ effectiveChallengeWaitMs,
30
+ effectiveContextMode,
31
+ normalizeCdpEndpoint,
32
+ resolveConfig,
33
+ snapshotsOf,
34
+ } from './config.ts'
35
+ export type {
36
+ Config as PlaywrightFetchConfig,
37
+ CdpContextMode,
38
+ PlaywrightBackend,
39
+ PlaywrightPluginConfig,
40
+ ResolvedConfig,
41
+ } from './config.ts'
22
42
  export { CdpConnectionPool } from './cdp-pool.ts'
23
43
  export type { CdpAcquireMode, CdpConnect, CdpLease } from './cdp-pool.ts'
24
44
  export { CHALLENGE_DOM_PROBE, CHALLENGE_FINISH_RESERVE_MS, CHALLENGE_POLL_INTERVAL_MS, CHALLENGE_TITLE_RE, classifyChallengeHtml, classifyChallengeResponse, isChallengeCompatibleResponse } from './challenge.ts'
@@ -30,33 +50,34 @@ export type { DenoiseMode, DenoiseResult } from './markdown.ts'
30
50
  /** Cordis plugin name used by loader diagnostics. */
31
51
  export const name = 'dsh-web-fetch-playwright'
32
52
 
33
- /** The web seam this provider registers into. */
53
+ /**
54
+ * The capability seam this plugin registers into. The settings section
55
+ * needs no inject: the host's settings service derives it from the entry's
56
+ * `Config` schema (its volatile fields) by entry id.
57
+ */
34
58
  export const inject = ['web']
35
59
 
36
- /** Settings namespace carrying this provider's configuration card. */
60
+ /**
61
+ * Settings namespace carrying this provider's configuration page: the
62
+ * composition entry id, which is what the settings service keys the
63
+ * derived section by.
64
+ */
37
65
  export const WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE = 'web-fetch-playwright'
38
66
 
39
- /** Register the Playwright fetch provider with `ctx.web`. */
40
- export function apply(ctx: Context, config: Config): void {
41
- // `current` is REASSIGNED by setSource when the settings scope attaches
42
- // (possibly after this function returns), so the provider must receive an
43
- // indirection — `() => current()` — never the thunk's value at this moment.
44
- // Passing `current` directly would pin the composition entry forever (the
45
- // web-search-deepseek provider uses the same wrapper idiom).
46
- let current: () => ResolvedConfig = () => config as ResolvedConfig
47
- ctx.inject(['settings'], (settingsCtx) => {
48
- settingsCtx.settings.installSection(ctx, WEB_FETCH_PLAYWRIGHT_SETTINGS_NAMESPACE, Config, config, {
49
- setSource: (source) => {
50
- current = source as () => ResolvedConfig
51
- },
52
- // The provider projects the section per fetch, so a committed change
53
- // needs no re-registration.
54
- onChange: () => {},
55
- })
56
- })
67
+ /**
68
+ * Register the Playwright fetch provider with `ctx.web`.
69
+ *
70
+ * @param ctx - plugin context supplying the web seam.
71
+ * @param config - the loader-resolved plugin config; its volatile fields are
72
+ * live references a settings commit updates in place.
73
+ */
74
+ export function apply(ctx: Context, config: PlaywrightPluginConfig): void {
75
+ // Re-read AND re-resolve per fetch: `snapshotsOf` dereferences the volatile
76
+ // references each time, so a section committed from the settings page
77
+ // between two fetches serves the second one.
78
+ const provider = new PlaywrightFetchProvider(() => resolveConfig(snapshotsOf(config)))
57
79
  // The CDP backend holds one shared connection for the provider's lifetime;
58
80
  // drop it when this plugin unloads so restarts don't strand sockets.
59
- const provider = new PlaywrightFetchProvider(() => current())
60
81
  ctx.effect(() => () => { void provider.dispose() }, 'dsh-web-fetch-playwright: shared CDP connection')
61
82
  ctx.web.registerFetchProvider(provider)
62
83
  }
package/src/markdown.ts CHANGED
@@ -11,16 +11,46 @@
11
11
  * options and span-safe table rules as the shipped `dsh-tool-web` renderer,
12
12
  * so output is consistent with what `web_fetch` produces elsewhere.
13
13
  *
14
- * Pure and synchronous — unit-tested against fixture pages.
14
+ * Synchronous for its callers and unit-tested against fixture pages: jsdom
15
+ * itself is loaded lazily on the first call — and, inside a dsh profile, only
16
+ * after `installBuiltinSlashResolveCompat`, so a host resolver that
17
+ * mishandles tr46's `require("punycode/")` cannot take the plugin down.
15
18
  *
16
19
  * @module dsh-web-fetch-playwright/markdown
17
20
  */
18
21
 
19
- import { JSDOM, VirtualConsole } from 'jsdom'
22
+ import { createRequire } from 'node:module'
20
23
  import createDOMPurify from 'dompurify'
21
24
  import { Readability } from '@mozilla/readability'
22
25
  import TurndownService from 'turndown'
23
26
  import { gfm } from '@joplin/turndown-plugin-gfm'
27
+ import { installBuiltinSlashResolveCompat } from './host-resolve-compat.ts'
28
+
29
+ /** `createRequire` anchored at this module, so jsdom resolves from this install. */
30
+ const require_ = createRequire(import.meta.url)
31
+
32
+ /** The lazily loaded jsdom exports; jsdom is CommonJS, so loading stays synchronous. */
33
+ type JsdomModule = typeof import('jsdom')
34
+
35
+ /** Loaded jsdom module, cached after the first denoise. */
36
+ let jsdom: JsdomModule | undefined
37
+
38
+ /**
39
+ * Load jsdom on first use, installing the host resolve compat first.
40
+ *
41
+ * Deferral serves two purposes: plugin activation never depends on jsdom's
42
+ * import chain surviving the host's module-resolution interception, and the
43
+ * compat shim — which must wrap the resolver *before* tr46's
44
+ * `require("punycode/")` runs — gets a guaranteed installation point.
45
+ * @returns the jsdom module exports.
46
+ */
47
+ function loadJsdom(): JsdomModule {
48
+ if (jsdom === undefined) {
49
+ installBuiltinSlashResolveCompat()
50
+ jsdom = require_('jsdom') as JsdomModule
51
+ }
52
+ return jsdom
53
+ }
24
54
 
25
55
  /** Layout/noise tags DOMPurify removes outright (with their content). */
26
56
  const FORBID_TAGS = [
@@ -157,6 +187,7 @@ export interface DenoiseResult {
157
187
  * @returns the markdown and the extraction mode used.
158
188
  */
159
189
  export function htmlToMarkdown(html: string, url: string): DenoiseResult {
190
+ const { JSDOM, VirtualConsole } = loadJsdom()
160
191
  // jsdom's virtual console defaults to forwarding parse noise; a silent one
161
192
  // keeps broken inline CSS on random pages out of host logs.
162
193
  const dom = new JSDOM(html, { url, virtualConsole: new VirtualConsole() })