{"record":{"id":"7ff3175c19f88a48","repo":"SeleniumHQ/selenium","slug":"contexts-must-be-an-array-of-non-empty-strings","errorCode":null,"errorMessage":"Contexts must be an array of non-empty strings","messagePattern":"Contexts must be an array of non-empty strings","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/network.js","lineNumber":389,"sourceCode":"  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\n    }\n\n    await this.bidi.send(command)\n  }\n\n  /**\n   * Unsubscribes from network events for all browsing contexts.\n   * @returns {Promise<void>} A promise that resolves when the network connection is closed.\n   */\n  async close() {\n    if (\n      this._browsingContextIds !== null &&\n      this._browsingContextIds !== undefined &&\n      this._browsingContextIds.length > 0\n    ) {\n      await this.bidi.unsubscribe(","sourceCodeStart":371,"sourceCodeEnd":407,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/network.js#L371-L407","documentation":"Thrown by Network.setCacheBehavior() when the optional contexts argument is non-null but is not a non-empty array of non-empty trimmed strings. The client verifies Array.isArray, length > 0, and that every element is a string whose trim() is not empty, before attaching the contexts to the network.setCacheBehavior command. This guards against empty context IDs that the remote end would reject.","triggerScenarios":"Calling setCacheBehavior('bypass', 'ctx1') (string not array), setCacheBehavior('bypass', []), setCacheBehavior('bypass', ['']), setCacheBehavior('bypass', ['   ']), or setCacheBehavior('bypass', [123]).","commonSituations":"Passing a single context id string instead of an array; reusing a variable that was filtered to empty; including whitespace-only or null context ids copied from a stale context list.","solutions":["Pass an array of one or more non-empty string context ids, e.g. setCacheBehavior('bypass', ['ctx1','ctx2']).","Filter out empty/blank ids before calling: contexts.filter(c => typeof c === 'string' && c.trim() !== '').","Pass null (the default) to apply the cache behavior globally, avoiding the contexts check."],"exampleFix":"// before\nawait network.setCacheBehavior('bypass', currentContextId) // string\n\n// after\nawait network.setCacheBehavior('bypass', [currentContextId]) // array of non-empty strings","handlingStrategy":"validation","validationCode":"function assertContexts(contexts) {\n  if (contexts === null) return null\n  if (!Array.isArray(contexts) || contexts.length === 0 ||\n      contexts.some((c) => typeof c !== 'string' || c.trim() === '')) {\n    throw new Error('contexts must be a non-empty array of non-empty strings')\n  }\n  return contexts\n}","typeGuard":"function isNonEmptyStringArray(v) {\n  return Array.isArray(v) && v.length > 0 &&\n    v.every((c) => typeof c === 'string' && c.trim() !== '')\n}","tryCatchPattern":null,"preventionTips":["Pass null to apply cache behavior globally when per-context is unneeded.","Filter context arrays to remove empty/blank ids before calling.","Always wrap a single context id in an array."],"tags":["bidi","network","cache","array-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}