dev3000 0.0.182 → 0.0.184

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.
Files changed (60) hide show
  1. package/README.md +37 -169
  2. package/bin/d3k-runtime +2 -0
  3. package/bin/dev3000 +2 -119
  4. package/dist/cdp-monitor.d.ts +6 -0
  5. package/dist/cdp-monitor.d.ts.map +1 -1
  6. package/dist/cdp-monitor.js +30 -8
  7. package/dist/cdp-monitor.js.map +1 -1
  8. package/dist/cli.js +4 -53
  9. package/dist/cli.js.map +1 -1
  10. package/dist/dev-environment.d.ts.map +1 -1
  11. package/dist/dev-environment.js +8 -46
  12. package/dist/dev-environment.js.map +1 -1
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.js +2 -0
  16. package/dist/index.js.map +1 -1
  17. package/dist/runtime/browser-events.d.ts +5 -0
  18. package/dist/runtime/browser-events.d.ts.map +1 -0
  19. package/dist/runtime/browser-events.js +87 -0
  20. package/dist/runtime/browser-events.js.map +1 -0
  21. package/dist/runtime/cli.d.ts +3 -0
  22. package/dist/runtime/cli.d.ts.map +1 -0
  23. package/dist/runtime/cli.js +90 -0
  24. package/dist/runtime/cli.js.map +1 -0
  25. package/dist/runtime/runtime.d.ts +10 -0
  26. package/dist/runtime/runtime.d.ts.map +1 -0
  27. package/dist/runtime/runtime.js +346 -0
  28. package/dist/runtime/runtime.js.map +1 -0
  29. package/dist/runtime/session.d.ts +18 -0
  30. package/dist/runtime/session.d.ts.map +1 -0
  31. package/dist/runtime/session.js +61 -0
  32. package/dist/runtime/session.js.map +1 -0
  33. package/dist/runtime/timeline.d.ts +40 -0
  34. package/dist/runtime/timeline.d.ts.map +1 -0
  35. package/dist/runtime/timeline.js +69 -0
  36. package/dist/runtime/timeline.js.map +1 -0
  37. package/dist/skills/d3k/internal-skill.md +20 -131
  38. package/dist/skills/index.d.ts +54 -0
  39. package/dist/skills/index.d.ts.map +1 -0
  40. package/dist/skills/index.js +214 -0
  41. package/dist/skills/index.js.map +1 -0
  42. package/dist/utils/d3k-skill-installer.d.ts +4 -0
  43. package/dist/utils/d3k-skill-installer.d.ts.map +1 -0
  44. package/dist/utils/d3k-skill-installer.js +30 -0
  45. package/dist/utils/d3k-skill-installer.js.map +1 -0
  46. package/dist/utils/version-check.d.ts +1 -21
  47. package/dist/utils/version-check.d.ts.map +1 -1
  48. package/dist/utils/version-check.js +2 -97
  49. package/dist/utils/version-check.js.map +1 -1
  50. package/package.json +7 -16
  51. package/skills/d3k/PUBLISH.md +46 -0
  52. package/skills/d3k/SKILL.md +32 -0
  53. package/skills/d3k/agents/openai.yaml +4 -0
  54. package/skills/d3k/scripts/runtime.mjs +26 -0
  55. package/dist/commands/skill-runner.d.ts +0 -40
  56. package/dist/commands/skill-runner.d.ts.map +0 -1
  57. package/dist/commands/skill-runner.js +0 -826
  58. package/dist/commands/skill-runner.js.map +0 -1
  59. package/dist/skills/index.test.ts +0 -203
  60. package/dist/skills/index.ts +0 -259
package/README.md CHANGED
@@ -1,210 +1,78 @@
1
- # d3k (dev3000)
1
+ # d3k
2
2
 
3
- d3k is an agent-first local web debugging runtime. It starts your dev server, opens a monitored browser with a project-stable Chrome profile, and gives your coding agent one timeline of server logs, browser errors, network activity, interactions, and screenshots.
3
+ d3k gives your coding agent a managed browser and a shared timeline of server output, browser console messages, exceptions, network requests, and interactions.
4
4
 
