{"record":{"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/c791e707eab3c13dd9a261d2479c3cc4a49a6fed/lib/websocket.js#L677-L713","documentation":"Thrown by initAsClient() at websocket.js:694-698 when the protocolVersion option is not in the supported set [8, 13] (defined at websocket.js:37). The default is 13 (the current RFC 6455 version); version 8 is retained for legacy compatibility. Any other value — including typos, strings, or stale numbers — is rejected before any network activity.","triggerScenarios":"Passing { protocolVersion: 12 } or { protocolVersion: '13' } (string) or any non-8/13 number to the WebSocket constructor's options. The includes() check at line 694 fails and the RangeError is thrown synchronously during construction (because initAsClient runs in the constructor).","commonSituations":"Mistyping the version (e.g. 12, 14); passing a string '13' instead of the number 13; copying an outdated tutorial that referenced an old draft version (e.g. HyBi-07/10); a config loader coercing the value to a string.","solutions":["Omit protocolVersion entirely — the default is 13, the current standard.","If you must set it, use the number 13: new WebSocket(url, [], { protocolVersion: 13 }).","Ensure the value is a number, not a string: Number(opts.protocolVersion), and that it equals 8 or 13."],"exampleFix":"// before\nconst ws = new WebSocket(url, [], { protocolVersion: '13' });\n\n// after\nconst ws = new WebSocket(url); // defaults to protocolVersion 13","handlingStrategy":"validation","validationCode":"const SUPPORTED = [8, 13];\nfunction normalizeProtocolVersion(opts) {\n  const v = Number(opts && opts.protocolVersion);\n  return SUPPORTED.includes(v) ? v : 13; // default to standard\n}\n// usage: new WebSocket(url, [], { protocolVersion: normalizeProtocolVersion(options) });","typeGuard":"function isSupportedProtocolVersion(v) {\n  return typeof v === 'number' && (v === 8 || v === 13);\n}","tryCatchPattern":null,"preventionTips":["Omit protocolVersion to use the default (13).","If setting it explicitly, use the number 13, never a string.","Validate config values from external sources with Number() and a [8, 13] membership check."],"tags":["websocket","client","protocolversion","configuration","rfc6455"],"backgroundTag":null,"analyzedSha":"c791e707eab3c13dd9a261d2479c3cc4a49a6fed","analyzedAt":"2026-08-06T19:07:51.047Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}