{"record":{"id":"69d05bf46aec26c0","repo":"OrchardCMS/OrchardCore","slug":"withcredentials-option-was-not-a-boolean-or-undefined-value","errorCode":null,"errorMessage":"withCredentials option was not a 'boolean' or 'undefined' value","messagePattern":"withCredentials option was not a 'boolean' or 'undefined' value","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/OrchardCore.Modules/OrchardCore.SignalR/wwwroot/Scripts/signalr.js","lineNumber":2700,"sourceCode":"\n\nconst MAX_REDIRECTS = 100;\n/** @private */\nclass HttpConnection {\n    constructor(url, options = {}) {\n        this._stopPromiseResolver = () => { };\n        this.features = {};\n        this._negotiateVersion = 1;\n        Arg.isRequired(url, \"url\");\n        this._logger = createLogger(options.logger);\n        this.baseUrl = this._resolveUrl(url);\n        options = options || {};\n        options.logMessageContent = options.logMessageContent === undefined ? false : options.logMessageContent;\n        if (typeof options.withCredentials === \"boolean\" || options.withCredentials === undefined) {\n            options.withCredentials = options.withCredentials === undefined ? true : options.withCredentials;\n        }\n        else {\n            throw new Error(\"withCredentials option was not a 'boolean' or 'undefined' value\");\n        }\n        options.timeout = options.timeout === undefined ? 100 * 1000 : options.timeout;\n        let webSocketModule = null;\n        let eventSourceModule = null;\n        if (Platform.isNode && \"function\" !== \"undefined\") {\n            // In order to ignore the dynamic require in webpack builds we need to do this magic\n            // @ts-ignore: TS doesn't know about these names\n            const requireFunc =  true ? require : 0;\n            webSocketModule = requireFunc(\"ws\");\n            eventSourceModule = requireFunc(\"eventsource\");\n        }\n        if (!Platform.isNode && typeof WebSocket !== \"undefined\" && !options.WebSocket) {\n            options.WebSocket = WebSocket;\n        }\n        else if (Platform.isNode && !options.WebSocket) {\n            if (webSocketModule) {\n                options.WebSocket = webSocketModule;\n            }","sourceCodeStart":2682,"sourceCodeEnd":2718,"githubUrl":"https://github.com/OrchardCMS/OrchardCore/blob/4306c0717fe573f6fca1b4955909ddab6a192807/src/OrchardCore.Modules/OrchardCore.SignalR/wwwroot/Scripts/signalr.js#L2682-L2718","documentation":"HttpConnection options validation throws this when the withCredentials option is provided but is not a boolean or undefined. The library defaults withCredentials to true, but any explicitly wrong-typed value (string, number, object) is rejected at connection construction rather than coerced.","triggerScenarios":"Passing { withCredentials: \"true\" } or { withCredentials: 1 } to withUrl(url, options), or building options from parsed JSON/config where the value arrives as a string instead of a boolean.","commonSituations":"Reading options from query-string/config JSON where booleans deserialize as strings; copying option objects between HTTP libraries with different coercion rules; typos like withCredentials: 'false'.","solutions":["Pass a real boolean: withCredentials: true or withCredentials: false.","Coerce config values before use with Boolean(value) or value === \"true\".","Omit the option entirely to accept the default (true).","Fix the serialization layer so booleans survive JSON parsing as booleans."],"exampleFix":"// before\nnew signalR.HubConnectionBuilder()\n  .withUrl(\"/hub\", { withCredentials: \"true\" }) // throws\n  .build();\n// after\nconst raw = getConfig(\"withCredentials\");\nnew signalR.HubConnectionBuilder()\n  .withUrl(\"/hub\", { withCredentials: raw === undefined ? undefined : raw === true || raw === \"true\" })\n  .build();","handlingStrategy":"type-guard","validationCode":"function assertWithCredentials(v) {\n  if (v !== undefined && typeof v !== \"boolean\") {\n    throw new TypeError(`withCredentials must be boolean, got ${typeof v}`);\n  }\n}","typeGuard":"function isWithCredentialsValid(v) {\n  return v === undefined || typeof v === \"boolean\";\n}","tryCatchPattern":"try {\n  const conn = builder.withUrl(url, { withCredentials }).build();\n} catch (err) {\n  if (err.message.includes(\"withCredentials option\")) {\n    console.error(\"withCredentials must be a boolean — check config parsing\");\n  } else { throw err; }\n}","preventionTips":["Keep SignalR option objects defined in code, not parsed from strings.","Coerce config booleans explicitly (=== \"true\") before passing options.","Use TypeScript so withCredentials is typed as boolean | undefined.","Add a unit test that builds the connection from your real config source."],"tags":["signalr","type-mismatch","options-validation","cors"],"backgroundTag":"type-mismatch","analyzedSha":"4306c0717fe573f6fca1b4955909ddab6a192807","analyzedAt":"2026-09-13T17:41:05.024Z","contentChangedAt":"2026-09-13T17:41:05.024Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}