5
- Every app gets a stable Portless URL by default, so browser state and callbacks do not move when the underlying development port changes.
6
-
7
- The primary interface is the d3k skill: tell your agent what you want, and let it own the runtime.
8
-
9
- > "Let me test this project with d3k."
10
- >
11
- > "Debug the checkout flow with d3k."
12
- >
13
- > "Run this app with d3k and watch for errors while I reproduce the bug."
14
-
15
- The TUI is still available for people who want a standalone terminal dashboard, but it is not required for the agent workflow.
16
-
17
- ## Install
18
-
19
- Node.js 24 or newer is required.
20
-
21
- Install the runtime globally:
22
-
23
- ```bash
24
- bun install -g dev3000
25
- ```
26
-
27
- npm also works:
28
-
29
- ```bash
30
- npm install -g dev3000
31
- ```
32
-
33
- Install the d3k skill for your coding agents:
5
+ Install the skill, then ask your agent to run the project, reproduce an issue, and inspect what happened:
34
6
 
35
7
  ```bash
36
- bunx skills add vercel-labs/dev3000 --skill d3k --agent '*' -g -y
8
+ pnpm dlx skills add vercel-labs/dev3000 --skill d3k
37
9
  ```
38
10
 
39
- The skill teaches agents to start d3k non-interactively, retain the background process, reuse the managed browser, and inspect the unified evidence instead of launching a separate dev server or browser.
40
-
41
- ## The Agent Workflow
42
-
43
- When you ask to use d3k, the agent should:
44
-
45
- 1. Run `d3k portless status --json` and complete `d3k portless setup` if required.
46
- 2. Run `d3k status --json` and reuse only a ready Portless project session.
47
- 3. Start `d3k -t` in a retained background tool session when needed.
48
- 4. Wait for d3k to report a port-free HTTPS URL and managed browser.
49
- 5. Either hand the headed browser to you or drive it with `d3k agent-browser`, depending on your request.
50
- 6. Read `d3k errors --context` and the unified logs after reproduction.
51
- 7. Keep the same runtime and project-stable Chrome profile alive across edits and retests.
11
+ > Use d3k to run this project and help me debug the checkout flow.
52
12
 
53
- That gives the user one stable URL, one browser, one evidence stream, and one dev server.
13
+ The skill owns a small background JavaScript runtime. No global d3k binary or terminal dashboard is required. Node.js 24+, pnpm, and Chrome are needed. The installed skill runs the JavaScript runtime under Node; Bun is only used for development in this repository.
54
14
 
55
- ### "Let me test" vs. "Test this"
15
+ ## Try the source
56
16
 
57
- "Let me test with d3k" means the agent prepares the headed monitored browser and hands control to you. It should wait while you reproduce the issue, then inspect what d3k captured.
58
-
59
- "Test/debug this with d3k" means the agent can drive the managed browser and investigate autonomously.
60
-
61
- ## Agent Commands
17
+ Until this runtime is released, use the helper from this checkout. Run these commands from the **app you want to debug**, replacing `/path/to/dev3000` with this checkout:
62
18
 
63
19
  ```bash
64
- # Is this project's runtime ready?
65
- d3k status --json
66
-
67
- # Is canonical Portless HTTPS ready?
68
- d3k portless status --json
69
-
70
- # Start the runtime manually in agent-safe mode (non-TUI default)
71
- d3k -t
72
-
73
- # Inspect unified evidence
74
- d3k errors --context
75
- d3k logs -n 200
76
- d3k logs --type browser
77
- d3k logs --type server
78
-
79
- # Drive the exact browser d3k is monitoring
80
- d3k agent-browser snapshot -i
81
- d3k agent-browser click @e2
82
- d3k agent-browser fill @e3 "text"
83
- d3k agent-browser --require-d3k-browser open https://my-app.localhost
20
+ node /path/to/dev3000/skills/d3k/scripts/runtime.mjs portless status
21
+ # One-time administrator authorization, if setup is required:
22
+ node /path/to/dev3000/skills/d3k/scripts/runtime.mjs portless setup
23
+ node /path/to/dev3000/skills/d3k/scripts/runtime.mjs start
84
24
  ```
85
25
 
