mozilla/pdf.js · warning · Error

Invalid psf in AFSpecial_Keystroke

Error message

Invalid psf in AFSpecial_Keystroke

What it means

Thrown by AFSpecial_Keystroke when the psf selector is not 0 (zip), 1 (zip+4), 2 (phone), or 3 (SSN). Like AFSpecial_Format, it builds a mask per known format and rejects unknown selectors via the default branch. It executes within the sandboxed PDF-JS form layer.

Source

Thrown at src/scripting_api/aform.js:557

    let value = this.AFMergeChange(event);
    let formatStr, secondFormatStr;
    switch (psf) {
      case 0:
        formatStr = "99999";
        break;
      case 1:
        formatStr = "99999-9999";
        break;
      case 2:
        formatStr = "999-9999";
        secondFormatStr = "(999) 999-9999";
        break;
      case 3:
        formatStr = "999-99-9999";
        break;
      default:
        throw new Error("Invalid psf in AFSpecial_Keystroke");
    }
    const formats = secondFormatStr
      ? [formatStr, secondFormatStr]
      : [formatStr];
    for (const format of formats) {
      this.#AFSpecial_KeystrokeEx_helper(format, value, false);
      if (event.rc) {
        return;
      }
      event.rc = true;
    }

    const re = /[-()\s]+/g;
    value = value.replaceAll(re, "");
    for (const format of formats) {
      this.#AFSpecial_KeystrokeEx_helper(
        format.replaceAll(re, ""),
        value,

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Repair or report the PDF form script; the error originates in PDF content.
  2. Update PDF.js for any improved tolerance.
  3. Tolerate scripting failures at the embedding level so input handling continues.
  4. If authoring the PDF, use psf in 0..3.
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await runFormScript(...);
} catch (e) {
  if (/Invalid psf in AFSpecial_Keystroke/.test(e.message)) { /* skip keystroke mask */ }
}

Prevention

When it happens

Trigger: A PDF form script calls AFSpecial_Keystroke(psf) with psf outside [0,3].

Common situations: A malformed keystroke-format specifier in the PDF; an authoring tool emitting a non-standard psf.

Related errors


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