{"id":"9f50abe17f43cfa1","repo":"websockets/ws","slug":"unsupported-protocol-version-opts-protocolversi","errorCode":null,"errorMessage":"Unsupported protocol version: ${opts.protocolVersion} (supported versions: ${protocolVersions.join(', ')})","messagePattern":"Unsupported protocol version: (.+?) \\(supported versions: (.+?)\\)","errorType":"exception","errorClass":"RangeError","httpStatus":null,"severity":"error","filePath":"lib/websocket.js","lineNumber":695,"sourceCode":"    perMessageDeflate: true,\n    followRedirects: false,\n    maxRedirects: 10,\n    ...options,\n    socketPath: undefined,\n    hostname: undefined,\n    protocol: undefined,\n    timeout: undefined,\n    method: 'GET',\n    host: undefined,\n    path: undefined,\n    port: undefined\n  };\n\n  websocket._autoPong = opts.autoPong;\n  websocket._closeTimeout = opts.closeTimeout;\n\n  if (!protocolVersions.includes(opts.protocolVersion)) {\n    throw new RangeError(\n      `Unsupported protocol version: ${opts.protocolVersion} ` +\n        `(supported versions: ${protocolVersions.join(', ')})`\n    );\n  }\n\n  let parsedUrl;\n\n  if (address instanceof URL) {\n    parsedUrl = address;\n  } else {\n    try {\n      parsedUrl = new URL(address);\n    } catch {\n      throw new SyntaxError(`Invalid URL: ${address}`);\n    }\n  }\n\n  if (parsedUrl.protocol === 'http:') {","sourceCodeStart":677,"sourceCodeEnd":713,"githubUrl":"https://github.com/websockets/ws/blob/ae1de54330cef77e487548890fabfeb9aae1d83d/lib/websocket.js#L677-L713","documentation":"Thrown by initAsClient() (lib/websocket.js:694-699) when the protocolVersion option is not one of the supported values defined in the protocolVersions array ([8, 13]). The default is 13 (the current RFC 6455 version); version 8 is a legacy HyBi working-draft version still accepted. Any other value is rejected with RangeError before any network activity.","triggerScenarios":"Constructing a client with new WebSocket(url, protocols, { protocolVersion: X }) where X is not 8 or 13, e.g. 12, 7, '13' (string), or undefined coalescing to a bad value.","commonSituations":"Typing protocolVersion: 12 thinking it is a minor version; passing a string '13' instead of number 13; copy-pasting options across libraries with a different version scheme; bugs where a config value defaults to a non-version sentinel.","solutions":["Use the default (omit protocolVersion) which is 13, the current standard.","If you genuinely need legacy HyBi-08, set protocolVersion: 8 explicitly as a number.","Validate the option type and value before constructing the client."],"exampleFix":"// before\nnew WebSocket(url, [], { protocolVersion: 12 });\n\n// after\nnew WebSocket(url, [], { protocolVersion: 13 }); // or simply omit it","handlingStrategy":"validation","validationCode":"const SUPPORTED = new Set([8, 13]);\nfunction resolveProtocolVersion(opts) {\n  const v = (opts && opts.protocolVersion) || 13;\n  if (!SUPPORTED.has(v)) {\n    throw new RangeError(`Unsupported protocolVersion ${v}; use 8 or 13`);\n  }\n  return v;\n}","typeGuard":"function isSupportedProtocolVersion(v) {\n  return v === 8 || v === 13;\n}","tryCatchPattern":"try {\n  new WebSocket(url, protocols, opts);\n} catch (err) {\n  if (/Unsupported protocol version/.test(err.message)) {\n    new WebSocket(url, protocols, { ...opts, protocolVersion: 13 });\n  } else {\n    throw err;\n  }\n}","preventionTips":["Omit protocolVersion to use the default 13.","Only set protocolVersion: 8 for genuine legacy HyBi-08 peers.","Validate the option is a number and is in {8, 13} before constructing."],"tags":["websocket","client","configuration","protocol-version"],"analyzedSha":"ae1de54330cef77e487548890fabfeb9aae1d83d","analyzedAt":"2026-08-03T19:11:18.437Z","schemaVersion":2}