Skip to content

Commit 1df9da9

Browse files
committed
Prevent "Uncaught promise" messages in the console when cancelling (some) ReadableStreams
While fixing issue 13794, I noticed that cancelling the `ReadableStream` returned by the `PDFPageProxy.streamTextContent`-method could lead to "Uncaught promise" messages in the console.[1] Generally speaking, we don't really care about errors when *cancelling* a `ReadableStream` and it thus seems reasonable to simply suppress any output in those cases. --- [1] Although, after that issue was fixed you'd now need to set the API-option `stopAtErrors = true` to actually trigger this.
1 parent 4ad5c5d commit 1df9da9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

src/display/api.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1802,7 +1802,11 @@ class PDFPageProxy {
18021802
return;
18031803
}
18041804
}
1805-
intentState.streamReader.cancel(new AbortException(reason?.message));
1805+
intentState.streamReader
1806+
.cancel(new AbortException(reason?.message))
1807+
.catch(() => {
1808+
// Avoid "Uncaught promise" messages in the console.
1809+
});
18061810
intentState.streamReader = null;
18071811

18081812
if (this._transport.destroyed) {

src/display/text_layer.js

+7-4
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ class TextLayerRenderTask {
597597
}
598598
})
599599
.catch(() => {
600-
/* Avoid "Uncaught promise" messages in the console. */
600+
// Avoid "Uncaught promise" messages in the console.
601601
});
602602
}
603603

@@ -615,7 +615,11 @@ class TextLayerRenderTask {
615615
cancel() {
616616
this._canceled = true;
617617
if (this._reader) {
618-
this._reader.cancel(new AbortException("TextLayer task cancelled."));
618+
this._reader
619+
.cancel(new AbortException("TextLayer task cancelled."))
620+
.catch(() => {
621+
// Avoid "Uncaught promise" messages in the console.
622+
});
619623
this._reader = null;
620624
}
621625
if (this._renderTimer !== null) {
@@ -741,8 +745,7 @@ class TextLayerRenderTask {
741745
pump();
742746
} else {
743747
throw new Error(
744-
'Neither "textContent" nor "textContentStream"' +
745-
" parameters specified."
748+
'Neither "textContent" nor "textContentStream" parameters specified.'
746749
);
747750
}
748751

0 commit comments

Comments
 (0)