Skip to content

Commit a23855c

Browse files
committed
debug(pdf-server): expose pdfDocument.annotationStorage + window.__pdf internals
__pdfDebug() now also dumps PDF.js's annotationStorage contents (editor stamps live there, invisible to our tracking) and all localStorage keys matching pdf-annot pattern. After running __pdfDebug(), internals are exposed as window.__pdf.{pdfDocument, annotationMap, annotationLayerEl, formLayerEl} for interactive console poking.
1 parent 1534125 commit a23855c

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

examples/pdf-server/src/mcp-app.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5441,11 +5441,42 @@ app.connect().then(() => {
54415441
return { parseError: true, length: raw.length };
54425442
}
54435443
})(),
5444+
// PDF.js's own annotationStorage — where editor stamps live.
5445+
// Keys like "pdfjs_internal_editor_*" are PDF.js's built-in annotation
5446+
// editor; those are invisible to our annotationMap tracking.
5447+
pdfJsAnnotationStorage: (() => {
5448+
if (!pdfDocument) return null;
5449+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5450+
const storage = pdfDocument.annotationStorage as any;
5451+
const all = storage.getAll?.() ?? storage._storage ?? new Map();
5452+
const entries =
5453+
all instanceof Map ? [...all.entries()] : Object.entries(all);
5454+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5455+
return entries.map(([k, v]: [string, any]) => ({
5456+
key: k,
5457+
ctor: v?.constructor?.name,
5458+
annotationType: v?.annotationType,
5459+
hasBitmap: Boolean(v?.bitmap),
5460+
value: v?.value,
5461+
}));
5462+
})(),
5463+
// All localStorage keys that look like ours — per-tool-call keys mean
5464+
// old sessions' annotations won't restore under the current key.
5465+
allPdfAnnotKeys: Object.keys(localStorage).filter(
5466+
(k) => k.includes("pdf-annot") || k.includes(":annotations"),
5467+
),
54445468
currentPage,
54455469
isDirty,
54465470
panelOpen: annotationPanelOpen,
54475471
};
54485472
console.log(JSON.stringify(out, null, 2));
5473+
// Also expose internals on window for interactive poking
5474+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
5475+
const w = window as any;
5476+
w.__pdf = { pdfDocument, annotationMap, annotationLayerEl, formLayerEl };
5477+
console.log(
5478+
"→ internals exposed as window.__pdf.{pdfDocument, annotationMap, ...}",
5479+
);
54495480
return out;
54505481
};
54515482

0 commit comments

Comments
 (0)