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

Warning: Setting up fake worker #136

Closed
philippendrulat opened this issue Sep 3, 2019 · 19 comments
Closed

Warning: Setting up fake worker #136

philippendrulat opened this issue Sep 3, 2019 · 19 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. enhancement New feature or request Solved

Comments

@philippendrulat
Copy link

Describe the bug
See title. We are using Spring boot for the server and copy our files in the "public" folder. This means we changed angular.json/projects/PROJECT/architect/build/options/outputPath to ../resources/public and serve the "public" folder to the client.
We saw that the default lookup path for the worker is "../build/pdf.worker.js", which seems to not exist.
Do we need to copy the worker.js file to the correct location or do we set the worker.js location in pdfjs directly?

Version info

  • Version of ngx-extended-pdf-viewer: 1.0.2
@stephanrauh
Copy link
Owner

You don't need to do anything. If you PDF file is displayed, everything's fine.

I'm still trying to find out what these weird messages mean. I'm pretty sure it's a false positive. The default lookup path is also a puzzle. It shouldn't matter because the worker is imported by the angular.json (if you've followed my instructions, that is).

I'm keeping the ticket open. It's a good reminder to investigate the topic.

@stephanrauh stephanrauh added Confirmed I've managed to reproduce the bug. That's great news: chances are I'll solve it. nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly labels Sep 3, 2019
@Catscratch
Copy link

Hi guys.

I have the same problem. I thought pdfjs is doing the heavy load in a webworker for performance increasements. Currently when loading large PDFs the whole web application is blocked by this process which means I cannot interact with any of the other components outside pdfjs.

Also the browser brings up the message that a script is taking long time and ask me if I want to kill this script.

Shouldn't the webworker solve this problem? And at least the application should stay responsive?

@stephanrauh
Copy link
Owner

stephanrauh commented Sep 4, 2019

Sounds like your PDFs are really large. How many megabytes, how many pages are we talking about?

@stephanrauh
Copy link
Owner

BTW, it's an interesting theory that the "fake worker" stuff means pdf.js can't setup a worker thread. Maybe it's a hot trace. Thanks for the hint!

@Catscratch
Copy link

Sounds like your PDFs are really large. How many megabytes, how many pages are we talking about?

That is one of our test PDFs. Very heavy.
https://www.obwb.ca/library/okanagan-basin-waterscape-poster/

@stephanrauh
Copy link
Owner

If I get mozilla/pdf.js#7612 right, the pdf.worker.js must be in a file of its own (as opposed to being bundled with pdf.js). Otherwise it can't be run in a service worker thread.

@stephanrauh
Copy link
Owner

You sample file is heavy indeed. My Firefox needed several minutes to open the file (using the native viewer). Adding Angular and a falsy webworker configuration probably doesn't make things better.

However, the PDF itself looks really nice. I guess someone (you?) has spent a lot of energy and enthusiasm on it. Awesome!

@stephanrauh
Copy link
Owner

Finally, I've found an explanation what the fake worker is: https://www.codeproject.com/articles/568136/porting-and-extending-pdfjs-to-nodejs (scroll down to "Fake worker for web worker").

@stephanrauh
Copy link
Owner

Good news: I've figured out how to use the service worker, and it improves the performance of the PDF viewer a lot. I'm publishing the new version this evening after adding the documentation.

Thanks for nudging into the right direction!

@stephanrauh
Copy link
Owner

@Catscratch Completely off-topic - but when I opened your test document, this sentence caught my eye: "many say we should pay for the water based on how much we use". I can't believe it: you don't have water meters? They are so common in Europe I thought they're used everywhere. :)

@stephanrauh
Copy link
Owner

Since version 1.5.0 you can use the service worker. Currently it's not configurable; it's always /assets/pdf-worker.js. So you have to rename the file pdf.worker-es5.js to support IE11.

Basically, that's the only thing blocking the issue from closing.

@philippendrulat
Copy link
Author

I don't know how to make it run.
I copied pdf.worker.js into /assets/ folder and tried both pdf-worker.js and pdf.worker.js, but I still get the warning: Setting up fake worker.

I also cloned https://github.com/stephanrauh/extended-pdf-viewer-showcase ran npm i and npm start and I still get the warning.

Is there another demo project I can use?

@philippendrulat
Copy link
Author

PS: with the new Version 1.5.0 I get the error "ERROR Error: "Uncaught (in promise): Error: Invalid pages rotation angle.".
I did a little research and it seems the error happened since 1.4.0.
In 1.3.1 there was no error

@Catscratch
Copy link

@Catscratch Completely off-topic - but when I opened your test document, this sentence caught my eye: "many say we should pay for the water based on how much we use". I can't believe it: you don't have water meters? They are so common in Europe I thought they're used everywhere. :)

Sorry to disappoint you, but it's not my document. It's just a random one from the internet that I use for testing. ;-)

@stephanrauh
Copy link
Owner

@philippendrulat I'm still fighting with ES5 support for the PDF worker, so I didn't wan't to commit my code yesterday. Sorry for the inconvenience!

BTW: the pdf.worker.js file should be available as localhost:4200/assets/pdf.worker.js.

stephanrauh added a commit that referenced this issue Sep 9, 2019
stephanrauh added a commit to stephanrauh/extended-pdf-viewer-showcase that referenced this issue Sep 9, 2019
@stephanrauh
Copy link
Owner

@philippendrulat Now it's landed. Please update to version 1.5.1. It fixes the rotation bug and allows you to define a custom path for the pdf worker. I needed that for IE11 support.

Updating https://github.com/stephanrauh/extended-pdf-viewer-showcase should give you a working example. It's the same as https://pdfviewer.net.

@Catscratch
Copy link

Catscratch commented Sep 10, 2019

Thanks Stephan.

I don't get things running here.
I updated to 1.5.1 and added defaultOptions.workerSrc = './assets/pdf.worker-es5.js';to app.component.ts.

Furthermore I checked that the asset is accessible through the browser. It is!

But I still get the "setting up fake worker" message. Any chance to debug into here?

I solved it.

I had to modify the scripts node in the angular.json to match the right js file. (es5 or not) to use the correct worker js.

Also I had toi add the asset to the angular build.

{
 "glob": "pdf.worker-es5.js",
 "input": "node_modules/ngx-extended-pdf-viewer/assets",
 "output": "/assets/"
}

@stephanrauh
Copy link
Owner

@Catscratch Correct! I tried to document these steps, but I'm not sure I've managed to finish that. If there's something missing in the doc, just tell me.

BTW, I'm glad it finally works on your PC!

@stephanrauh stephanrauh removed the nuisance a bug that only shows in the logs; or: a bug with an obvious work-around every user finds quickly label Sep 10, 2019
@stephanrauh stephanrauh added bug Something isn't working enhancement New feature or request labels Sep 10, 2019
@Catscratch
Copy link

Catscratch commented Sep 16, 2019

@stephanrauh
Only difference is, I switched to the newer versions without "-es5" suffix.

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. enhancement New feature or request Solved
Projects
None yet
Development

No branches or pull requests

3 participants