Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR Error: Uncaught (in promise): UnknownErrorException: Window is not defined while displaying pdf using base64 string from server #1059

Closed
chetan592 opened this issue Dec 2, 2021 · 7 comments
Assignees
Labels
bug Something isn't working Confirmed I've managed to reproduce the bug. That's great news: chances are I'll solve it.

Comments

@chetan592
Copy link

I am using ngx-extended-pdf-viewer to show pdf using base64 strings that I receive from server.

I am not sure but I think it was not there when I was trying it for images from asset folder

For some pdf I get this issue where pdf is not visible and throws error, which is in console .

This issue may be because of base library but little direction towards solving it would be very helpful for me.

Adding screenshot for ref

431FB317-B7E5-4B18-B44D-64031E3DC1AD
0EFAFE03-1814-475B-91C3-D64AE6B34DFF

@stephanrauh
Copy link
Owner

That may be bad news because it might mean I have to remove a popular feature. So let's examine your case thoroughly first. Which version of ngx-pdf-extended-pdf-viewer are you using? And are you using the default branch or the "bleeding edge" branch?

@stephanrauh stephanrauh self-assigned this Dec 2, 2021
@stephanrauh stephanrauh added the bug Something isn't working label Dec 2, 2021
@chetan592
Copy link
Author

chetan592 commented Dec 3, 2021

I am using following version of ngx-extended-pdf-viewer
"ngx-extended-pdf-viewer": "^11.0.0-alpha.4"

I am on default branch.

Which feature is related with it and what is causing this issue?

Some more points that I observed -

  • For some PDFs its showing up for some its not
  • For some PDFs where error is there but still renders the PDF
  • There are also cases where error shows up and does not render the PDF

@stephanrauh
Copy link
Owner

It's the feature we've decided to build in #804: allow users to filter log messages.

The idea was to replace every console.log call by a custom call. However, the service worker thread doesn't have a Window object, and even trying to check if the Window object exists causes the service worker to crash. I don't understand this. That's not the usual behavior of JavaScript. I'm running out of ideas. There must be a way to detect whether the code is running in a server worker or in a regular UI thread, but I haven't found out yet how to do this!

function info(msg) {
  if (verbosity >= VerbosityLevel.INFOS) {
    if (typeof WorkerGlobalScope !== "undefined" && self instanceof WorkerGlobalScope) {
      console.log(`Info: ${msg}`);
    } else if (Window && Window['ngxConsole']) {   <<<<<<< Service worker crashes here!
      Window['ngxConsole'].log(`Info: ${msg}`);
    } else {
      console.log(`Info: ${msg}`);
    }
  }
}

@stephanrauh
Copy link
Owner

@chetan592 Please update to version 11.0.0-alpha.10. If this fixes your bug, please tell me. If it doesn't, please tell me, too. I've tried to implement a bugfix in version 11.0.0-alpha.6, and I'd like to know for sure if it fixes the bug or not.

@chetan592
Copy link
Author

chetan592 commented Dec 4, 2021

@stephanrauh Thanks for support you are providing to community.

I updated it to the 11.0.0-alpha.10. Now PDFs that were having issues are loaded and shown successfully. But warning of window not defined is there in console.Also sometimes it shows couple of warning on console including that of window undefined reference error.

Anything to worry about those warnings?

Attached screenshots for your reference.

image

@stephanrauh
Copy link
Owner

Hooray! That's good news. But you're right, some of these warnings are exceptions that must be fixed. They prevent displaying the digital signature of the file.

As for the other messages:

  • You didn't provide a height attribute, or you passed something like height="100%". More often that not, this results in a height of zero pixels. The PDF viewer tries to fix this. If you're fine with the automated fix, you can ignore the warning. You can also overwrite the global ngxConsole function to filter this message. I'm just afraid I haven't documented this feature yet.
  • The translation key is a new field of the find bar (the toolbar that shows when you hit the magnifying glass symbol). You'll spot the English text among the translated texts. If you don't mind, send me the translation of your language. I only speak a few languages, so I need the community support to do it right.
  • The "Filter: Crypt" message puzzles me. I don't think it's a good sign, but I've never seen it before.
  • Digital signatures are shown (at least if you activate the feature), but the PDF viewer can't verify if they are valid or fraud. I want developers to know what they're doing, so I've added a console message.
  • You can safely ignore the "undefined function 32". As far as I know, it's a bug of your PDF file. The embedded font is broken. More details here: Warning: TT: undefined function mozilla/pdf.js#3768 (comment)

@stephanrauh stephanrauh added the Confirmed I've managed to reproduce the bug. That's great news: chances are I'll solve it. label Dec 4, 2021
stephanrauh added a commit to stephanrauh/pdf.js that referenced this issue Dec 4, 2021
stephanrauh added a commit to stephanrauh/pdf.js that referenced this issue Dec 4, 2021
stephanrauh added a commit to stephanrauh/pdf.js that referenced this issue Dec 4, 2021
stephanrauh added a commit to stephanrauh/pdf.js that referenced this issue Dec 4, 2021
stephanrauh added a commit that referenced this issue Dec 4, 2021
…dded missing translations for a few languages; update the build chain to Angular 13; stop versioning the generated files on GitHub (with the exception of the non-minified ESNext files)
@stephanrauh
Copy link
Owner

stephanrauh commented Dec 4, 2021

fixed with version 11.0.0-alpha.12.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Confirmed I've managed to reproduce the bug. That's great news: chances are I'll solve it.
Projects
None yet
Development

No branches or pull requests

2 participants