{"record":{"id":"43e1a4fb5847fb29","repo":"SeleniumHQ/selenium","slug":"cache-behavior-must-be-either-cachebehavior-def","errorCode":null,"errorMessage":"Cache behavior must be either \"${CacheBehavior.DEFAULT}\" or \"${CacheBehavior.BYPASS}\"","messagePattern":"Cache behavior must be either \"(.+?)\" or \"(.+?)\"","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/network.js","lineNumber":373,"sourceCode":"    const command = {\n      method: 'network.provideResponse',\n      params: Object.fromEntries(params.asMap()),\n    }\n\n    await this.bidi.send(command)\n  }\n\n  /**\n   * Sets the cache behavior for network requests.\n   *\n   * @param {string} behavior - The cache behavior (\"default\" or \"bypass\")\n   * @param {Array<string>} [contexts] - Optional array of browsing context IDs\n   * @returns {Promise<void>} A promise that resolves when the cache behavior is set\n   * @throws {Error} If behavior is invalid or context IDs are invalid\n   */\n  async setCacheBehavior(behavior, contexts = null) {\n    if (!Object.values(CacheBehavior).includes(behavior)) {\n      throw new Error(`Cache behavior must be either \"${CacheBehavior.DEFAULT}\" or \"${CacheBehavior.BYPASS}\"`)\n    }\n\n    const command = {\n      method: 'network.setCacheBehavior',\n      params: {\n        cacheBehavior: behavior,\n      },\n    }\n\n    if (contexts !== null) {\n      if (\n        !Array.isArray(contexts) ||\n        contexts.length === 0 ||\n        contexts.some((c) => typeof c !== 'string' || c.trim() === '')\n      ) {\n        throw new Error('Contexts must be an array of non-empty strings')\n      }\n      command.params.contexts = contexts","sourceCodeStart":355,"sourceCodeEnd":391,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/network.js#L355-L391","documentation":"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.","triggerScenarios":"Calling network.setCacheBehavior('bypass-cache'), setCacheBehavior('DEFAULT') (wrong case), setCacheBehavior(null), setCacheBehavior(undefined), or setCacheBehavior(1).","commonSituations":"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.","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."],"exampleFix":"// before\nawait network.setCacheBehavior('bypass-cache', contexts)\n\n// after\nconst { CacheBehavior } = require('selenium-webdriver/bidi/network')\nawait network.setCacheBehavior(CacheBehavior.BYPASS, contexts)","handlingStrategy":"validation","validationCode":"const VALID = Object.values(CacheBehavior)\nif (!VALID.includes(behavior)) {\n  throw new Error(`Invalid cache behavior: ${behavior}`)\n}","typeGuard":"function isValidCacheBehavior(v) {\n  return v === CacheBehavior.DEFAULT || v === CacheBehavior.BYPASS\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["bidi","network","cache","enum-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}