mozilla/pdf.js · error · Error
extractPages: overlapping pageIndices.
Error message
extractPages: overlapping pageIndices.
What it means
Plain Error thrown by reservePageSlot when a newPageIndex is already occupied in this.oldPages (slot !== undefined). It prevents two source pages from being written to the same output slot, which would silently lose data.
Source
Thrown at src/core/editor/pdf_editor.js:994
* @return {Promise<void>}
*/
async extractPages(
pageInfos,
annotationStorage,
primaryDocument,
handler,
task
) {
this.#primaryDocument = primaryDocument;
pageInfos = this.#resolveInsertAfterIndices(pageInfos);
const promises = [];
let newIndex = 0;
const reservePageSlot = newPageIndex => {
if (!Number.isInteger(newPageIndex) || newPageIndex < 0) {
throw new Error("extractPages: invalid page index.");
}
if (this.oldPages[newPageIndex] !== undefined) {
throw new Error("extractPages: overlapping pageIndices.");
}
// Reserve the slot immediately because page/image collection can be
// async.
this.oldPages[newPageIndex] = null;
};
const allDocumentData = [];
if (annotationStorage) {
this.#newAnnotationsParams = {
handler,
task,
newAnnotationsByPage: getNewAnnotationsMap(annotationStorage),
imagesPromises: AnnotationFactory.generateImages(
annotationStorage.values(),
this.xrefWrapper,
true
),
};View on GitHub (pinned to 5903d58d58)
Solutions
- De-duplicate all pageIndices across pageInfos before calling extractPages.
- After resolving insertAfter yourself, ensure no slot is referenced twice.
- Compute target slots programmatically (e.g., accumulate an offset) rather than hard-coding.
Example fix
// before
pageInfos = [
{ document: a, pageIndices: [0, 2] },
{ document: b, pageIndices: [2, 4] }, // '2' overlaps
];
// after
pageInfos = [
{ document: a, pageIndices: [0, 2] },
{ document: b, pageIndices: [3, 4] },
]; Defensive patterns
Strategy: validation
Validate before calling
function assertNoOverlap(pageInfos) {
const seen = new Set();
for (const p of pageInfos) {
for (const idx of p.pageIndices ?? []) {
if (seen.has(idx)) throw new Error(`Overlapping pageIndex: ${idx}`);
seen.add(idx);
}
}
} Try / catch
try {
await editor.extractPages(pageInfos, ...);
} catch (e) {
if (e.message === 'extractPages: overlapping pageIndices.') {
pageInfos = dedupeSlots(pageInfos);
return editor.extractPages(pageInfos, ...);
}
throw e;
} Prevention
- Compute target slots programmatically (accumulating offset) instead of hard-coding.
- De-duplicate all pageIndices across pageInfos in a Set-based check.
- Re-run the contiguity/overlap check after any insertAfter resolution.
When it happens
Trigger: pageIndices across multiple pageInfos that share a value (e.g., both [{pageIndices:[2]}] and [{pageIndices:[2]}]); a single pageInfo with duplicate pageIndices; an insertAfter resolution that collides with explicit pageIndices.
Common situations: Caller reuses pageIndices from different sources without de-duplication; off-by-one when manually shifting indices after an insert.
Related errors
- extractPages: invalid page index.
- extractPages: sparse pageIndices.
- extractPages: partial pageIndices cannot be combined with in
- extractPages: too many pageIndices.
- extractPages: nothing to extract.
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/44af86c90ce572e4.
Report an issue: GitHub.