mozilla/pdf.js · warning · Error
ML isn't enabled for alt text.
Error message
ML isn't enabled for alt text.
What it means
Thrown by StampEditor.mlGuessAltText when an mlManager is registered but await mlManager.isEnabledFor('altText') returns false. The host owns the decision (user opt-out, model not downloaded, policy disabled); PDF.js treats the disabled state as a hard stop rather than attempting the request.
Source
Thrown at src/display/editor/stamp.js:168
// text.
this.mlGuessAltText();
} catch {}
}
this.div.focus();
}
async mlGuessAltText(imageData = null, updateAltTextData = true) {
if (this.hasAltTextData()) {
return null;
}
const { mlManager } = this._uiManager;
if (!mlManager) {
throw new Error("No ML.");
}
if (!(await mlManager.isEnabledFor("altText"))) {
throw new Error("ML isn't enabled for alt text.");
}
const { data, width, height } =
imageData ||
this.copyCanvas(null, null, /* createImageData = */ true).imageData;
const response = await mlManager.guess({
name: "altText",
request: {
data,
width,
height,
channels: data.length / (width * height),
},
});
if (!response) {
throw new Error("No response from the AI service.");
}
if (response.error) {
throw new Error("Error from the AI service.");View on GitHub (pinned to 5903d58d58)
Solutions
- Gate the call on isEnabledFor first and hide/disable the alt-text UI accordingly.
- Surface a user-facing setting to enable the alt-text model and re-check after toggling.
- Fall back to manual alt-text entry when ML is disabled.
Example fix
// before
const alt = await stampEditor.mlGuessAltText(imageData);
// after
const ml = stampEditor._uiManager.mlManager;
if (!ml || !(await ml.isEnabledFor('altText'))) {
// show manual alt-text entry instead
return null;
}
const alt = await stampEditor.mlGuessAltText(imageData); Defensive patterns
Strategy: validation
Validate before calling
async function canGuessAltText(editor) {
const ml = editor._uiManager?.mlManager;
return !!ml && await ml.isEnabledFor('altText');
}
if (await canGuessAltText(stampEditor)) {
return stampEditor.mlGuessAltText(imageData);
} Type guard
null
Try / catch
null
Prevention
- Check isEnabledFor('altText') before showing the Guess button.
- Re-check on user toggle since the enabled state can change at runtime.
- Always provide a manual fallback for alt text.
When it happens
Trigger: User disabled alt-text ML in host settings; the model has not finished downloading; enterprise policy disabled the feature; calling mlGuessAltText before the user has granted the capability.
Common situations: Firefox with the alt-text model toggle off; embedded deployments where isEnabledFor returns false by default; race with model initialization where enabled state flips later.
Related errors
- No ML.
- XFA: Cannot save new annotations.
- extractPages: partial pageIndices cannot be combined with in
- extractPages: invalid page index.
- extractPages: overlapping pageIndices.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/ef502c314dacc907.
Report an issue: GitHub.