mozilla/pdf.js · error · Error

doc.mouseY is read-only

Error message

doc.mouseY is read-only

What it means

`Doc.mouseY` is the read-only counterpart to mouseX, returning the cursor's Y coordinate (points) from the page's top-left corner. PDF.js hard-codes it to 0 because the browser-rendered viewer does not push live cursor coordinates into the sandboxed scripting engine. The setter throws `doc.mouseY is read-only` to enforce the Acrobat spec contract that cursor position is observable, not settable.

Source

Thrown at src/scripting_api/doc.js:502

  set modDate(_) {
    throw new Error("doc.modDate is read-only");
  }

  get mouseX() {
    return 0;
  }

  set mouseX(_) {
    throw new Error("doc.mouseX is read-only");
  }

  get mouseY() {
    return 0;
  }

  set mouseY(_) {
    throw new Error("doc.mouseY is read-only");
  }

  get noautocomplete() {
    return this._noautocomplete;
  }

  set noautocomplete(noautocomplete) {
    this._noautocomplete = noautocomplete;
  }

  get nocache() {
    return this._nocache;
  }

  set nocache(nocache) {
    this._nocache = nocache;
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Delete the assignment; treat mouseY as read-only input only (`var y = doc.mouseY;`).
  2. Use the `event` object fields (`event.y`, `event.targetY`) for the coordinate at the action that triggered the script.
  3. Run untrusted/legacy scripts through a try/catch boundary so a read-only write is logged and skipped rather than fatal.

Example fix

// before
doc.mouseY = doc.mouseY + 10;

// after
var y = doc.mouseY; // 0 in PDF.js; not writable
Defensive patterns

Strategy: try-catch

Validate before calling

const READ_ONLY_DOC_PROPS = new Set(['mouseX','mouseY' /* ... */]);
function assertsNoReadOnlyWrite(scriptSrc) {
  for (const p of READ_ONLY_DOC_PROPS) {
    if (new RegExp(`\\bdoc\\.${p}\\s*=`).test(scriptSrc)) {
      throw new Error(`Script writes read-only property doc.${p}`);
    }
  }
}
assertsNoReadOnlyWrite(myScript);

Type guard

function isReadOnlyDocProp(doc, prop) {
  const desc = Object.getOwnPropertyDescriptor(Object.getPrototypeOf(doc), prop)
    || Object.getOwnPropertyDescriptor(doc, prop);
  return !!desc && !!desc.get && !desc.set;
}
isReadOnlyDocProp(doc, 'mouseY'); // true

Try / catch

try {
  doc.mouseY = value; // legacy write
} catch (e) {
  if (/mouseY is read-only/.test(e.message)) {
    console.warn('Ignored read-only write:', e.message);
  } else { throw e; }
}

Prevention

When it happens

Trigger: A document script assigns to `doc.mouseY` (e.g. `doc.mouseY = someValue;`) inside any script event (Page/Open, MouseUp, Calculate). The throwing setter fires on that assignment line.

Common situations: Legacy AcroJS scripts attempting to record or override cursor position; scripts auto-generated by form designers that probe-set every property; tutorials copied from the Acrobat SDK that demonstrate unsupported writes.

Related errors


AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13). Data as JSON: /api/errors/292128b97b70d136. Report an issue: GitHub.