86
- Do not run `npm run dev` or `bun run dev` alongside d3k. d3k is the dev-server owner for the session.
87
-
88
- Portless is required by default and only counts as ready when it provides a genuinely port-free URL such as `https://my-app.localhost`. `d3k portless setup` performs one-time administrator authorization to generate/trust the local HTTPS CA and install a root-owned startup service on port 443. After setup, every d3k server registers behind that proxy and the managed browser opens the Portless URL. d3k fails before starting the app when canonical Portless is unavailable; use `--no-portless` only when direct localhost routing is specifically required.
89
-
90
- ## Why the Managed Browser Matters
91
-
92
- Each project gets a persistent Chrome profile under `~/.d3k/<project>/chrome-profile/`. Login state, cookies, and local storage survive across debugging sessions.
26
+ Keep `start` in a retained background process session. The helper runs checkout source with Bun. An installed skill can target this source by setting `D3K_RUNTIME_ROOT=/path/to/dev3000`.
93
27
 
94
- d3k also connects browser activity to server output, so an agent can see the interaction that preceded an error instead of reasoning from disconnected terminal and browser snapshots.
28
+ Canonical Portless HTTPS must be ready before starting the server or browser. The runtime uses a port-free URL such as `https://my-app.localhost`, with a project-stable Chrome profile for authentication. It fails before launching the app if setup is incomplete.
95
29
 
96
- For OAuth and other auth-sensitive flows, let d3k launch Chrome. A separate Playwright, browser MCP, raw Chrome, or custom `agent-browser --profile` session is a different browser identity and can break sign-in flows.
30
+ ## Read evidence
97
31
 
98
- ## What d3k Captures
99
-
100
- - Development-server output
101
- - Browser console messages and exceptions
102
- - Network requests and responses
103
- - User interactions
104
- - Navigation and error screenshots
105
- - Chrome DevTools Protocol events
106
- - A session manifest that agents can discover with `d3k status --json`
107
-
108
- Artifacts are stored per project:
109
-
110
- | Artifact | Location |
111
- | --- | --- |
112
- | Active session | `~/.d3k/<project>/session.json` |
113
- | Consolidated log | `~/.d3k/<project>/d3k.log` or `logs/` |
114
- | Screenshots | `~/.d3k/<project>/screenshots/` |
115
- | Chrome profile | `~/.d3k/<project>/chrome-profile/` |
116
- | Crash log | `~/.d3k/crash.log` |
117
-
118
- ## Standalone TUI
119
-
120
- Run `d3k` directly when you want the interactive terminal experience:
32
+ The commands below use `d3k-runtime`, the package's JavaScript entrypoint. In a checkout, substitute `node /path/to/dev3000/skills/d3k/scripts/runtime.mjs`.
121
33
 
122
34
  ```bash
123
- d3k
35
+ d3k-runtime status
36
+ d3k-runtime browser snapshot -i
37
+ d3k-runtime browser click @e2
38
+ d3k-runtime events --session <sessionId> --after <cursor>
39
+ d3k-runtime events --after <cursor> --source server
40
+ d3k-runtime events --after <cursor> --level error
41
+ d3k-runtime stop
124
42
  ```
125
43
 
126
- You can also launch an agent beside the TUI in tmux:
44
+ Before reproducing an issue, retain the `sessionId` and `cursor` from `status`. Read events after that cursor, continuing while `hasMore` is true. A new session returns `reset: true`; `dropped` reports events evicted from the buffer. Filtered queries advance through examined events, so keep the original cursor when comparing multiple views of an interval.
127
45
 
128
- ```bash
129
- d3k --with-agent claude
130
- d3k --with-agent codex
131
- d3k --with-agent opencode
132
- ```
133
-
134
- The split-screen workflow requires tmux. The agent-first background workflow does not.
135
-
136
- ## Runtime Options
46
+ Server and browser events share sequence numbers assigned at collection time. Network events retain CDP request IDs, and exceptions retain stack traces. Chronological proximity to a server line does not establish causation.
137
47
 
138
- ```bash
139
- d3k --help
140
- ```
48
+ The timeline holds at most 5,000 events or 8 MiB. Individual records are capped. No log files are written by the skill runtime, and its evidence disappears on exit. Request headers and bodies are omitted; URL query values are redacted. Console output and server messages can still contain application secrets.
141
49
 
