UXP Plugin – Cannot Access app.documents in InDesign
Copy link to clipboard
Copied
Hello everyone,
I am developing a UXP plugin for InDesign (version 20.1.0) and I am trying to retrieve the master spreads of the currently open document. However, I am encountering an issue where app.documents is undefined in my UXP environment, even though a document is open.
My Code:
import { app } from "indesign";
const getParentPageObjects = async () => {
try {
console.log(":rocket: Starting getParentPageObjects...");
if (!app.documents || app.documents.length === 0) {
throw new Error(":cross_mark: No InDesign document open!");
}
const document = app.activeDocument;
console.log(":page_facing_up: Active document:", document.name);
const masterSpreads = document.masterSpreads.everyItem().getElements();
console.log(`:page_facing_up: Number of master spreads: ${masterSpreads.length}`);
let masterPageNames = masterSpreads.map(spread => spread.name || "Unnamed");
console.log(":scroll: Found master spreads:", masterPageNames);
} catch (error) {
console.error(":cross_mark: Error retrieving master spreads:", error);
}
};
Error Message in the Console:
:bookmark_tabs: InDesign API loaded: ID { ... }
:open_file_folder: inDesignApp.documents: undefined
:cross_mark: Error retrieving master spreads: Error: :cross_mark: `documents` is not defined. Missing permissions?
What I've Tried So Far:
Checked manifest.json:
"requiredPermissions": {
"localFileSystem": "request",
"uxp.app": "fullAccess",
"uxp.host": "fullAccess"
}
Tried executeAsModal
I attempted to use executeAsModal, but app.documents remains undefined
- Why is app.documents undefined in UXP, even when a document is open?
- Is there a specific API or permission I might be missing?
I would really appreciate any help or guidance. Thank you in advance! 🙏😊
Copy link to clipboard
Copied
Do you use a typescript preprocessor?
Otherwise try

