getCanvasReferences
Extracts the outgoing references of a canvas (.canvas) file.
Obsidian does not index canvas links into the per-file metadata cache, so a canvas file’s CachedMetadata is empty and the usual cache-based readers return nothing for it. This helper reads the canvas JSON directly and returns both its file-node links and its text-node embeds as CanvasReferences.
The returned references carry the nodeIndex/type (and, for text nodes, the originalReference) that the canvas-aware write path needs, so a consumer can move a canvas-referenced attachment and rewrite the canvas by composing referenceToFileChange (from ./reference.ts) with applyFileChanges (from ./file-change.ts).
Import:
import { getCanvasReferences } from 'obsidian-dev-utils/obsidian/canvas';Signature:
function getCanvasReferences(app: App, pathOrFile: PathOrFile): Promise<CanvasReference[]>Parameters:
| Parameter | Type | Description |
|---|---|---|
app | App | The Obsidian app instance. |
pathOrFile | PathOrFile | The canvas file (or its path) to extract references from. |
Returns: Promise<CanvasReference[]> — A Promise that resolves to the canvas references, or an empty array when the file is missing or its content is not valid canvas JSON.