{"record":{"id":"e35497c7a6606fb1","repo":"denoland/deno","slug":"expected-data-to-be-a-string-buffer-uint8array-e35497","errorCode":null,"errorMessage":"Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer","messagePattern":"Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"ext/node/polyfills/inspector_network_bridge.js","lineNumber":54,"sourceCode":"      TypedArrayPrototypeGetByteLength(buf),\n    );\n  }\n  if (TypedArrayPrototypeGetSymbolToStringTag(data) === \"Uint8Array\") {\n    return op_base64_encode_from_buffer(\n      data,\n      0,\n      TypedArrayPrototypeGetByteLength(data),\n    );\n  }\n  if (ObjectPrototypeIsPrototypeOf(ArrayBufferPrototype, data)) {\n    const view = new Uint8Array(data);\n    return op_base64_encode_from_buffer(\n      view,\n      0,\n      TypedArrayPrototypeGetByteLength(view),\n    );\n  }\n  throw new TypeError(\n    \"Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer\",\n  );\n}\n\nfunction emit(eventName, params) {\n  op_inspector_emit_protocol_event(eventName, JSONStringify(params ?? {}));\n}\n\nfunction emitWithData(eventName, params) {\n  if (params && params.data !== undefined) {\n    const encoded = encodeNetworkData(params.data);\n    if (encoded !== params.data) {\n      params = ObjectAssign({ __proto__: null }, params, { data: encoded });\n    }\n  }\n  emit(eventName, params);\n}\n","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/denoland/deno/blob/9ad36f7a2cce60488e6ec52283efb32efddaf93a/ext/node/polyfills/inspector_network_bridge.js#L36-L72","documentation":"The inspector network bridge (inspector_network_bridge.js) base64-encodes params.data before emitting network-domain protocol events (the emitWithData path that forwards data to the DevTools front-end). The data must be a string, a non-DataView typed array (Buffer/Uint8Array), or an ArrayBuffer; anything else (plain object, number, boolean, null, DataView) reaches a plain TypeError with no err.code.","triggerScenarios":"Broadcasting a network event whose params.data is a plain object or number — e.g. emitWithData('Network.dataReceived', { requestId, data: parsedJson }) — or a DataView holding the body bytes.","commonSituations":"Translating CDP payloads between JSON and binary representations; passing decoded objects where the raw body (string or bytes) is expected by the front-end.","solutions":["Pass bodies as string or Uint8Array; stringify anything else with JSON.stringify().","Convert DataView via new Uint8Array(dv.buffer, dv.byteOffset, dv.byteLength).","When catching, match on the TypeError message text — there is no code property."],"exampleFix":"// before\nemitWithData('Network.dataReceived', { requestId, data: { length: 1024 } });\n// TypeError: Expected data to be a string, Buffer, Uint8Array, or ArrayBuffer\n\n// after\nemitWithData('Network.dataReceived', { requestId, data: JSON.stringify({ length: 1024 }) });","handlingStrategy":"type-guard","validationCode":"function encodeNetworkData(data) {\n  if (typeof data === 'string') return data;\n  if (ArrayBuffer.isView(data) && !(data instanceof DataView)) return data;\n  if (data instanceof ArrayBuffer) return new Uint8Array(data);\n  return JSON.stringify(data);\n}\nemitWithData('Network.dataReceived', { requestId, data: encodeNetworkData(body) });","typeGuard":"function isNetworkEncodable(v) {\n  return typeof v === 'string' || v instanceof ArrayBuffer ||\n    (ArrayBuffer.isView(v) && !(v instanceof DataView));\n}","tryCatchPattern":null,"preventionTips":["Pass network-domain data as string or Uint8Array; stringify everything else.","Do not hand DataView instances to the bridge — convert to Uint8Array first.","This is a plain TypeError with no code; catch on message text if you must."],"tags":["inspector","network","type-error","internal-api","node-compat"],"backgroundTag":"invalid-argument-type","analyzedSha":"9ad36f7a2cce60488e6ec52283efb32efddaf93a","analyzedAt":"2026-08-20T13:07:44.778Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}