{"record":{"id":"a48480a32a809586","repo":"PaddlePaddle/PaddleOCR","slug":"paddleocr-js-requires-an-http-s-origin-so-model-a","errorCode":null,"errorMessage":"PaddleOCR.js requires an HTTP(S) origin so model assets can be fetched.","messagePattern":"PaddleOCR\\.js requires an HTTP\\(S\\) origin so model assets can be fetched\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"paddleocr-js/packages/core/src/platform/browser.ts","lineNumber":29,"sourceCode":"  width: number;\n  height: number;\n  mat: Mat;\n  dispose(): void;\n}\n\nexport interface WorkerPayload {\n  kind: \"imageBitmap\";\n  imageBitmap: ImageBitmap;\n}\n\nexport interface WorkerPayloadResult {\n  payload: WorkerPayload;\n  transferables: Transferable[];\n}\n\nexport function ensureServedFromHttp(): void {\n  if (globalThis.location.protocol === \"file:\") {\n    throw new Error(\"PaddleOCR.js requires an HTTP(S) origin so model assets can be fetched.\");\n  }\n}\n\nfunction hasDomConstructor(name: string): boolean {\n  return typeof (globalThis as Record<string, unknown>)[name] !== \"undefined\";\n}\n\nexport async function sourceToImageBitmap(source: ImageSource): Promise<ImageBitmap> {\n  if (typeof ImageBitmap !== \"undefined\" && source instanceof ImageBitmap) return source;\n  if (source instanceof Blob) return createImageBitmap(source);\n  if (hasDomConstructor(\"HTMLCanvasElement\") && source instanceof HTMLCanvasElement) {\n    return createImageBitmap(source);\n  }\n  if (source instanceof ImageData) {\n    const canvas = document.createElement(\"canvas\");\n    canvas.width = source.width;\n    canvas.height = source.height;\n    const ctx = canvas.getContext(\"2d\");","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr-js/packages/core/src/platform/browser.ts#L11-L47","documentation":"The browser platform guard ensureServedFromHttp() checks globalThis.location.protocol and throws when it is 'file:'. Model assets (ONNX weights, configs) must be fetched over HTTP(S); under the file: protocol fetch is blocked or unreliable due to browser security rules (CORS/opaque origins), so the library refuses to continue.","triggerScenarios":"Opening an HTML page directly from disk (file:///C:/...index.html) that calls PaddleOCR.create() or predict(); local demos opened by double-clicking instead of serving.","commonSituations":"Quick local testing without a dev server; Electron apps loading content via file:// without a custom protocol; distributable HTML attachments opened from the filesystem.","solutions":["Serve the app over HTTP: npx serve, python -m http.server, or your bundler dev server.","In Electron, load content via http(s) or a custom app:// protocol registered as standard/secure.","For static demos, use a hosting provider or GitHub Pages."],"exampleFix":"# before\nopen index.html  # file:// URL -> throws\n\n# after\nnpx serve .\n# then open http://localhost:3000","handlingStrategy":"validation","validationCode":"// Refuse to boot the OCR app from file://\nif (typeof location !== 'undefined' && location.protocol === 'file:') {\n  showBanner('Serve this app over http(s) — e.g. `npx serve .` — model downloads require an HTTP origin.');\n}","typeGuard":"function isHttpOrigin(): boolean {\n  return typeof globalThis.location === 'undefined' || globalThis.location.protocol !== 'file:';\n}","tryCatchPattern":"try {\n  const ocr = await PaddleOCR.create();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('HTTP(S) origin')) {\n    showUserError('Please open this page via a local web server, not by double-clicking the HTML file.');\n    return;\n  }\n  throw e;\n}","preventionTips":["Always develop/test through a dev server (vite serve, npx serve) rather than opening HTML from disk.","In Electron, register a standard secure protocol (app://) instead of loading file:// pages."],"tags":["environment","browser","file-protocol","http","cors"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}