SeleniumHQ/selenium · error · Error
Cache behavior must be either "${CacheBehavior.DEFAULT}" or
Error message
Cache behavior must be either "${CacheBehavior.DEFAULT}" or "${CacheBehavior.BYPASS}" What it means
Thrown by Network.setCacheBehavior() when the behavior argument is not one of the frozen CacheBehavior enum values ('default' or 'bypass'). The client checks Object.values(CacheBehavior).includes(behavior) before issuing network.setCacheBehavior, so any other string (or wrong casing) is rejected. This prevents sending an unsupported cache behavior to the remote end.
Source
Thrown at javascript/selenium-webdriver/bidi/network.js:373
const command = {
method: 'network.provideResponse',
params: Object.fromEntries(params.asMap()),
}
await this.bidi.send(command)
}
/**
* Sets the cache behavior for network requests.
*
* @param {string} behavior - The cache behavior ("default" or "bypass")
* @param {Array<string>} [contexts] - Optional array of browsing context IDs
* @returns {Promise<void>} A promise that resolves when the cache behavior is set
* @throws {Error} If behavior is invalid or context IDs are invalid
*/
async setCacheBehavior(behavior, contexts = null) {
if (!Object.values(CacheBehavior).includes(behavior)) {
throw new Error(`Cache behavior must be either "${CacheBehavior.DEFAULT}" or "${CacheBehavior.BYPASS}"`)
}
const command = {
method: 'network.setCacheBehavior',
params: {
cacheBehavior: behavior,
},
}
if (contexts !== null) {
if (
!Array.isArray(contexts) ||
contexts.length === 0 ||
contexts.some((c) => typeof c !== 'string' || c.trim() === '')
) {
throw new Error('Contexts must be an array of non-empty strings')
}
command.params.contexts = contextsView on GitHub (pinned to aa36b38e69)
Solutions
- Pass exactly 'default' or 'bypass', preferably via the CacheBehavior constants exported by the module (CacheBehavior.DEFAULT / CacheBehavior.BYPASS).
- Double-check casing: the values are lowercase.
- If you read behavior from config, validate against the two allowed values before calling.
Example fix
// before
await network.setCacheBehavior('bypass-cache', contexts)
// after
const { CacheBehavior } = require('selenium-webdriver/bidi/network')
await network.setCacheBehavior(CacheBehavior.BYPASS, contexts) Defensive patterns
Strategy: validation
Validate before calling
const VALID = Object.values(CacheBehavior)
if (!VALID.includes(behavior)) {
throw new Error(`Invalid cache behavior: ${behavior}`)
} Type guard
function isValidCacheBehavior(v) {
return v === CacheBehavior.DEFAULT || v === CacheBehavior.BYPASS
} Prevention
- Always pass the CacheBehavior.DEFAULT / CacheBehavior.BYPASS constants, never hand-typed strings.
- Remember the values are lowercase.
- Validate behavior read from config against the two allowed values.
When it happens
Trigger: Calling network.setCacheBehavior('bypass-cache'), setCacheBehavior('DEFAULT') (wrong case), setCacheBehavior(null), setCacheBehavior(undefined), or setCacheBehavior(1).
Common situations: Typing the behavior string by hand and misspelling it; using uppercase from a different enum source; passing a boolean or numeric flag instead of the enum string.
Related errors
- Contexts must be an array of non-empty strings
- Params must be an instance of AddInterceptParameters. Receiv
- Params must be an instance of ContinueRequestParameters. Rec
- Params must be an instance of ContinueResponseParameters. Re
- Params must be an instance of ProvideResponseParameters. Rec
AI-assisted analysis of SeleniumHQ/selenium@aa36b38e69 (2026-08-14).
Data as JSON: /api/errors/43e1a4fb5847fb29.
Report an issue: GitHub.