mozilla/pdf.js · error · Error
Loading aborted
Error message
Loading aborted
What it means
A generic Error thrown after the WorkerTransport is constructed: if task.destroyed is true (destroy() was called during the worker handshake), pdf.js aborts with 'Loading aborted' instead of sending the Ready message. The orderly shutdown (including the Terminate message) is handled later by the transport, so this is a controlled abort of the load promise.
Source
Thrown at src/display/api.js:467
throw new Error("Worker was destroyed");
}
const messageHandler = new MessageHandler(docId, workerId, worker.port);
const transport = new WorkerTransport(
messageHandler,
task,
networkStream,
transportParams,
transportFactory,
pagesMapper
);
task._transport = transport;
if (task.destroyed) {
// `destroy()` was called during the worker handshake; the orderly
// shutdown (including the "Terminate" message) will be issued
// through the transport once destroy resumes.
throw new Error("Loading aborted");
}
messageHandler.send("Ready", null);
});
})
.catch(task._capability.reject)
.finally(task._setupCapability.resolve);
return task;
}
/**
* @typedef {Object} OnProgressParameters
* @property {number} loaded - Currently loaded number of bytes.
* @property {number} total - Total number of bytes in the PDF file.
* @property {number} percent - Currently loaded percentage, as an integer value
* in the [0, 100] range. If `total` is undefined, the percentage is `NaN`.
*/
View on GitHub (pinned to 5903d58d58)
Solutions
- If cancellation is intended, catch and swallow 'Loading aborted' as a normal outcome.
- Do not call destroy() unless you actually want to cancel; debounce rapid load requests.
- Sequence loads: await one task's destroy before starting the next.
Example fix
try {
const doc = await loadingTask.promise;
} catch (e) {
if (/Loading aborted|Worker was destroyed/.test(e.message)) return;
throw e;
} Defensive patterns
Strategy: try-catch
Validate before calling
if (loadingTask.destroyed) {
// do not expect the load to resolve; it will reject with 'Loading aborted'.
} Try / catch
try {
const doc = await loadingTask.promise;
} catch (e) {
if (/Loading aborted/.test(e.message)) return; // intentional cancel
throw e;
} Prevention
- Treat 'Loading aborted' as a normal outcome of user-initiated cancel.
- Debounce rapid load requests so you do not destroy a load mid-handshake.
- Sequence loads: await one task's destroy before starting the next.
When it happens
Trigger: loadingTask.destroy() invoked during the window between worker handshake completion and the Ready send; rapid create/destroy cycles; a component that destroys its task in cleanup while the initial load is still settling.
Common situations: SPA route changes, timeout-based cancellation, user cancel button pressed during initial load, double-mount bugs in React StrictMode.
Related errors
- Worker was destroyed
- Transport destroyed
- PDFWorker.create - the worker is being destroyed. Please rem
- Worker was destroyed.
- Not implemented: NetworkStream
AI-assisted analysis of mozilla/pdf.js@5903d58d58 (2026-08-13).
Data as JSON: /api/errors/19f19c5474ad226b.
Report an issue: GitHub.