{"record":{"id":"3698fc17f5af4f41","repo":"websockets/ws","slug":"unexpected-or-invalid-parameter-client-max-window","errorCode":null,"errorMessage":"Unexpected or invalid parameter \"client_max_window_bits\"","messagePattern":"Unexpected or invalid parameter \"client_max_window_bits\"","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"lib/permessage-deflate.js","lineNumber":231,"sourceCode":"    const params = response[0];\n\n    if (\n      this._options.clientNoContextTakeover === false &&\n      params.client_no_context_takeover\n    ) {\n      throw new Error('Unexpected parameter \"client_no_context_takeover\"');\n    }\n\n    if (!params.client_max_window_bits) {\n      if (typeof this._options.clientMaxWindowBits === 'number') {\n        params.client_max_window_bits = this._options.clientMaxWindowBits;\n      }\n    } else if (\n      this._options.clientMaxWindowBits === false ||\n      (typeof this._options.clientMaxWindowBits === 'number' &&\n        params.client_max_window_bits > this._options.clientMaxWindowBits)\n    ) {\n      throw new Error(\n        'Unexpected or invalid parameter \"client_max_window_bits\"'\n      );\n    }\n\n    return params;\n  }\n\n  /**\n   * Normalize parameters.\n   *\n   * @param {Array} configurations The extension negotiation offers/reponse\n   * @return {Array} The offers/response with normalized parameters\n   * @private\n   */\n  normalizeParams(configurations) {\n    configurations.forEach((params) => {\n      Object.keys(params).forEach((key) => {\n        let value = params[key];","sourceCodeStart":213,"sourceCodeEnd":249,"githubUrl":"https://github.com/websockets/ws/blob/c791e707eab3c13dd9a261d2479c3cc4a49a6fed/lib/permessage-deflate.js#L213-L249","documentation":"Thrown by `PerMessageDeflate.acceptAsClient()` when the server's permessage-deflate response contains a `client_max_window_bits` value the client cannot accept: either the client set `clientMaxWindowBits: false` (it does not want this parameter) but the server sent one, or the server sent a value larger than the number the client advertised (`params.client_max_window_bits > clientMaxWindowBits`). RFC 7692 forbids the server from raising the window above the client's offer.","triggerScenarios":"Client created with `new WebSocket(url, { perMessageDeflate: { clientMaxWindowBits: 10 } })` against a server that responds with `client_max_window_bits: 15`; or a client with `clientMaxWindowBits: false` against a server that includes the parameter anyway.","commonSituations":"Server bug/proxy that inflates the window size in the response; mismatched compression policies across a load balancer; a peer that does not honor RFC 7692 negotiation rules.","solutions":["Match the client's `clientMaxWindowBits` to (or above) what the server will respond with, or omit it to advertise the default.","Fix the server so it never responds with a `client_max_window_bits` larger than the client's offer.","Disable compression on the client (`perMessageDeflate: false`) if the server cannot be changed."],"exampleFix":"// before\nconst ws = new WebSocket(url, {\n  perMessageDeflate: { clientMaxWindowBits: 10 }\n});\n// server responds with client_max_window_bits=15 -> throws\n\n// after\nconst ws = new WebSocket(url, {\n  perMessageDeflate: { clientMaxWindowBits: 15 }\n});","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  perMessageDeflate.accept(serverResponseOffers);\n} catch (err) {\n  if (/client_max_window_bits/.test(err.message)) {\n    // Server's window-size response is incompatible with the client's offer.\n    reconnectWithoutCompression(url);\n    return;\n  }\n  throw err;\n}","preventionTips":["Either omit `clientMaxWindowBits` on the client (advertise the default) or set it to a value the server will accept.","Ensure the server never responds with a window larger than the client's offer (RFC 7692).","Have a `perMessageDeflate: false` fallback path when the server is non-conformant."],"tags":["websocket","compression","permessage-deflate","negotiation","handshake","client","rfc7692"],"backgroundTag":null,"analyzedSha":"c791e707eab3c13dd9a261d2479c3cc4a49a6fed","analyzedAt":"2026-08-06T19:07:51.047Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}