mozilla/pdf.js · error · FormatError

No domain.

Error message

No domain.

What it means

Thrown by PDFFunction.constructPostScript (FunctionType 4) when the /Domain array is missing or non-numeric. PostScript calculator functions need Domain to know their input dimensionality before the embedded PostScript program can be compiled to JS/Wasm.

Source

Thrown at src/core/function.js:348

      // Prevent the value from becoming NaN as a result
      // of division by zero (fixes issue6113.pdf).
      tmpBuf[0] =
        dmin === dmax
          ? rmin
          : rmin + ((v - dmin) * (rmax - rmin)) / (dmax - dmin);

      // call the appropriate function
      fns[i](tmpBuf, 0, dest, destOffset);
    };
  }

  static constructPostScript(factory, fn, dict) {
    const domain = toNumberArray(dict.getArray("Domain"));
    const range = toNumberArray(dict.getArray("Range"));

    if (!domain) {
      throw new FormatError("No domain.");
    }

    if (!range) {
      throw new FormatError("No range.");
    }

    const psCode = fn.getString();

    try {
      if (factory.useWasm) {
        const wasmFn = buildPostScriptWasmFunction(psCode, domain, range);
        if (wasmFn) {
          return wasmFn; // (src, srcOffset, dest, destOffset) → void
        }
      }
    } catch {}

    warn("Failed to compile PostScript function to wasm, falling back to JS");

View on GitHub (pinned to 5903d58d58)

Solutions

  1. If authoring Type 4 functions, always set /Domain and /Range as numeric arrays of equal even length.
  2. Validate the PDF in Acrobat and report rendering gaps to pdf.js if Acrobat succeeds.
  3. Catch FormatError and degrade the page render.
  4. Regenerate the PDF with a spec-conformant tool.
Defensive patterns

Strategy: try-catch

Validate before calling

function postScriptHasDomain(dict) {
  const d = dict.getArray?.('Domain');
  return Array.isArray(d) && d.every(Number.isFinite) && d.length % 2 === 0;
}

Type guard

function isNumericIntervalArray(arr) {
  return Array.isArray(arr) && arr.length % 2 === 0 &&
    arr.every(x => typeof x === 'number' && Number.isFinite(x));
}

Try / catch

try { await page.render({ canvasContext }).promise; }
catch (err) {
  if (err?.name === 'FormatError' && err.message === 'No domain.') {
    console.warn('PostScript function missing domain; skipping.');
  } else throw err;
}

Prevention

When it happens

Trigger: A FunctionType 4 stream whose dictionary lacks /Domain or whose Domain is not a clean number array. Reached while rendering shading patterns, transfer functions, or Indexed lookups that embed a PostScript calculator.

Common situations: PDFs produced by tools that emit incomplete Type 4 functions, or PostScript functions damaged by a corrupt object stream. Often seen with custom ICC/CalRGB gradients.

Related errors


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