{"record":{"id":"a847db7f4a41e986","repo":"mozilla/pdf.js","slug":"invalid-pdf-binary-data-either-typedarray-string","errorCode":null,"errorMessage":"Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property.","messagePattern":"Invalid PDF binary data: either TypedArray, string, or array-like object is expected in the data property\\.","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"src/display/api_utils.js","lineNumber":85,"sourceCode":"    );\n  }\n  if (val instanceof Uint8Array && val.byteLength === val.buffer.byteLength) {\n    // Use the data as-is when it's already a Uint8Array that completely\n    // \"utilizes\" its underlying ArrayBuffer, to prevent any possible\n    // issues when transferring it to the worker-thread.\n    return val;\n  }\n  if (typeof val === \"string\") {\n    return stringToBytes(val);\n  }\n  if (\n    val instanceof ArrayBuffer ||\n    ArrayBuffer.isView(val) ||\n    (typeof val === \"object\" && !isNaN(val?.length))\n  ) {\n    return new Uint8Array(val);\n  }\n  throw new Error(\n    \"Invalid PDF binary data: either TypedArray, \" +\n      \"string, or array-like object is expected in the data property.\"\n  );\n}\n\nfunction getFactoryUrlProp(val) {\n  if (typeof val !== \"string\") {\n    return null;\n  }\n  if (val.endsWith(\"/\")) {\n    return val;\n  }\n  throw new Error(`Invalid factory url: \"${val}\" must include trailing slash.`);\n}\n\nconst isRefProxy = v =>\n  typeof v === \"object\" &&\n  Number.isInteger(v?.num) &&","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/api_utils.js#L67-L103","documentation":"Thrown by getDataProp when the 'data' property of getDocument() is not a string, ArrayBuffer, TypedArray, or array-like object with a numeric length. PDF.js needs raw bytes to send to the worker; values that are none of the accepted shapes cannot be coerced and are rejected.","triggerScenarios":"getDocument({ data: 42 }), getDocument({ data: true }), getDocument({ data: {} }) (plain object without .length), getDocument({ data: Promise }) or any non-array-like value.","commonSituations":"Passing a Blob or File directly (must be arrayBuffer()'d first); passing a JSON object; passing a ReadableStream; assuming fetch().then(r => r.body) can be used as data.","solutions":["Convert the source to a Uint8Array first: const data = new Uint8Array(await blob.arrayBuffer()).","For fetch responses use response.bytes() or new Uint8Array(await response.arrayBuffer()).","For raw bytes use a Uint8Array covering its full ArrayBuffer."],"exampleFix":"// before\nconst res = await fetch(url);\ngetDocument({ data: await res.blob() });\n\n// after\nconst res = await fetch(url);\ngetDocument({ data: new Uint8Array(await res.arrayBuffer()) });","handlingStrategy":"validation","validationCode":"async function toBytes(src) {\n  if (src instanceof Uint8Array) return src;\n  if (src instanceof ArrayBuffer || ArrayBuffer.isView(src)) return new Uint8Array(src);\n  if (typeof src === 'string') return new TextEncoder().encode(src);\n  if (src && typeof src.arrayBuffer === 'function') return new Uint8Array(await src.arrayBuffer());\n  throw new TypeError('Unsupported data type');\n}\ngetDocument({ data: await toBytes(raw) });","typeGuard":"const isAcceptableData = (v): boolean =>\n  v instanceof Uint8Array ||\n  v instanceof ArrayBuffer ||\n  ArrayBuffer.isView(v) ||\n  typeof v === 'string' ||\n  (!!v && typeof v.length === 'number');","tryCatchPattern":"null","preventionTips":["Always arrayBuffer() Blobs/Files before passing as data.","Centralize byte-conversion in one helper used for every load.","Type getDocument's data as Uint8Array in your wrappers."],"tags":["getdocument","binary-data","validation"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}