mozilla/pdf.js · error · Error

thermometer.cancelled is read-only

Error message

thermometer.cancelled is read-only

What it means

Thrown by the setter of `Thermometer.cancelled` (src/scripting_api/thermometer.js:32). A `Thermometer` (progress bar) object exposes `cancelled` so scripts can detect user cancellation; PDF.js treats it as read-only state driven by the host, so programmatic assignment throws. The other thermomemeter properties (`duration`, `text`, `value`) are writable.

Source

Thrown at src/scripting_api/thermometer.js:32

 */

import { PDFObject } from "./pdf_object.js";

class Thermometer extends PDFObject {
  _cancelled = false;

  _duration = 100;

  _text = "";

  _value = 0;

  get cancelled() {
    return this._cancelled;
  }

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

  get duration() {
    return this._duration;
  }

  set duration(val) {
    this._duration = val;
  }

  get text() {
    return this._text;
  }

  set text(val) {
    this._text = val;
  }

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Read `cancelled` only, and break out of your loop when it becomes true instead of assigning it.
  2. To stop the thermometer, call `thermo.end()` rather than setting `cancelled`.
  3. Wrap the assignment in try/catch if it originates in unchangeable generic code.

Example fix

// before
thermo.cancelled = true;
// after
// signal cancellation through your own flag and end the thermometer:
thermo.end();
Defensive patterns

Strategy: try-catch

Validate before calling

const READ_ONLY_THERMO_PROPS = new Set(['cancelled']);
function isWritableThermoProp(key) {
  return !READ_ONLY_THERMO_PROPS.has(key);
}

Try / catch

try {
  thermo.cancelled = true;
} catch (e) {
  // cancelled is read-only; end the thermometer instead
  thermo.end();
}

Prevention

When it happens

Trigger: A long-running script does `thermo.cancelled = true;` to try to abort itself, or generic state-restore code that writes every read property back.

Common situations: Scripts that conflate 'request cancellation' with 'set the flag'; polling-progress routines that mirror the thermometer object into another structure and back.

Related errors


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