{"record":{"id":"fa704bd53dabe5db","repo":"denoland/deno","slug":"invalid-webassembly-content-type","errorCode":null,"errorMessage":"Invalid WebAssembly content type","messagePattern":"Invalid WebAssembly content type","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/fetch/26_fetch.js","lineNumber":1028,"sourceCode":"  try {\n    const res = webidl.converters[\"Response\"](\n      source,\n      \"Failed to execute 'WebAssembly.compileStreaming'\",\n      \"Argument 1\",\n    );\n\n    // 2.3.\n    // The spec is ambiguous here, see\n    // https://github.com/WebAssembly/spec/issues/1138. The WPT tests expect\n    // the raw value of the Content-Type attribute lowercased. We ignore this\n    // for file:// because file fetches don't have a Content-Type.\n    if (!StringPrototypeStartsWith(res.url, \"file://\")) {\n      const contentType = res.headers.get(\"Content-Type\");\n      if (\n        typeof contentType !== \"string\" ||\n        StringPrototypeToLowerCase(contentType) !== \"application/wasm\"\n      ) {\n        throw new TypeError(\"Invalid WebAssembly content type\");\n      }\n    }\n\n    // 2.5.\n    if (!res.ok) {\n      throw new TypeError(\n        `Failed to receive WebAssembly content: HTTP status code ${res.status}`,\n      );\n    }\n\n    // Pass the resolved URL to v8.\n    op_wasm_streaming_set_url(rid, res.url);\n\n    if (res.body !== null) {\n      // 2.6.\n      // Rather than consuming the body as an ArrayBuffer, this feeds each chunk\n      // to the streaming compiler as soon as it's available. Instead of reading\n      // the body chunk-by-chunk in JS and calling `op_wasm_streaming_feed` once","sourceCodeStart":1010,"sourceCodeEnd":1046,"githubUrl":"https://github.com/denoland/deno/blob/a961cdec3b1948844414ebeecc697dcad76df2d1/ext/fetch/26_fetch.js#L1010-L1046","documentation":"WebAssembly.instantiateStreaming() and compileStreaming() require the response's Content-Type header to be exactly application/wasm (compared lowercased, so any parameter suffix such as '; charset=utf-8' fails). Deno exempts file:// URLs because local file fetches carry no Content-Type.","triggerScenarios":"WebAssembly.instantiateStreaming(fetch('/module.wasm')) when the server replies with application/octet-stream, text/plain, application/wasm; charset=utf-8, or omits the header; serving .wasm from a dev server without a wasm mime mapping; passing a blob: or data: response lacking the header.","commonSituations":"Static file servers (python -m http.server, naive SPA hosts) that default .wasm to octet-stream; CDN misconfiguration; middleware rewriting headers and adding charset; fixtures served from memory without headers.","solutions":["Configure the server/CDN to send exactly 'Content-Type: application/wasm' for .wasm files, with no parameters","If you cannot change the header, use the non-streaming API: WebAssembly.instantiate(await (await fetch(url)).arrayBuffer())","For local files use fetch('file:///...wasm') (exempt from the check) or Deno.readFile + non-streaming compile"],"exampleFix":"// before\nconst mod = await WebAssembly.instantiateStreaming(fetch(\"/app.wasm\"));\n\n// after (server header cannot be fixed)\nconst res = await fetch(\"/app.wasm\");\nconst mod = await WebAssembly.instantiate(await res.arrayBuffer());","handlingStrategy":"validation","validationCode":"const res = await fetch(url);\nconst ct = (res.headers.get(\"content-type\") ?? \"\").toLowerCase();\nif (ct === \"application/wasm\") {\n  result = await WebAssembly.instantiateStreaming(res);\n} else {\n  result = await WebAssembly.instantiate(await res.arrayBuffer());\n}","typeGuard":null,"tryCatchPattern":"try {\n  mod = await WebAssembly.instantiateStreaming(res);\n} catch (err) {\n  if (err instanceof TypeError && err.message === \"Invalid WebAssembly content type\") {\n    mod = await WebAssembly.instantiate(await res.arrayBuffer());\n  } else throw err;\n}","preventionTips":["Verify with curl -I that .wasm responses send exactly application/wasm","Keep the Content-Type header free of parameters like charset","Default to the buffer-based (non-streaming) compile when you do not control headers"],"tags":["webassembly","fetch","content-type","streaming-compile"],"backgroundTag":"wasm-content-type-mismatch","analyzedSha":"a961cdec3b1948844414ebeecc697dcad76df2d1","analyzedAt":"2026-08-20T13:07:44.778Z","contentChangedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}