mozilla/pdf.js · error · Error
doc.dataObjects is read-only
Error message
doc.dataObjects is read-only
What it means
PDF.js's scripting sandbox (src/scripting_api) implements the Acrobat JavaScript `doc` object inside a QuickJS sandbox. Per the Acrobat API specification this property is read-only, so the class defines a getter that returns the current value and a setter that unconditionally throws `Error("doc.<prop> is read-only")`. The throw aborts the currently executing sandboxed script event and is reported back to the host. `dataObjects` is the list of embedded file attachments; pdf.js returns `[]` (attachments unsupported) and marks it read-only.
Source
Thrown at src/scripting_api/doc.js:303
set calculate(calculate) {
this._calculate = calculate;
}
get creator() {
return this._creator;
}
set creator(_) {
throw new Error("doc.creator is read-only");
}
get dataObjects() {
return [];
}
set dataObjects(_) {
throw new Error("doc.dataObjects is read-only");
}
get delay() {
return this._delay;
}
set delay(delay) {
this._delay = delay;
}
get dirty() {
return this._dirty;
}
set dirty(dirty) {
this._dirty = dirty;
}
View on GitHub (pinned to 5903d58d58)
Solutions
- Remove the assignment to `doc.dataObjects`; read it through the getter instead.
- Embed attachments at authoring time if needed; pdf.js does not support writing them from script.
- If you cannot edit the PDF's embedded script, wrap the statement in try/catch so the rest of the form logic still runs.
Example fix
// before doc.dataObjects = []; // after // dataObjects is read-only — drop the assignment; read via doc.dataObjects
Defensive patterns
Strategy: validation
Validate before calling
// Known read-only doc properties (PDF.js scripting_api/doc.js)
const READONLY_DOC_PROPS = new Set([
'author','bookmarkRoot','creator','dataObjects','docID',
'documentFileName','dynamicXFAForm','external','filesize','hidden',
'hostContainer','icons','info','innerAppWindowRect','innerDocWindowRect',
'isModal','keywords','modDate'
]);
if (READONLY_DOC_PROPS.has('dataObjects')) {
// skip the write; dataObjects is read-only in pdf.js
console.warn('doc.dataObjects is read-only in pdf.js');
} else {
doc.dataObjects = value;
} Type guard
// Known read-only doc properties (PDF.js scripting_api/doc.js)
const READONLY_DOC_PROPS = new Set([
'author','bookmarkRoot','creator','dataObjects','docID',
'documentFileName','dynamicXFAForm','external','filesize','hidden',
'hostContainer','icons','info','innerAppWindowRect','innerDocWindowRect',
'isModal','keywords','modDate'
]);
const isReadOnlyDocProp = (name) => READONLY_DOC_PROPS.has(name);
// usage: if (!isReadOnlyDocProp('keywords')) doc.keywords = v; Try / catch
try {
doc.dataObjects = value;
} catch (e) {
// pdf.js throws Error('doc.dataObjects is read-only')
if (/is read-only/.test(e.message)) { /* swallow, expected */ }
else { throw e; }
} Prevention
- Treat every property listed in the Acrobat JS reference as read-only unless pdf.js provides a setter that stores the value.
- Before assigning, check `isReadOnlyDocProp('dataObjects')` or grep the setter in src/scripting_api/doc.js for a `throw`.
- When porting scripts from Acrobat, run them against the pdf.js sandbox in the dev server first to surface writes early.
- Prefer reading metadata through the Info dictionary at PDF authoring time rather than mutating it from a script.
When it happens
Trigger: A sandboxed PDF form/script executes an assignment to the property, e.g. `doc.dataObjects = value;` or `doc.dataObjects++`. Because the setter always throws (there is no condition), any write attempt triggers it.
Common situations: Scripts ported from desktop Acrobat where dataObjects held attachments; forms that try to stamp runtime state into document metadata on save/open; and PDFs generated by tools that emit non-spec-compliant JavaScript.
Related errors
- doc.info.${prop} is read-only
- doc.author is read-only
- doc.bookmarkRoot is read-only
- doc.creator is read-only
- doc.docID is read-only
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/30999cd6aa39a319.
Report an issue: GitHub.