mozilla/pdf.js · error · Error

No "textContentSource" parameter specified.

Error message

No "textContentSource" parameter specified.

What it means

Thrown by the TextLayer constructor when textContentSource is neither a ReadableStream nor, in the GENERIC build, a plain object. The text layer needs a stream of text-content items to lay out, so a missing or wrong-typed source is a hard configuration error. The GENERIC build additionally accepts a raw object by wrapping it in a one-shot stream.

Source

Thrown at src/display/text_layer.js:119

  /**
   * @param {TextLayerParameters} options
   */
  constructor({ textContentSource, images, container, viewport }) {
    if (textContentSource instanceof ReadableStream) {
      this.#textContentSource = textContentSource;
    } else if (
      (typeof PDFJSDev === "undefined" || PDFJSDev.test("GENERIC")) &&
      typeof textContentSource === "object"
    ) {
      this.#textContentSource = new ReadableStream({
        start(controller) {
          controller.enqueue(textContentSource);
          controller.close();
        },
      });
    } else {
      throw new Error('No "textContentSource" parameter specified.');
    }
    this.#container = this.#rootContainer = container;

    this.#imagesHandler = images;

    this.#scale = viewport.scale * OutputScale.pixelRatio;
    this.#rotation = viewport.rotation;
    this.#layoutTextParams = {
      div: null,
      properties: null,
      ctx: null,
    };
    const { pageWidth, pageHeight, pageX, pageY } = viewport.rawDims;
    this.#transform = [1, 0, 0, -1, -pageX, pageY + pageHeight];
    this.#pageWidth = pageWidth;
    this.#pageHeight = pageHeight;

    TextLayer.#ensureMinFontSizeComputed();

View on GitHub (pinned to 5903d58d58)

Solutions

  1. Pass the ReadableStream from await page.streamTextContent() as textContentSource.
  2. In GENERIC builds you may pass the text-content object directly; otherwise wrap it.
  3. Ensure the value is not null/undefined before constructing the layer.
  4. Check that the build target (GENERIC vs others) matches how you supply content.

Example fix

// before
const textLayer = new TextLayer({ textContentSource: undefined, container, viewport });
// after
const stream = await page.streamTextContent();
const textLayer = new TextLayer({ textContentSource: stream, container, viewport });
Defensive patterns

Strategy: validation

Validate before calling

const source = await page.streamTextContent();
if (!(source instanceof ReadableStream)) {
  throw new Error('textContentSource must be a ReadableStream');
}
const textLayer = new TextLayer({ textContentSource: source, container, viewport });

Type guard

function isValidTextContentSource(src) {
  return src instanceof ReadableStream || (typeof src === 'object' && src !== null && !(src instanceof Promise));
}

Prevention

When it happens

Trigger: new TextLayer({ textContentSource: undefined, container, viewport }) or passing a number/string/Promise instead of a stream/object.

Common situations: Forgetting to pass textContentSource; passing the awaited text content array in a non-GENERIC build; passing null after a failed page.streamTextContent().

Related errors


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