{"record":{"id":"4b80cae65fdbe775","repo":"SeleniumHQ/selenium","slug":"pattern-must-be-an-instance-of-urlpattern-receive-4b80ca","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":57,"sourceCode":"  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()))\n    })\n    return this\n  }\n\n  /**\n   * Adds string URL to intercept.\n   *\n   * @param {string} pattern - The URL pattern to be added.\n   * @returns {AddInterceptParameters} - Returns the instance of AddInterceptParameters for chaining..\n   * @throws {Error} - If the pattern is not an instance of String.\n   */\n  urlStringPattern(pattern) {\n    if (typeof pattern !== 'string') {\n      throw new Error(`Pattern must be an instance of String. Received:'${pattern}'`)\n    }\n","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/SeleniumHQ/selenium/blob/aa36b38e696a0909e973bdf5e2f9031ffe842c4b/javascript/selenium-webdriver/bidi/addInterceptParameters.js#L39-L75","documentation":"AddInterceptParameters.urlPatterns() iterates an array and validates each entry is an instance of UrlPattern. This is the batch variant of urlPattern(): any non-UrlPattern element in the array throws. The error message is slightly different from the single-pattern variant (no stray ')'), confirming these are two distinct throw sites.","triggerScenarios":"Calling urlPatterns([{ protocol: 'https' }, ...]) with plain objects. Mixing UrlPattern instances and strings in the array (strings should go via urlStringPatterns). Passing an array containing null/undefined. Cross-realm UrlPattern instances where instanceof fails.","commonSituations":"Building the array from user/config data as plain objects. Mixing pattern types in one call instead of separating structured vs string patterns. Duplicate selenium-webdriver installs causing instanceof realm mismatch.","solutions":["Ensure every array element is a UrlPattern instance built via new UrlPattern().","Separate structured patterns (urlPatterns) from string URLs (urlStringPatterns) into the correct method.","Dedupe node_modules so instanceof resolves against one UrlPattern class.","Filter out null/undefined entries before calling."],"exampleFix":"// before\nparams.urlPatterns([\n  { protocol: 'https', hostname: 'a.com' },\n  { protocol: 'https', hostname: 'b.com' },\n])\n\n// after\nconst mk = (h) => new UrlPattern().protocol('https').hostname(h)\nparams.urlPatterns([mk('a.com'), mk('b.com')])","handlingStrategy":"validation","validationCode":"if (!Array.isArray(patterns)) throw new TypeError('urlPatterns expects an array')\npatterns.forEach((p) => {\n  if (!(p instanceof UrlPattern)) throw new TypeError('Each pattern must be a UrlPattern')\n})","typeGuard":"function areUrlPatterns(arr) {\n  return Array.isArray(arr) && arr.every((p) => p instanceof UrlPattern)\n}","tryCatchPattern":null,"preventionTips":["Build every array element via new UrlPattern().","Separate structured patterns (urlPatterns) from strings (urlStringPatterns).","Dedupe node_modules to avoid realm instanceof failures.","Filter null/undefined entries before calling."],"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"}