{"record":{"id":"89bde9803f532e4f","repo":"SeleniumHQ/selenium","slug":"pattern-must-be-an-instance-of-urlpattern-receive","errorCode":null,"errorMessage":"Pattern must be an instance of UrlPattern. Received: '${pattern})'","messagePattern":"Pattern must be an instance of UrlPattern\\. Received: '(.+?)\\)'","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"javascript/selenium-webdriver/bidi/addInterceptParameters.js","lineNumber":41,"sourceCode":"\n  constructor(phases) {\n    if (phases instanceof Array) {\n      phases.forEach((phase) => this.#phases.push(phase))\n    } else {\n      this.#phases.push(phases)\n    }\n  }\n\n  /**\n   * Adds a URL pattern to intercept.\n   *\n   * @param {UrlPattern} pattern - The URL pattern to add.\n   * @returns {AddInterceptParameters} - Returns the current instance of the class AddInterceptParameters for chaining.\n   * @throws {Error} - Throws an error if the pattern is not an instance of UrlPattern.\n   */\n  urlPattern(pattern) {\n    if (!(pattern instanceof UrlPattern)) {\n      throw new Error(`Pattern must be an instance of UrlPattern. Received: '${pattern})'`)\n    }\n    this.#urlPatterns.push(Object.fromEntries(pattern.asMap()))\n    return this\n  }\n\n  /**\n   * Adds array of URL patterns to intercept.\n   *\n   * @param {UrlPattern[]} patterns - An array of UrlPattern instances representing the URL patterns to intercept.\n   * @returns {AddInterceptParameters} - Returns the instance of AddInterceptParameters for chaining.\n   * @throws {Error} - Throws an error if the pattern is not an instance of UrlPattern.\n   */\n  urlPatterns(patterns) {\n    patterns.forEach((pattern) => {\n      if (!(pattern instanceof UrlPattern)) {\n        throw new Error(`Pattern must be an instance of UrlPattern. Received:'${pattern}'`)\n      }\n      this.#urlPatterns.push(Object.fromEntries(pattern.asMap()))","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/addInterceptParameters.js#L23-L59","documentation":"AddInterceptParameters.urlPattern() (WebDriver BiDi network.addIntercept) validates that the single pattern argument is an instance of the UrlPattern class from ./urlPattern. UrlPattern is the only structured-pattern type in BiDi network interception (alongside plain string patterns handled by urlStringPattern). Passing a plain object, a string, a Map, or an instance from a different module realm fails the instanceof check. The error message interpolates the received value — note the literal has a stray ')' producing `Received: '<value>)'`, a minor message bug.","triggerScenarios":"Calling addInterceptParameters.urlPattern({ protocol: 'https' }) with a plain object instead of a UrlPattern instance. Passing a string URL (should use urlStringPattern instead). Passing a UrlPattern constructed in a different Node module instance/realm where instanceof fails. Passing null/undefined.","commonSituations":"Confusing urlPattern (structured) with urlStringPattern (plain string). Copying example code that builds a raw object. Multiple copies of the selenium-webdriver package installed, causing instanceof to fail across realms. Importing UrlPattern from the wrong path.","solutions":["Construct a UrlPattern via new UrlPattern() and chain .protocol()/.hostname()/.pathname() etc. before passing it to urlPattern().","If you only have a URL string, use urlStringPattern(url) or urlStringPatterns([urls]) instead.","Ensure a single copy of selenium-webdriver is installed (dedupe node_modules) so instanceof works.","Do not pass plain objects or Map instances; only UrlPattern instances are accepted."],"exampleFix":"// before\nparams.urlPattern({ protocol: 'https', hostname: 'example.com' })\n\n// after\nconst { UrlPattern } = require('selenium-webdriver/bidi/urlPattern')\nconst pattern = new UrlPattern().protocol('https').hostname('example.com')\nparams.urlPattern(pattern)","handlingStrategy":"type-guard","validationCode":"if (!(pattern instanceof UrlPattern)) {\n  throw new TypeError('urlPattern expects a UrlPattern instance')\n}","typeGuard":"function isUrlPattern(p) {\n  return p instanceof UrlPattern\n}","tryCatchPattern":null,"preventionTips":["Always construct UrlPattern via new UrlPattern().","Use urlStringPattern() for plain string URLs.","Dedupe node_modules so instanceof resolves to one class.","Never pass plain objects or Maps."],"tags":["bidi","network","intercept","type-validation","urlpattern"],"backgroundTag":null,"analyzedSha":"aa36b38e696a0909e973bdf5e2f9031ffe842c4b","analyzedAt":"2026-08-14T02:32:32.244Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}