Bug 2065545 - [firefox-devtools-mcp] Add a tool to disable the network cache - #168
Open
shoemoney wants to merge 1 commit into
Open
Bug 2065545 - [firefox-devtools-mcp] Add a tool to disable the network cache#168shoemoney wants to merge 1 commit into
shoemoney wants to merge 1 commit into
Conversation
…k cache
Adds set_network_cache, wrapping the BiDi network.setCacheBehavior command.
behavior='bypass' sends every request to the network; 'default' restores
normal caching. Scoped to the selected tab by default, browser-wide with
scope='global', as the bug asks for.
Joins the existing network module, so it comes with the developer preset
alongside the profiler tools it is meant to be used with.
Unknown behavior and scope values are rejected rather than defaulted:
silently caching when the caller asked to bypass would quietly invalidate
whatever they were measuring.
Note the bug names emulation.setNetworkConditions. That command exists in
Firefox but takes {type: "offline"} or null and has no cache parameter --
it is offline emulation, not cache control. network.setCacheBehavior is the
command that bypasses the cache; details and measurements in the PR.
juliandescottes
requested changes
Aug 25, 2026
juliandescottes
left a comment
Collaborator
There was a problem hiding this comment.
Thanks for the patch, works nicely. Just one small comment to address.
Comment on lines
+17
to
+28
| /** | ||
| * WebDriver BiDi network.CacheBehavior. | ||
| * - "default": normal HTTP cache behaviour | ||
| * - "bypass": skip the cache, so every request goes to the network | ||
| */ | ||
| export const CACHE_BEHAVIORS = ['default', 'bypass'] as const; | ||
|
|
||
| export type CacheBehavior = (typeof CACHE_BEHAVIORS)[number]; | ||
|
|
||
| export function isCacheBehavior(value: unknown): value is CacheBehavior { | ||
| return CACHE_BEHAVIORS.includes(value as CacheBehavior); | ||
| } |
Collaborator
There was a problem hiding this comment.
Feels a bit odd in index.ts. Could we move this to another module, eg create a src/firefox/cache.ts ?
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.
Adds a
set_network_cachetool so an agent can send every request to the network instead of the cache:Per your note on the bug, this is a tool rather than a config, and it is scoped to the selected tab by default with
scope: "global"as the opt-in. It joins the existingnetworkmodule, so it arrives with thedeveloperpreset alongside the profiler tools it is meant to be used with.One correction to the bug, with evidence
The bug says:
That command does exist in Firefox, but it has no cache parameter — it is offline emulation. Probed against Firefox 154 through this repo's own BiDi transport:
The only accepted values are
{type: "offline"}andnull.I checked that
invalid argumentreally meant "exists, wrong params" rather than "no such command", because reading it the other way would have sent me down the wrong path:The command that actually bypasses the cache is
network.setCacheBehavior, withcacheBehavior: "bypass" | "default"and an optionalcontexts— omit it for global, pass one for per-tab. That is what this PR wraps.Measured, not assumed
A local server serving
asset.jswithCache-Control: public, max-age=86400, counting real server hits across 3 page loads:setCacheBehavior('bypass'), tab-scopedsetCacheBehavior('default')restoresetCacheBehavior('bypass', {global:true})Both scopes work, and the effect is reversible.
Rejecting rather than defaulting
An unrecognised
behaviororscopereturns an error instead of falling back:Defaulting to
defaultwhen someone asked fordisabledwould silently leave the cache on and quietly invalidate whatever they were measuring — the exact failure this tool exists to prevent.bypassalso echoes back how to undo it, since the setting persists until reset:Tests
Six new unit tests in
tests/tools/network.test.ts, all failing on unmodifiedmain:No integration test: the cache-bypass assertion needs a local HTTP server with a cacheable asset and a hit counter, which is a new pattern for
tests/integration/(every file there usesfile://fixtures, andfile://cannot exercise the HTTP cache). Happy to add one if you would like that pattern introduced — the measurements above came from exactly that harness, so it is written.Left alone deliberately
emulation.setNetworkConditionswith{type: "offline"}is a genuinely useful thing to expose — offline-mode testing — but it is a different feature from this bug and would want its own tool and its own name. Happy to follow up if you want it.