142
- | Option | Purpose |
143
- | --- | --- |
144
- | `-p, --port <port>` | Override the detected dev-server port |
145
- | `-s, --script <script>` | Override the detected package script |
146
- | `-c, --command <command>` | Run a custom dev-server command |
147
- | `--app-url <url>` | Open a specific URL in the managed browser |
148
- | `--profile-dir <dir>` | Override the project Chrome profile |
149
- | `--no-portless` | Disable the default stable Portless URL |
150
- | `--headless` | Run Chrome headlessly for CI |
151
- | `--servers-only` | Intentionally disable browser monitoring |
152
- | `--tui` | Enable the interactive dashboard (off by default) |
153
- | `--no-agent` | Skip the standalone agent-selection prompt |
154
- | `-t, --tail` | Stream the consolidated log |
155
- | `--debug` | Print verbose runtime diagnostics |
156
-
157
- Prefer auto-detection. Use overrides only when the project has an unusual dev command, port, or target URL.
158
-
159
- ## Diagnostic Commands
50
+ Only browser profile and session discovery data persist under `~/.d3k/<project>/`. Local control uses authenticated IPC, not an HTTP listener on the network. Automatic screenshots are off; use `browser screenshot <absolute-path>` when needed.
160
51
 
161
- ```bash
162
- d3k errors
163
- d3k errors --context
164
- d3k errors --all
52
+ ## Server and browser ownership
165
53
 
166
- d3k logs
167
- d3k logs --type browser
168
- d3k logs --type server
169
- d3k logs --json
54
+ The runtime detects the project's package manager and `dev` script. Use `start --command '<dev command>'` for other projects or custom servers. Use `--headless` for CI and `--servers-only` when browser monitoring is intentionally unwanted.
170
55
 
171
- d3k fix
172
- d3k fix --focus build
56
+ Chrome's sandbox stays enabled in both headed and headless modes. If a constrained container cannot support Chrome sandboxing, explicitly set `D3K_CHROME_NO_SANDBOX=1` when starting the runtime. This disables browser isolation and emits a startup warning; use it only in an appropriately isolated environment. d3k does not retry without the sandbox automatically.
173
57
 
174
- d3k crawl
175
- d3k crawl --depth all
176
- ```
58
+ The agent and user share the same monitored browser. Do not launch a second server or substitute another browser profile during a session. Leave the runtime running when handing the browser to the user for testing.
177
59
 
178
- ## Supported Projects
60
+ ## Compatibility
179
61
 
180
- d3k detects common web projects, including:
62
+ `d3k` and `dev3000` retain the previous local CLI, including optional terminal UI and file-backed logging. The skill uses `d3k-runtime` instead. The two runtimes must not own the same project simultaneously. The npm package now ships JavaScript instead of platform-specific d3k binaries.
181
63
 
182
- - Next.js, Vite, React, Vue, Svelte, and Astro
183
- - Django, Flask, and FastAPI
184
- - Rails
185
- - Custom servers supplied through `--command`
64
+ The website is a public landing page and changelog. Hosted dev agents, skill runners, workflow execution, sandboxes, OAuth, teams, admin controls, report/blob storage, and CLI telemetry have been removed. Existing remote deployments and stored data are not deleted by a source change.
186
65
 
187
66
  ## Development
188
67
 
189
- Use d3k itself as the local runtime for this repository:
190
-
191
- ```bash
192
- d3k -t
193
- ```
194
-
195
- After code changes:
196
-
197
68
  ```bash
69
+ bun install
198
70
  bun run lint
199
71
  bun run typecheck
200
- ```
201
-
202
- For CLI or TUI changes under `src/`:
203
-
204
- ```bash
72
+ bun run test
205
73
  bun run canary
206
74
  ```
207
75
 
208
- ## License
76
+ `bun run canary` builds, packs, installs, and smoke-tests the JavaScript package locally. It does not publish to npm. Use `./scripts/release.sh` from a clean `main` checkout to prepare a stable release; GitHub Actions publishes through Trusted Publishing.
209
77
 
210
78
  MIT
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ import "../dist/runtime/cli.js"
package/bin/dev3000 CHANGED
@@ -1,120 +1,3 @@
1
1
  #!/usr/bin/env node
