mozilla/pdf.js · error · Error
The AnnotationEditor is not enabled.
Error message
The AnnotationEditor is not enabled.
What it means
Setting `PDFViewer.annotationEditorMode` requires the annotation editor subsystem to have been initialized at construction. The guard checks `#annotationEditorUIManager`, which is only created when the viewer was built with annotation-editor support enabled (an `enableAnnotationEditor` option other than `AnnotationEditorType.DISABLE`, plus the editor layer builder attached). Throwing here prevents callers from driving an editor UI that has no backing manager. It fires before any validation of `mode` itself, so even a benign `mode: AnnotationEditorType.NONE` will trip it if the manager was never created.
Source
Thrown at web/pdf_viewer.js:2711
* keyboard action.
* @property {boolean} [mustEnterInEditMode] - True if the editor must enter
* edit mode.
* @property {boolean} [editComment] - True if the editor must enter
* comment edit mode.
*/
/**
* @param {AnnotationEditorModeOptions} options
*/
set annotationEditorMode({
mode,
editId = null,
isFromKeyboard = false,
mustEnterInEditMode = false,
editComment = false,
}) {
if (!this.#annotationEditorUIManager) {
throw new Error(`The AnnotationEditor is not enabled.`);
}
if (this.#annotationEditorMode === mode) {
return; // The AnnotationEditor mode didn't change.
}
if (!isValidAnnotationEditorMode(mode)) {
throw new Error(`Invalid AnnotationEditor mode: ${mode}`);
}
if (!this.pdfDocument) {
return;
}
this.#preloadEditingData(mode);
const { eventBus, pdfDocument } = this;
const updater = async () => {
this.#cleanupSwitchAnnotationEditorMode();
this.#annotationEditorMode = mode;
await this.#annotationEditorUIManager.updateMode(
mode,View on GitHub (pinned to 5903d58d58)
Solutions
- Construct the viewer with `enableAnnotationEditor` set to a non-DISABLE mode (e.g. `AnnotationEditorType.EDIT_FREETEXT`) if you intend to use editors.
- Ensure the AnnotationEditorLayerBuilder is registered for each page view so the UI manager is instantiated.
- Gate the assignment: only set `annotationEditorMode` when you know editing is enabled (track the flag you passed at construction).
- If editing must be optional, wrap the assignment and degrade gracefully (disable the toolbar control) instead of letting the throw propagate.
Example fix
// before
const viewer = new PDFViewer({ container, viewer: div }); // no editor opts
viewer.annotationEditorMode = { mode: AnnotationEditorType.EDIT_FREETEXT };
// after
const viewer = new PDFViewer({
container,
viewer: div,
enableAnnotationEditor: AnnotationEditorType.EDIT_FREETEXT,
});
viewer.annotationEditorMode = { mode: AnnotationEditorType.EDIT_FREETEXT }; Defensive patterns
Strategy: validation
Validate before calling
// Track the flag you passed at construction; gate the setter.
const editorEnabled = enableAnnotationEditor && enableAnnotationEditor !== AnnotationEditorType.DISABLE;
function setEditorMode(viewer, mode) {
if (!editorEnabled) {
console.warn('Annotation editor not enabled at construction; ignoring mode change.');
return;
}
viewer.annotationEditorMode = { mode };
} Type guard
// There is no public field exposing #annotationEditorUIManager, so guard via
// construction state (the only thing that creates the manager).
function viewerSupportsEditors(enableAnnotationEditor) {
return (
enableAnnotationEditor != null &&
enableAnnotationEditor !== -1 /* AnnotationEditorType.DISABLE */
);
} Try / catch
try {
viewer.annotationEditorMode = { mode };
} catch (e) {
if (/AnnotationEditor is not enabled/.test(e.message)) {
disableEditorToolbar(); // graceful degrade
} else {
throw e;
}
} Prevention
- Set enableAnnotationEditor at construction whenever editor UI is reachable.
- Keep the editor toolbar control disabled until you confirm the manager exists.
- Don't assume a later set of annotationEditorMode can lazily enable editing — it can't.
When it happens
Trigger: Calling `pdfViewer.annotationEditorMode = { mode: ... }` on a viewer instance whose constructor was given `enableAnnotationEditor: false`/omitted, or `DISABLE`. Also when the AnnotationEditorLayerBuilder was never attached to the page viewer, leaving `#annotationEditorUIManager` null.
Common situations: Embedding PDF.js in a custom app with a minimal config that omits editor options; upgrading PDF.js versions where the editor feature became opt-in; reading `mode` from a toolbar toggle before the document (and thus editing data) is ready.
Related errors
- Invalid `workerPort` type.
- Invalid `workerSrc` type.
- Invalid updateScale options: either `steps` or `scaleFactor`
- Unknown CMap name: ${name}
- Built-in CMap parameters are not provided.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/4864c9ecb864ab66.
Report an issue: GitHub.