{"record":{"id":"8f503899282d1b10","repo":"mozilla/pdf.js","slug":"no-ml","errorCode":null,"errorMessage":"No ML.","messagePattern":"No ML\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"src/display/editor/stamp.js","lineNumber":165,"sourceCode":"      });\n      try {\n        // The alt-text dialog isn't opened but we still want to guess the alt\n        // text.\n        this.mlGuessAltText();\n      } catch {}\n    }\n\n    this.div.focus();\n  }\n\n  async mlGuessAltText(imageData = null, updateAltTextData = true) {\n    if (this.hasAltTextData()) {\n      return null;\n    }\n\n    const { mlManager } = this._uiManager;\n    if (!mlManager) {\n      throw new Error(\"No ML.\");\n    }\n    if (!(await mlManager.isEnabledFor(\"altText\"))) {\n      throw new Error(\"ML isn't enabled for alt text.\");\n    }\n    const { data, width, height } =\n      imageData ||\n      this.copyCanvas(null, null, /* createImageData = */ true).imageData;\n    const response = await mlManager.guess({\n      name: \"altText\",\n      request: {\n        data,\n        width,\n        height,\n        channels: data.length / (width * height),\n      },\n    });\n    if (!response) {\n      throw new Error(\"No response from the AI service.\");","sourceCodeStart":147,"sourceCodeEnd":183,"githubUrl":"https://github.com/mozilla/pdf.js/blob/5903d58d58e4dd9ce6ffa3834aea8480f06b4ada/src/display/editor/stamp.js#L147-L183","documentation":"Thrown by StampEditor.mlGuessAltText when this._uiManager.mlManager is null/undefined. The ML manager is an optional, host-provided integration (e.g., Firefox's built-in model); when it is not registered, alt-text guessing is unavailable and the method aborts rather than silently returning garbage.","triggerScenarios":"Calling mlGuessAltText in a generic/embedding context where no mlManager was passed to the editor UI manager; calling it before the host wired up the ML integration.","commonSituations":"Using pdfjs-dist outside Firefox and trying to use alt-text guessing; calling the API in tests without stubbing mlManager; feature gated off by the host application.","solutions":["Check for mlManager availability before calling: if (!editor._uiManager.mlManager) return null.","Register an mlManager implementation on the UI manager if you want the feature.","Feature-detect and hide the 'Guess alt text' UI when no mlManager is present."],"exampleFix":"// before\nconst alt = await stampEditor.mlGuessAltText(imageData);\n\n// after\nif (!stampEditor._uiManager.mlManager) {\n  // alt-text ML is not available in this build/host\n  return null;\n}\nconst alt = await stampEditor.mlGuessAltText(imageData);","handlingStrategy":"type-guard","validationCode":"function canGuessAltText(editor) {\n  return !!editor._uiManager?.mlManager;\n}\nif (canGuessAltText(stampEditor)) {\n  return stampEditor.mlGuessAltText(imageData);\n}","typeGuard":"const hasMlManager = (e): boolean => !!e?._uiManager?.mlManager;","tryCatchPattern":"null","preventionTips":["Hide alt-text-guess UI when no mlManager is registered.","Treat ML as an optional capability in your feature detection.","Provide a manual alt-text path as the default."],"tags":["editor","ml","alt-text","optional-feature"],"backgroundTag":null,"analyzedSha":"5903d58d58e4dd9ce6ffa3834aea8480f06b4ada","analyzedAt":"2026-08-13T02:28:27.364Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}