2
- /**
3
- * Platform wrapper script for d3k
4
- *
5
- * This script detects the current platform and executes the appropriate
6
- * pre-compiled binary from the platform-specific optional dependency.
7
- */
8
-
9
- import { spawn } from "child_process"
10
- import { existsSync } from "fs"
11
- import { createRequire } from "module"
12
- import { arch, platform } from "os"
13
- import { dirname, join } from "path"
14
- import { fileURLToPath } from "url"
15
-
16
- const __filename = fileURLToPath(import.meta.url)
17
- const __dirname = dirname(__filename)
18
- const require = createRequire(import.meta.url)
19
-
20
- // Map of platform-arch to package name
21
- const PLATFORMS = {
22
- "darwin-arm64": "@d3k/darwin-arm64",
23
- "linux-x64": "@d3k/linux-x64",
24
- "win32-x64": "@d3k/windows-x64",
25
- // "darwin-x64": "@d3k/darwin-x64", // Add later
26
- // "linux-arm64": "@d3k/linux-arm64", // Add later
27
- }
28
-
29
- function findBinary() {
30
- const key = `${platform()}-${arch()}`
31
- const pkgName = PLATFORMS[key]
32
-
33
- if (!pkgName) {
34
- console.error(`\n Unsupported platform: ${key}`)
35
- console.error(` Currently supported platforms: macOS ARM64 (Apple Silicon), Linux x64, Windows x64`)
36
- console.error(`\n For other platforms, please open an issue at:`)
37
- console.error(` https://github.com/vercel-labs/dev3000/issues\n`)
38
- process.exit(1)
39
- }
40
-
41
- // Windows binaries have .exe extension
42
- const isWindows = platform() === "win32"
43
- const binaryName = isWindows ? "dev3000.exe" : "dev3000"
44
-
45
- // Try to find the binary in node_modules
46
- // It could be in the local node_modules or a parent directory
47
- const possiblePaths = [
48
- // Installed as a dependency
49
- join(__dirname, "..", "node_modules", pkgName, "bin", binaryName),
50
- // Installed globally (npm)
51
- join(__dirname, "..", "..", pkgName, "bin", binaryName),
52
- // Installed globally (pnpm)
53
- join(__dirname, "..", "node_modules", ".pnpm", `${pkgName}@*`, "node_modules", pkgName, "bin", binaryName),
54
- ]
55
-
56
- for (const binPath of possiblePaths) {
57
- if (existsSync(binPath)) {
58
- return binPath
59
- }
60
- }
61
-
62
- // Try to resolve through require
63
- try {
64
- const pkgPath = require.resolve(`${pkgName}/package.json`)
65
- const pkgDir = join(pkgPath, "..")
66
- const binPath = join(pkgDir, "bin", binaryName)
67
- if (existsSync(binPath)) {
68
- return binPath
69
- }
70
- } catch {
71
- // Package not found via require.resolve
72
- }
73
-
74
- console.error(`\n Could not find ${pkgName} binary.`)
75
- console.error(` Please ensure the package is properly installed:`)
76
- console.error(` npm install -g dev3000`)
77
- console.error(` or`)
78
- console.error(` pnpm install -g dev3000\n`)
79
- process.exit(1)
80
- }
81
-
82
- function main() {
83
- const binPath = findBinary()
84
-
85
- // Keep the JavaScript launcher alive so it can forward terminal signals to
86
- // the compiled runtime. This matters when the runtime owns detached child
87
- // process groups such as Portless-managed dev servers.
88
- const child = spawn(binPath, process.argv.slice(2), {
89
- stdio: "inherit",
90
- shell: false,
91
- })
92
-
93
- const forwardSignal = (signal) => {
94
- if (!child.killed) {
95
- child.kill(signal)
96
- }
97
- }
98
-
99
- process.on("SIGINT", () => forwardSignal("SIGINT"))
100
- process.on("SIGTERM", () => forwardSignal("SIGTERM"))
101
- if (process.platform !== "win32") {
102
- process.on("SIGHUP", () => forwardSignal("SIGHUP"))
103
- }
104
-
105
- child.on("error", (error) => {
106
- console.error(`Failed to start d3k: ${error.message}`)
107
- process.exit(1)
108
- })
109
-
110
- child.on("exit", (code, signal) => {
111
- if (code !== null) {
112
- process.exit(code)
113
- }
114
-
115
- const signalExitCodes = { SIGINT: 130, SIGTERM: 143, SIGHUP: 129 }
116
- process.exit(signalExitCodes[signal] || 1)
117
- })
118
- }
119
-
120
- main()
2
+ // Compatibility CLI. The skill uses bin/d3k-runtime, which doesn't load this UI.
3
+ import "../dist/cli.js"
@@ -1,4 +1,6 @@
1
1
  import { WebSocket } from "ws";
