Skip to content

Add per-device JS-disable and network-level script-blocking toggles - #1549

Open
aks240295 wants to merge 4 commits into
responsively-org:mainfrom
aks240295:feature/js-disable-and-network-block-toggle
Open

aks240295 wants to merge 4 commits into
responsively-org:mainfrom
aks240295:feature/js-disable-and-network-block-toggle

Conversation

@aks240295

Copy link
Copy Markdown

Summary

Two independent per-device preview toggles, exposed both in the toolbar and over MCP:

  • Disable JS (set_javascript_enabled): fully disables the JS engine for that device's guest via the CDP debugger (Emulation.setScriptExecutionDisabled). Nothing on the page runs, including inline scripts.
  • Block JS Network (set_network_scripts_blocked): cancels script network requests (webRequest.onBeforeRequest, resourceType: "script") for that device's guest while leaving the JS engine on. Inline and already-loaded scripts keep running; only new network-fetched <script src> requests are blocked. This is a distinct failure mode from the JS-disable toggle -- closer to an ad-blocker, corporate firewall, or a dead CDN than a no-JS browser.

Both toggles reload the affected preview so the change takes visible effect, and persist across further reloads/navigation until changed again or the device leaves the active preview.

Also fixes a pre-existing bug in the MCP bridge's device lookup: McpBridge/commands.ts resolved a device's <webview> by document.getElementById(device.name), which is fragile once names contain spaces or slashes. Both new toggles need a reliable id-based lookup, so this adds a small webviewRegistry (registered on mount, unregistered on unmount) and switches the existing navigate/getCaptureTargets lookups over to it as well.

Test plan

  • Toggle each button in the toolbar and confirm the preview reloads and reflects the change
  • Confirm set_javascript_enabled / set_network_scripts_blocked work via MCP (list_devices, then the two new tools)
  • Confirm state persists across navigation and clears when the device leaves the active preview

Two independent per-device preview toggles, exposed both in the toolbar
and over MCP:

- set_javascript_enabled / Disable JS: fully disables the JS engine for
  that device's guest via the CDP debugger
  (Emulation.setScriptExecutionDisabled). Nothing on the page runs,
  including inline scripts.

- set_network_scripts_blocked / Block JS Network: cancels script
  network requests (webRequest.onBeforeRequest, resourceType
  script) for that device's guest while leaving the JS engine on.
  Inline and already-loaded scripts keep running; only new
  network-fetched <script src> requests are blocked. Distinct failure
  mode from the JS-disable toggle: closer to an ad-blocker, corporate
  firewall, or a dead CDN than a no-JS browser.

Both toggles reload the affected preview so the change takes visible
effect, and persist across further reloads/navigation until changed
again or the device leaves the active preview.

Also fixes a pre-existing bug in the MCP bridge's device lookup:
McpBridge/commands.ts resolved a device's <webview> by
document.getElementById(device.name), which is fragile once names
contain spaces or slashes. Both new toggles need a reliable id-based
lookup, so this adds a small webviewRegistry (registered on mount,
unregistered on unmount) and switches the existing navigate/
getCaptureTargets lookups over to it as well.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@aks240295
aks240295 force-pushed the feature/js-disable-and-network-block-toggle branch from 5299808 to 3201424 Compare September 24, 2026 07:00
aks240295 and others added 3 commits September 24, 2026 15:14
The lists-the-available-tools test in both mcp-server.spec.ts and
mcp-bridge-stdio.spec.ts hardcodes the full tool list, so it broke
once set_javascript_enabled and set_network_scripts_blocked were
registered.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The event-mirroring transport (BrowserSync) is injected into every
preview as a network-fetched script, indistinguishable from a page's
own scripts by resourceType alone. Blocking it silently dropped a
device out of scroll/click mirroring with the rest of the previews
whenever network-script-blocking was armed, instead of just blocking
the site's own scripts as intended.

Verified by temporarily logging every cancel/exempt decision: the
browser-sync-client.js request switched from cancelled to exempted
after this fix, while the site's own scripts stayed correctly blocked.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Found while live-testing the arm-a-toggle-then-navigate-then-read
workflow these toggles exist for, against a real site across all 8
device/condition screens.

- set_network_scripts_blocked's forced reload (reloadIgnoringCache(),
  needed to bypass the HTTP cache so the network filter can actually
  see the request) resolved before the reload had started or
  committed. A caller's very next action — a navigate() call, most
  realistically — could race that in-flight reload on the same
  webContents: two competing navigations, and whichever happened to
  commit last (not necessarily the one requested last) won. Now waits
  for the reload to genuinely settle (did-stop-loading/did-fail-load)
  before resolving, so a device is reliably idle again by the time
  the promise returns.

- navigate() only waited for the primary device to finish loading
  before returning. A slower non-primary device could still be
  showing the previous page when a caller read every device right
  after navigate() returned — exactly what happens when a script
  arms a toggle on one device, navigates, then reads all of them.
  Now waits for every active device to settle, plus a short buffer
  for async-mounted content, before returning.

Verified live against a real 8-screen device setup (JS-enabled,
JS-disabled, network-blocked, and Googlebot-UA, each on mobile and
desktop): 0 mismatches across repeated rapid navigations with both
toggles explicitly armed, versus reproducible device desyncs before
the fix.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant