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

ReferenceError: window is not defined #1719

Closed
cecilehautecoeur opened this issue Mar 21, 2023 · 10 comments
Closed

ReferenceError: window is not defined #1719

cecilehautecoeur opened this issue Mar 21, 2023 · 10 comments
Assignees
Labels
bug Something isn't working Solved version 17 Scheduled for version 17

Comments

@cecilehautecoeur
Copy link

cecilehautecoeur commented Mar 21, 2023

Hello,

Describe the bug
The following warning appears when displaying some documents:
Warning: getOperatorList - ignoring XObject: "ReferenceError: window is not defined".

In that case, most elements of the pdf are missing (e.g. the text and some images).

Version info
Version 16.X.X
The bug seems not to happen in previous versions. We tested on version 15.

Desktop (please complete the following information):
Chrome. We also tested on Safari and the bug does not seem to appear there.

It seems that the bug has already been fixed in version 11.0.0-alpha.12 #1059.

Thank you

@stephanrauh
Copy link
Owner

The message "getOperatorList - ignoring XObject" only occurs in the JavaScript sandbox. It doesn't show in any of my test files. Can you send me a PDF file causing this warning, please?

@stephanrauh stephanrauh self-assigned this Mar 21, 2023
@stephanrauh stephanrauh added bug Something isn't working waiting for the user's answer Can't reproduce the bug You've reported a bug, but the feature works fine on my machine. So I don't know how to help you. labels Mar 21, 2023
@RodolfoGraziano
Copy link

RodolfoGraziano commented Apr 3, 2023

Hi, i'd like to report that i get the same error with a single specific file (pdf viewer version 16.2.16).

[Warning: getOperatorList - ignoring XObject: "ReferenceError: window is not defined".](pdf.worker-3.4.493.min.js:22 Warning: getOperatorList - ignoring XObject: "ReferenceError: window is not defined".)

Unfortunately I can't share the file since it has confidential info inside.
However, id' like to add that the bug does not seem to appear when the file is loaded inside the demo at https://pdfviewer.net/extended-pdf-viewer/getting-started.
It is present however in a clean new project that follows the minimal setup step for the ngx-extended-pdf-viewer (npm add followed by the asset glob setup in the angular.json) made in Angular 15.1.0.
Is there some specific configuration that are present in the demo that are not reported in the generic setup steps?

@stephanrauh
Copy link
Owner

No, I don't think there's any specific configuration. You can look it up yourself: https://github.com/stephanrauh/ngx-extended-pdf-viewer/tree/main/projects/ngx-extended-pdf-viewer/schematics/ng-add. All the magic of ng add ngx-extended-pdf-viewer sits in the index.ts, which is a pretty short file, so you can browse it quickly.

@cecilehautecoeur
Copy link
Author

Dear Stephan,

Thank you very much for your fast answer and sorry for the delay to come back to you.

As for Rodolfo, the file causing the problem are confidential, and we can therefore not share them with you. Nevertheless, we could observe that the problematic files had been created by a scanner named "KONICA MINOLTA bizhub C458", if this information can be of any help.

We unfortunately do not have access to this scanner to produce a non-confidential example file.

@sudilshr
Copy link

sudilshr commented Apr 17, 2023

Hi @stephanrauh,

I am facing the same issue.

Angular: 15.2.0
ngx-extended-pdf-viewer: 17.0.0-alpha.0
pdfjs version: 3.5.528

window.pdfDefaultOptions.activateWillReadFrequentlyFlag in pdf.worker file might be the source of the problem.
https://github.com/stephanrauh/ngx-extended-pdf-viewer/blob/95bc342c32805e746fb7187253ea33752ac00b51/projects/ngx-extended-pdf-viewer/assets/pdf.worker-3.5.528.js#L36025

createMask and FakeUnicodeFont is checking window.pdfDefaultOptions.activateWillReadFrequentlyFlag. The PDF I had issue with has a /ImageMask in it.

<< /Type /XObject /Subtype /Image /Width 2176 /Height 2972 /ImageMask true
/Interpolate true /BitsPerComponent 1 /Length 113993 /Filter /FlateDecode >>

I am not allowed to share the original file so I generated a sample PDF with /ImageMask to replicate the issue.
https://github.com/sudilshr/pdf-viewer-masked-image-issue/blob/bf99814abf2c94572e918e04b98be17252ae171a/src/assets/sandwich-masked.pdf

https://stackblitz.com/edit/github-uf3tfg

Update:
@cecilehautecoeur @RodolfoGraziano - Downgrading to version 16.2.2 resolves the issue for me.

@stephanrauh
Copy link
Owner

@sudilshr The original problem was the "window is not defined" message. I don't think that's your issue, or is it? Server-side rendering shouldn't load the pdf.worker-*.js file at all. The flag window.pdfDefaultOptions.activateWillReadFrequentlyFlag won't cause problems, either, because it's simply a flag. So I wonder what problem you're referring to.

Does setting the flag to true or false solve the problem? Can you test this, please? IMHO the default value (false) means that ngx-extended-pdf-viewer does what pdf.js does. Only setting the flat to true makes a difference. It solves some exotic problems of the Chrome browser, at the price of less performance.

@michaelmarcuccio
Copy link

michaelmarcuccio commented Apr 18, 2023

This issue is happening to us too, it completely jumbles/breaks (potentially without the user being able to realize it) the rendering of the PDFs. I tried the flag you mentioned above with true and false. Neither one helps fix the issue.

I have isolated the rendering issue to starting in v16.2.4 as it does not occur in v16.2.3. We have to downgrade back to v16.2.3 to avoid the issue. I would consider this issue a major bug as it silently fails to render PDFs that would previously be rendered by this library. Anyone upgrading can run into this issue and not even realize it.

The warning message being discussed here(getOperatorList - ignoring XObject: "ReferenceError: window is not defined) might just be a side effect or inconsequential to this rendering issue; but this warning does not show up in v16.2.3 where the bug does not occur.

Edit: forgot to mention, I am on normal version - NOT bleeding edge.

@sudilshr
Copy link

@stephanrauh - I was not aware Stackblitz url I shared was doing server side rendering. My original project is browser side rendering though.

I log the original error on the console and the error is originating from PDFImage.createMask line 36027 which is const options = window.pdfDefaultOptions.activateWillReadFrequentlyFlag ? {.

PDF bd650c3e558bb8f69adc5bc1ce139a10 [1.6 GPL Ghostscript 9.21 / ocrmypdf 5.3.3 / Tesseract OCR-PDF 3.05.01] (PDF.js: 3.5.528 [97fe1fa13]) modified by ngx-extended-pdf-viewer
ReferenceError: window is not defined
at PDFImage.createMask (pdf.worker-3.5.528.min.js:36027:23)
at PartialEvaluator.buildPaintImageXObject (pdf.worker-3.5.528.min.js:8796:39)
at pdf.worker-3.5.528.min.js:9577:22
at new Promise ()
at promiseBody (pdf.worker-3.5.528.min.js:9540:18)
at pdf.worker-3.5.528.min.js:9510:13
pdf.worker-3.5.528.min.js:22 Warning: getOperatorList - ignoring XObject: "ReferenceError: window is not defined".

AFAIK window is not accessible inside web worker. I am guessing that's the problem.

stephanrauh added a commit to stephanrauh/pdf.js that referenced this issue Apr 18, 2023
stephanrauh added a commit to stephanrauh/pdf.js that referenced this issue Apr 18, 2023
@stephanrauh
Copy link
Owner

stephanrauh commented Apr 18, 2023

Right you are! During the last couple of weeks, I worked a lot to support server-side rendering, so I missed the real cause of the issue. It's good that you, @sudilshr, mentioned the web worker. I've introduced the bug accidentally when implementing #1659. And kudos for providing me with a test PDF. I didn't have a file to test this particular feature yet, so your file comes in handy!

Your bugfix has landed with version 17.0.0-alpha.1.

Enjoy!
Stephan

@stephanrauh stephanrauh added Solved version 17 Scheduled for version 17 and removed Can't reproduce the bug You've reported a bug, but the feature works fine on my machine. So I don't know how to help you. labels Apr 18, 2023
@stephanrauh
Copy link
Owner

Oops. I've announced your bug fix but somehow I've forgotten to publish the new version. Now it's there. This time for real!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Solved version 17 Scheduled for version 17
Projects
None yet
Development

No branches or pull requests

5 participants