2
+ /** Sandbox exceptions must be explicit; headless mode alone never disables it. */
3
+ export declare function getChromeSandboxFlags(env?: NodeJS.ProcessEnv): string[];
2
4
  export interface CDPEvent {
3
5
  method: string;
4
6
  params: Record<string, unknown>;
@@ -25,6 +27,10 @@ export declare function selectCDPTarget(targets: CDPTargetInfo[], options?: {
25
27
  initialAppUrl?: string;
26
28
  }): CDPTargetInfo;
27
29
  export declare class CDPMonitor {
30
+ private eventObserver?;
31
+ private automaticScreenshots;
32
+ setEventObserver(observer: (event: CDPEvent) => void): void;
33
+ setAutomaticScreenshots(enabled: boolean): void;
28
34
  private browser;
29
35
  private connection;
30
36
  private debugPort;
@@ -1 +1 @@
1
- {"version":3,"file":"cdp-monitor.d.ts","sourceRoot":"","sources":["../src/cdp-monitor.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,MAAM,IAAI,CAAA;AAE9B,MA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AO,CAAC,gBAAgB;IAqDlB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,SAAS,GAAE,MAAiC,GAAG,OAAO,CAAC,IAAI,CAAC,CAiE5F;IAEK,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,GAAE,OAAe,GAAG,OAAO,CAAC,IAAI,CAAC,CAG1E;YAEa,wBAAwB;IAoTtC,OAAO,CAAC,uBAAuB;IAkG/B,OAAO,CAAC,6BAA6B;YAuBvB,cAAc;IA6CtB,kBAAkB,CAAC,WAAW,EAAE;QACpC,IAAI,EAAE,MAAM,CAAA;QACZ,WAAW,CAAC,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;QACtC,GAAG,CAAC,EAAE,MAAM,CAAA;QACZ,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;QACnC,EAAE,CAAC,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;QAC7B,IAAI,CAAC,EAAE;YAAE,CAAC,EAAE,MAAM,CAAC;YAAC,CAAC,EAAE,MAAM,CAAA;SAAE,CAAA;KAChC,GAAG,OAAO,CAAC,IAAI,CAAC,CAoDhB;IAED;;;OAGG;IACH,eAAe,IAAI,IAAI,CAGtB;YAEa,kBAAkB;YAyBlB,uBAAuB;IAoF/B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAkF9B;YAEa,2BAA2B;CA+C1C"}
@@ -4,6 +4,10 @@ import { tmpdir } from "os";
4
4
  import { dirname, join } from "path";
5
5
  import { fileURLToPath } from "url";
6
6
  import { WebSocket } from "ws";
7
+ /** Sandbox exceptions must be explicit; headless mode alone never disables it. */
8
+ export function getChromeSandboxFlags(env = process.env) {
9
+ return env.D3K_CHROME_NO_SANDBOX === "1" ? ["--no-sandbox", "--disable-setuid-sandbox"] : [];
10
+ }
7
11
  const EMBEDDED_LOADING_HTML = `<!DOCTYPE html>
8
12
  <html>
9
13
  <head>
@@ -228,6 +232,14 @@ export function selectCDPTarget(targets, options = {}) {
228
232
  throw new Error(`CDP target mismatch on port ${options.appServerPort || "unknown"}; expected ${expectedDetails}, found ${debuggableTargets.map(formatTargetForLog).join(", ")}`);
229
233
  }
230
234
  export class CDPMonitor {
235
+ eventObserver;
236
+ automaticScreenshots = true;
237
+ setEventObserver(observer) {
238
+ this.eventObserver = observer;
239
+ }
240
+ setAutomaticScreenshots(enabled) {
241
+ this.automaticScreenshots = enabled;
242
+ }
231
243
  browser = null;
232
244
  connection = null;
233
245
  debugPort = 9222;
@@ -435,7 +447,7 @@ export class CDPMonitor {
435
447
  }
436
448
  }
437
449
  getCdpUrl() {
438
- return this.cdpUrl;
450
+ return this.connection?.ws.readyState === 1 ? this.cdpUrl : null;
439
451
  }
440
452
  getChromePids() {
441
453
  return Array.from(this.chromePids);
@@ -640,8 +652,12 @@ export class CDPMonitor {
640
652
  "--disable-sync",
641
653
  "--metrics-recording-only",
642
654
  "--disable-default-apps",
655
+ ...getChromeSandboxFlags(),
643
656
  ...CHROME_CRASH_RESTORE_SUPPRESSION_FLAGS
644
657
  ];
658
+ if (chromeArgs.includes("--no-sandbox")) {
659
+ this.logger("browser", "[CDP] WARNING: Chrome sandbox disabled explicitly by D3K_CHROME_NO_SANDBOX=1");
660
+ }
645
661
  if (shouldEnableReactDevTools && reactDevToolsExtensionPath) {
646
662
  chromeArgs.push(`--disable-extensions-except=${reactDevToolsExtensionPath}`);
647
663
  chromeArgs.push(`--load-extension=${reactDevToolsExtensionPath}`);
@@ -654,9 +670,7 @@ export class CDPMonitor {
654
670
  if (this.headless) {
655
671
  // Use new headless mode (Chrome 112+) which has better compatibility
656
672
  chromeArgs.push("--headless=new");
657
- // Additional flags needed for headless in serverless environments
658
- chromeArgs.push("--no-sandbox");
659
- chromeArgs.push("--disable-setuid-sandbox");
673
+ // Headless rendering does not require disabling Chrome's sandbox.
660
674
  chromeArgs.push("--disable-gpu");
661
675
  chromeArgs.push("--disable-dev-shm-usage");
662
676
  chromeArgs.push("--disable-background-timer-throttling");
@@ -1307,7 +1321,8 @@ export class CDPMonitor {
1307
1321
  this.debugLog(`Target destroyed: ${params.targetId}`);
1308
1322
  this.logger("browser", `[TARGET] Window/tab closed: ${params.targetId}`);
1309
1323
  // If this is our main tab/window being closed, trigger shutdown callback
1310
- if (this.onWindowClosedCallback && !this.isShuttingDown) {
1324
+ const monitoredTarget = this.cdpUrl?.split("/").pop();
1325
+ if (params.targetId === monitoredTarget && this.onWindowClosedCallback && !this.isShuttingDown) {
1311
1326
  this.debugLog("Chrome window was manually closed, triggering d3k shutdown");
1312
1327
  this.logger("browser", "[TARGET] Chrome window manually closed, shutting down d3k");
1313
1328
  this.onWindowClosedCallback();
@@ -1345,6 +1360,12 @@ export class CDPMonitor {
1345
1360
  }
1346
1361
  if (message.method) {
1347
1362
  this.debugLog(`Received CDP event: ${message.method}`);
1363
+ this.eventObserver?.({
1364
+ method: message.method,
1365
+ params: message.params || {},
1366
+ timestamp: Date.now(),
1367
+ sessionId: message.sessionId
1368
+ });
1348
1369
  const handler = this.eventHandlers.get(message.method);
1349
1370
  if (handler) {
1350
1371
  const event = {
@@ -1496,8 +1517,7 @@ export class CDPMonitor {
1496
1517
  id: el.id || '',
1497
1518
  className: el.className || '',
1498
1519
  name: el.name || '',
1499
- type: el.type || '',
1500
- value: el.value || ''
1520
+ type: el.type || ''
1501
1521
  };
1502
1522
  return JSON.stringify(details);
1503
1523
  }
@@ -1524,7 +1544,7 @@ export class CDPMonitor {
1524
1544
  let details = getElementDetails(e.target);
1525
1545
  // Send interaction data via custom event instead of console.log to avoid user visibility
1526
1546
  window.dispatchEvent(new CustomEvent('dev3000-interaction', {
1527
- detail: { type: 'KEY', key: e.key, element: details }
1547
+ detail: { type: 'KEY', key: e.key.length === 1 ? '[character]' : e.key, element: details }
1528
1548
  }));
1529
1549
  });
1530
1550
 
@@ -1794,6 +1814,8 @@ export class CDPMonitor {
1794
1814
  }
1795
1815
  }
1796
1816
  async takeScreenshot(event) {
1817
+ if (!this.automaticScreenshots)
1818
+ return null;
1797
1819
  try {
1798
1820
  // Throttle screenshots to avoid spam
1799
1821
  const now = Date.now();