{"record":{"id":"7455765f45dd0929","repo":"mozilla/pdf.js","slug":"cannot-create-sandbox","errorCode":null,"errorMessage":"Cannot create sandbox.","messagePattern":"Cannot create sandbox\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"web/firefoxcom.js","lineNumber":254,"sourceCode":"  })();\n}\n\nclass FirefoxComDataRangeTransport extends PDFDataRangeTransport {\n  requestDataRange(begin, end) {\n    FirefoxCom.request(\"requestDataRange\", { begin, end });\n  }\n\n  // NOTE: This method is currently not invoked in the Firefox PDF Viewer.\n  abort() {\n    FirefoxCom.request(\"abortLoading\", null);\n  }\n}\n\nclass FirefoxScripting {\n  static async createSandbox(data) {\n    const success = await FirefoxCom.requestAsync(\"createSandbox\", data);\n    if (!success) {\n      throw new Error(\"Cannot create sandbox.\");\n    }\n  }\n\n  static async dispatchEventInSandbox(event) {\n    FirefoxCom.request(\"dispatchEventInSandbox\", event);\n  }\n\n  static async destroySandbox() {\n    FirefoxCom.request(\"destroySandbox\", null);\n  }\n}\n\nclass MLManager {\n  #abortSignal = null;\n\n  #enabled = null;\n\n  #eventBus = null;","sourceCodeStart":236,"sourceCodeEnd":272,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/web/firefoxcom.js#L236-L272","documentation":"Thrown by FirefoxScripting.createSandbox when the host Firefox process returns a falsy value from the async 'createSandbox' request. It signals that the browser-side sandbox (used to execute interactive PDF JavaScript for form calculation/validation) could not be initialized. This code path only runs inside the Firefox PDF Viewer (MOZCENTRAL build), not in the generic web build.","triggerScenarios":"Calling FirefoxScripting.createSandbox(data) where FirefoxCom.requestAsync('createSandbox', data) resolves to a falsy value (false/undefined/null). This happens when the host chrome-privileged handler rejects or fails to set up the sandbox for an interactive PDF with JavaScript actions.","commonSituations":"Opening a PDF with AcroForm/JavaScript actions in a Firefox build where the scripting host is unavailable, disabled, or where the data payload (sandbox configuration) is malformed. Also seen during Firefox version mismatches where the host message contract changed.","solutions":["Verify the PDF actually requires a scripting sandbox; if it has no JS actions the failure is benign and can be ignored.","Ensure the Firefox host (browser chrome) handles 'createSandbox' requests and is the correct MOZCENTRAL build matching this pdf.js version.","If building/embedding, confirm the data object passed to createSandbox is the serialized sandbox settings the host expects.","Catch the error in the dispatch layer and degrade gracefully (forms render without JS-driven behaviors)."],"exampleFix":"// before\nawait FirefoxScripting.createSandbox(data);\n\n// after - guard host availability and degrade gracefully\ntry {\n  await FirefoxScripting.createSandbox(data);\n} catch (e) {\n  console.warn('Sandbox unavailable; interactive JS disabled:', e.message);\n}","handlingStrategy":"try-catch","validationCode":"// Cannot validate host availability from JS; guard the call site.\nconst canCreateSandbox = typeof FirefoxCom !== 'undefined' && typeof FirefoxCom.requestAsync === 'function';","typeGuard":"function isSandboxCapable(host) {\n  return host && typeof host.requestAsync === 'function';\n}","tryCatchPattern":"try {\n  await FirefoxScripting.createSandbox(data);\n} catch (e) {\n  if (e.message === 'Cannot create sandbox.') {\n    // Degrade: render forms without JS execution.\n    console.warn('PDF scripting sandbox unavailable.');\n  } else {\n    throw e;\n  }\n}","preventionTips":["Only invoke createSandbox for PDFs known to contain JavaScript actions.","Run inside the matching MOZCENTRAL/Firefox build that hosts the sandbox.","Log and continue rather than failing the whole viewer when scripting is optional."],"tags":["firefox","scripting","sandbox","mozcentral","forms"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}