{"record":{"id":"695d9ed5e5a13da0","repo":"SeleniumHQ/selenium","slug":"params-must-be-an-instance-of-addinterceptparamete","errorCode":null,"errorMessage":"Params must be an instance of AddInterceptParameters. Received:'${params}'","messagePattern":"Params must be an instance of AddInterceptParameters\\. Received:'(.+?)'","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/network.js","lineNumber":203,"sourceCode":"            params.errorText,\n          )\n        }\n        this.invokeCallbacks(eventType, response)\n      }\n    })\n    return id\n  }\n\n  /**\n   * Adds a network intercept.\n   *\n   * @param {AddInterceptParameters} params - The parameters for the network intercept.\n   * @returns {Promise<string>} - A promise that resolves to the added intercept's id.\n   * @throws {Error} - If params is not an instance of AddInterceptParameters.\n   */\n  async addIntercept(params) {\n    if (!(params instanceof AddInterceptParameters)) {\n      throw new Error(`Params must be an instance of AddInterceptParameters. Received:'${params}'`)\n    }\n\n    const command = {\n      method: 'network.addIntercept',\n      params: Object.fromEntries(params.asMap()),\n    }\n\n    let response = await this.bidi.send(command)\n\n    return response.result.intercept\n  }\n\n  /**\n   * Removes an intercept.\n   *\n   * @param {string} interceptId - The ID of the intercept to be removed.\n   * @returns {Promise<void>} - A promise that resolves when the intercept is successfully removed.\n   */","sourceCodeStart":185,"sourceCodeEnd":221,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/network.js#L185-L221","documentation":"Thrown by Network.addIntercept() when the params argument is not an instance of the AddInterceptParameters class. The method serializes the params via params.asMap() to build the network.addIntercept BiDi command, so it requires the exact class to guarantee the payload shape. A plain object, string, or any other type is rejected because it lacks the asMap() contract.","triggerScenarios":"Calling network.addIntercept({...}) with a literal object, calling addIntercept('phase:beforeRequestSent'), calling addIntercept(undefined), or passing a ContinueRequestParameters/ProvideResponseParameters object by mistake.","commonSituations":"Copying example code that built a raw object before the Parameters API existed; passing the wrong parameter class when chaining several network calls; forgetting to import AddInterceptParameters and substituting a plain object.","solutions":["Construct and pass an AddInterceptParameters instance: import { AddInterceptParameters } and call new AddInterceptParameters().phases([...]).intercepts([...]) before network.addIntercept(params).","Confirm the import path matches the class instance type at runtime (instanceof relies on the same class reference, not a structurally identical copy).","If you have a plain object, translate it into an AddInterceptParameters instance rather than passing it directly."],"exampleFix":"// before\nawait network.addIntercept({ phases: ['beforeRequestSent'], urlPatterns: [...] })\n\n// after\nconst { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters')\nconst params = new AddInterceptParameters()\n  .phases([Network.Phase.BEFORE_REQUEST_SENT])\n  .urlPatterns([...])\nawait network.addIntercept(params)","handlingStrategy":"type-guard","validationCode":"if (!(params instanceof AddInterceptParameters)) {\n  throw new TypeError('addIntercept requires AddInterceptParameters')\n}","typeGuard":"function isAddInterceptParameters(v) {\n  return v instanceof AddInterceptParameters\n}","tryCatchPattern":"try {\n  await network.addIntercept(params)\n} catch (e) {\n  if (/instance of AddInterceptParameters/.test(e.message)) {\n    // rebuild params as AddInterceptParameters\n  } else throw e\n}","preventionTips":["Always construct AddInterceptParameters via its builder; never pass plain objects.","Keep a single import for AddInterceptParameters to avoid duplicate class references that break instanceof.","Use TypeScript/JSDoc types so the editor flags plain-object arguments."],"tags":["bidi","network","intercept","type-validation","javascript"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}