Can we not break the Viewer if source is sent twice in a fraction of second ? Observed Error: Worker was terminated
See original GitHub issueError in console and PDF viewer is blank: The error says “worker was terminated” and also another error says “You’re trying to open two instances of the PDF viewer. Most likely, this will result in errors.”
Possible questions: Is there any event or property or callback you exposed saying that instance is already running. i tried looking into the NgxExtendedPdfViewerService but no luck to see if the instance is already running or not ? Please suggest a way how to identify if a instance is already running ? or is there a way in code where i can end or destroy the current instance that is up and then accept the 2nd instance to be the 1st or vice versa ?
Problem statement: How do i know if a instance is already running ? or is it possible if a second instance is initialized the first instance should terminate or untill the first instance is ended the second instance cannot be opened. Today if second instance is up then the page breaks 😦 Can we not consider the second instance at all? Can this enhancement suggestion be considered ? I dont want my PDF viewer to break at all. Please suggest ?
Error in console:
Seeing this blank window with scroll bar:
Code:
<ng-container *ngIf="useCustomRendered">
<!-- Default: Renders the PDF using the custom viewer -->
<ngx-extended-pdf-viewer [src]="safeUrl" height="100vh" zoom="115%" [useBrowserLocale]="true"
[showBorders]="false" backgroundColor="white" [showSidebarButton]="false" [showFindButton]="false"
[showPagingButtons]="false" [showZoomButtons]="false" [showPresentationModeButton]="false"
[showOpenFileButton]="false" [showPrintButton]="false" [showDownloadButton]="false"
[filenameForDownload]="false" [showBookmarkButton]="false" [showSecondaryToolbarButton]="false"
[showRotateButton]="false" [showHandToolButton]="false" [showScrollingButton]="false" [showSpreadButton]="false"
[showPropertiesButton]="false">
</ngx-extended-pdf-viewer>
</ng-container>
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (4 by maintainers)
I’ve played around one or two hours with your scenario. I think I know what’s going on. However, I believe that stopping a render task is difficult. For most users, there’s only the occasional error message “Worker was terminated”, but the PDF file shows without problems. So I’d prefer not to change anything.
However, I suppose it’s easy on your side. I’ve already mentioned the double-click protection. But you also know which data the user requests, and you’ve got the BLOB data. So it should be easy to detect if the user sends identical data to the PDF viewer twice.
Hope that helps! Stephan
In any case, I’d add a double-click protection to the button. Almost every user has learned that a double click always does the trick on Windows. They don’t distinguish between desktop applications and web applications, so they use their trick in the web, too. Most of the time it works perfectly: double-clicking on a link does exactly what you want, unless your technically versed and watch the network traffic.
Here are several nice approaches: https://stackoverflow.com/questions/51390476/how-to-prevent-double-click-in-angular
IMHO using RXJS
debounce()
is the most elegant approach, but disabling the button after is has been clicked is even simpler.