question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

What should be the value for `workerSrc`?

See original GitHub issue

Link to PDF file (or attach file here):

Configuration:

  • Web browser and its version: Chrome 57.0.2987.133
  • Operating system and its version: OSX 10.11.6
  • PDF.js version: 1.7.365
  • Is an extension: bundled via webpack 2.2.1

I tried to follow the documentation for webpack but it’s not working (keep getting setting up fake worker), probably due to me not understanding what exactly should go into workerSrc.

Is workerSrc:

  • a URL that’ll get resolved by the browser? e.g. PDFJS.workerSrc = '/pdf.worker.js';
  • a Node require spec that’ll get resolved and bundled into the same file via webpack & node? e.g. PDFJS.workerSrc = 'pdfjs-dist/build/pdf.worker.js';
  • a relative path that’ll get resolved and bundled into the same file via webpack & node? e.g. PDFJS.workerSrc = '../../node_modules/pdfjs-dist/build/pdf.worker.js';
  • something else?

Thanks for any pointers.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:6
  • Comments:18 (4 by maintainers)

github_iconTop GitHub Comments

57reactions
luistakcommented, Aug 6, 2019

Try this:

  const pdfjs = await import('pdfjs-dist/build/pdf');
  const pdfjsWorker = await import('pdfjs-dist/build/pdf.worker.entry');

  pdfjs.GlobalWorkerOptions.workerSrc = pdfjsWorker;

  ...
9reactions
Nataliasemcommented, Jul 1, 2021

I use Pdfjs v2.8.335 with legacy supporting in this way:

import * as pdfjsLib from ‘pdfjs-dist/legacy/build/pdf’ import PDFJSWorker from ‘pdfjs-dist/legacy/build/pdf.worker.entry’

pdfjsLib.GlobalWorkerOptions.workerSrc = PDFJSWorker

Read more comments on GitHub >

github_iconTop Results From Across the Web

CSP: worker-src - HTTP - MDN Web Docs
The HTTP Content-Security-Policy (CSP) worker-src directive specifies valid sources for Worker, SharedWorker, or ServiceWorker scripts.
Read more >
No PDFJS.workerSrc specified - Stack Overflow
I had a similar error and I fixed it by specifying the pdf.worker.js explicitly at the end of the pdf.js if (!PDFJS.workerSrc &&...
Read more >
Examples
This tutorial shows how PDF.js can be used as a library in a web browser. ... window['pdfjs-dist/build/pdf']; // The workerSrc property shall be...
Read more >
CSP: worker-src - HTTP - UDN Web Docs: MDN Backup
The server must generate a unique nonce value each time it transmits a policy. It is critical to provide an unguessable nonce, as...
Read more >
How to add worker-src to the trusted sources of Web Security ...
As a workaround, the worker-src can be set into the 'Content Security ... Add the worker-src blob:; at the Http header value field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found