Repository navigation
Conversation
…Chrome DevTools Protocol Adds a high-privilege developer-tools group on top of the existing browser bridge: element/CSS inspection and live edits, page-context JavaScript plus console output, and network capture with request detail and bodies. ## Capability negotiation The group is registered only while the connected extension advertises `devTools` in its `hello` (version 1). `BridgeServer` now records the caps of the authenticated connection and reports changes through `onCapsChange`, so a reconnect that drops the capability retracts the tools instead of offering tools the extension cannot serve. Firefox builds do not declare the API and therefore never advertise it. ## Consent model Approval in this repository is rooted in the extension, and the host-level approval seam is refused outright under a `never` session policy, so the consent boundary lives where the user actually is: the side panel. - Every devtools call raises its own dialog unless the user turned on the new **Allow developer tools** setting. - `trustedActionOrigins` and `unrestrictedBrowserAccess` deliberately do NOT cover this group: `resolveApprovalGate` keeps those shortcuts to ordinary actions, so enabling either can never silently hand over the debugger. - A session-scoped grant is cleared when the setting changes, the panel closes, or the worker restarts. Revoking detaches the debugger and aborts in-flight devtools calls. The controller itself only owns capability and target policy (platform support, undebuggable schemes, attachment); it must not add a second hard gate on the setting, or the dialog above becomes unreachable. ## Elements and CSS Resolves a target by CSS selector or by the `data-dsh-el` inventory index written by the content script, then reports box model, filtered computed styles, inline style, and matched rules. Writes apply to the inline style (through `CSS.setStyleTexts` when Chrome exposes an editable range, otherwise through the `style` attribute) or to the first matching author rule, spliced into its stylesheet by token range so unrelated rules survive. Reports are canonicalized: CSS custom properties are dropped (theme plumbing, hundreds of lines on one `body`) and a longhand is folded away only when the same block carries the shorthand covering it. An edit resolves its whole shorthand family, otherwise the shorthand would win the cascade and the edit would silently do nothing. Script-capable attributes are refused. ## Console `browser_console_eval` runs in the page's own context with `returnByValue` so JSON-compatible results come back as data instead of an opaque "object Object"; classes, functions, and DOM nodes fall back to description plus an optional preview. Exceptions are reported with their stack. ## Network capture `Network.enable` is not sufficient on its own: on live pages Chrome may emit `Network.requestWillBeSentExtraInfo` without ever sending the main `requestWillBeSent`, and a store that only listens for the main event records nothing while its event counters show traffic. Entries are therefore created from either event, a response adopts itself when no request event arrived, and both header shapes (the array the main event uses, the map the extra-info events use) are normalized. An entry whose request event never arrived is flagged rather than presenting a guessed method as fact. Capture is in memory, bounded (200 requests, 500 console entries), and resets on attach and on every top-level navigation; credential headers are redacted unless a call opts in, and bodies of authentication-shaped URLs are redacted by default. A status answer carries the enabled domains and observed network event kinds, so a thin capture is explainable without a rebuild. Wire format is unchanged: results remain single text payloads.
Adds 8 suites (extension + bridge) and extends the existing ones, on top of the implementation in the previous commit. ## Coverage - `debugger-session`: attach once and enable the four domains, conflict -> `devtools-conflict` with an actionable message, half-attachment cleanup, command timeout, pending commands settling on detach, absent platform API. - `devtools-network`: the observed live sequence (`requestWillBeSentExtraInfo` -> `responseReceivedExtraInfo` -> `responseReceived` -> `loadingFinished`, with the main request event withheld), response adoption, both header shapes, the incomplete-request flag clearing when the main event arrives, ring-buffer cap, reset on navigation, console levels and cap. - `devtools-elements`: selector and inventory-index resolution, computed-style filtering, shorthand canonicalization (including single-value `margin: 0`, which an earlier revision missed), family-aware edits, rule splicing, attribute risk classification, and both inline-edit paths. - `devtools-controller`: allowance no longer blocks a call (the dialog must stay reachable), internal pages refused before attach, stale failures cleared, pipeline evidence, and the `sinceIndex` window. - `devtools-authorization`: prompt shape for all nine tools, read vs action classification, and `resolveApprovalGate` proving neither unrestricted access nor the origin allowlist covers the group. - Plus the `hello` capability contract, the config key, and the manifest asymmetry asserted against both manifests. ## Docs Both READMEs (EN/ZH) gain a developer-tools section: the tool table, the opt-out setting, the one-debugger-per-tab constraint, and the data handling (redaction, bounded in-memory capture). The manifest and known-limitations sections record that the group is Chrome-only and needs a debuggable tab. ## Verification - `pnpm run check:runtime`, `pnpm run typecheck`, `pnpm run build`, `pnpm run test:smoke` (all five CI gates) pass locally. - `pnpm run test`: bridge 160/160, extension 493/493. - Exercised end to end on a real page: element inspection and CSS edit (written to the `style` attribute and re-read back), object evaluation returning JSON, console logs including uncaught exceptions, and a captured `fetch` with status, headers, timing, and pretty-printed response body.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
概述 / Summary
Adds an optional developer-tools group: inspect and edit element styles, run JS in the page, and capture network requests. Off by default; requires separate authorization. Closes #114.
81eb4cdimplementation (20 files)9d4d2e4tests and docs (21 files)动机 / Motivation
See #114. The existing tools cannot read computed styles or layout information, so style-related questions dead-end.
改动内容 / Changes
Host side (bridge-browser):
hellogains adevToolscapability negotiation: the group is registered only after the extension advertises it, and retracted on reconnect if the capability disappearsbrowser_devtools_elements(inspect elements),browser_devtools_set_element_style/browser_devtools_set_element_attribute(edit styles and attributes),browser_console_eval/browser_console_logs(run JS, read the console),browser_devtools_network/browser_devtools_list_requests/browser_devtools_get_request/browser_devtools_request_body(network capture); output remains{ text }Extension side (dsh-browser):
chrome.debuggersession management: attach, domain enable, timeouts, and a clear error on conflicts asking to close DevToolsRuntime.evaluateruns JS and returns the result; console output and exceptions are recordeddebuggerpermission; the Firefox manifest does notTwo implementation notes:
Network.requestWillBeSentalone: on some pages Chrome emits onlyrequestWillBeSentExtraInfoand never the main event, leaving the capture empty. Both events now create entries, and entries missing the main event are annotated "request method may be incomplete".测试 / Testing
pnpm run check:runtimepnpm run typecheckpnpm run test: bridge 160/160, extension 494/494pnpm run buildpnpm run test:smokeNew tests cover: debugger session lifecycle, network-capture event handling (including the ExtraInfo case), element location and style edits, authorization policy ("full browser control" and the origin allowlist never cover this group), and the manifest platform differences.
Verified in Chrome: inspecting an element's computed styles and matched rules; adding an outline and re-reading it to confirm the style attribute was written; running JS in the console and reading back JSON plus an uncaught exception with its stack; capturing a fetch with status, headers, timing, and a formatted JSON body.
影响范围 / Impact
Checklist
pnpm run build/bash -n scripts/install.sh等基础检查 / Passed basic checks