Running documents
The Runtime API
globalThis.idop — every method a document can call, and how errors work.
Before a document’s code runs, the reader installs a frozen object at globalThis.idop. It is the only way for a document to reach the reader. There is no endpoint to infer from location.
Methods
| Method | Result |
|---|---|
idop.runtime.getInfo() |
{ runtimeApiVersion, availableCapabilities } |
idop.storage.read(path) |
{ text } |
idop.storage.write(path, text) |
{ written: true } |
idop.storage.delete(path) |
{ deleted: true } |
idop.storage.list() |
{ paths } |
idop.storage.transaction(operations) |
{ committed: true } — all or nothing |
idop.env.get(id) |
{ value } for a declared environment binding |
idop.network.request(request) |
{ status, headers, body } |
idop.ui.requestSave() |
asks the reader to show its Save control |
idop.ui.requestConfiguration() |
asks the reader to show its configuration |
idop.host.getInputFile() |
the file a viewer was opened for |
idop.host.putOutputFile(bytes) |
hands an edited copy back to the reader |
Every method returns a promise.
Errors
A failure rejects with an Error whose code is stable — for example IDOP-STORAGE-NOT-FOUND, IDOP-NETWORK-ORIGIN-DENIED or IDOP-ENV-MISSING. Branch on code. Never parse message, which is a diagnostic and may be translated or changed.
try {
const { text } = await idop.storage.read('settings.json');
} catch (error) {
if (error.code === 'IDOP-STORAGE-NOT-FOUND') useDefaults();
else throw error;
}
What is deliberately missing
There is no method that returns a secret, lists environment variables, or exports content to an arbitrary destination.