Pdf.js: DataCloneError: Failed to execute 'postMessage' on 'Worker'

Created on 25 Jun 2018  路  11Comments  路  Source: mozilla/pdf.js

Attach (recommended) or Link to PDF file here:

Configuration:

  • Web browser and its version: Electron 2.0.3
  • Operating system and its version: Windows 10
  • PDF.js version: 2.0.489
  • Is a browser extension: no

Steps to reproduce the problem:
Create Ellectron app with angular 6 + pdfjs

What is the expected behavior? (add screenshot)
PDF gets displayed

What went wrong? (add screenshot)

ERROR Error: Uncaught (in promise): DataCloneError: Failed to execute 'postMessage' on 'Worker': TypeError: https.request is not a function could not be cloned.
Error: Failed to execute 'postMessage' on 'Worker': TypeError: https.request is not a function could not be cloned.

In Google Chrome everything works fine.

VadimDez/ng2-pdf-viewer#326

All 11 comments

app with angular 6

This looks like a duplicate of issue #9166, which was caused by a bug in Angular (rather than PDF.js); please refer to https://github.com/angular/zone.js/pull/980.

This issue is related to non-existent PDF - I have an existing PDF, and the error only occurs in electron app. In Google Chrome everything works fine in my case.

I don't think we can do anything on the PDF.js side without more information, most notably a running demo that shows the issue. Moreover, make sure zone.js is updated per the issue above.

Closing since no information shows that this is caused by PDF.js itself. All signs point to the Angular issue mentioned above, and there have been more reports of it there.

The issue is not what the error message says, it's actually something else. Since error handling faced another exception while reporting, things got messed up.

The reason for the issue is, Http module misses "require" method to be precise both Http and Https modules are empty.

When using pdf.js in Chrome browser, it uses PDFFetchStream to read data whereas when using pdf.js in Electron it uses PDFNodeStream. When in Electron, to resolve Http request PDFNodeStream uses Node's Http module ( require('http') ), somehow the http variable got overwritten.

Moving Http import inside PDFNodeStreamFullReader and PDFNodeStreamRangeReader solves the issue that we face.

I don't know why http variable got overwritten or who is responsible for this issue as am very new to frontend development but it would be helpful if someone helps us out to resolve this problem.

@giridharkannan I have same issue but I don't know how to move Http report to both PDFNodeStreamFullReader and PDFNodeStreamRangeReader.

@Farbod29
It's been long and I forgot the context, but I can share my working code snippet. Hope this will be helpful

``typescript if(isElectronBuild()) { pdfjsDisplayAPI.setPDFNetworkStreamFactory((params) => { return new PDFFetchStream(params); }); task = getDocument(pdfUrl); } else { task = getDocument(pdfUrl); }

Screenshot 2019-04-06 21 26 46

@giridharkannan thanks for prompt response,I just added task = getDocument(pdfUrl); here but I don't really know how PDF.js working didn't fix yet.

Screenshot 2019-04-06 21 31 31

Screenshot 2019-04-06 21 37 31
Screenshot 2019-04-06 21 37 55
Screenshot 2019-04-06 21 31 31
Screenshot 2019-04-06 18 45 59
Screenshot 2019-04-06 21 25 04
Screenshot 2019-04-06 18 42 36

@Farbod29 If it's not a overkill, please do share your code snippet to my mail id. And the code snippet that I gave is not be added on pdf.js's code base, rather on your code.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

collinanderson picture collinanderson  路  29Comments

StevenHarlow picture StevenHarlow  路  29Comments

syssgx picture syssgx  路  29Comments

Rob--W picture Rob--W  路  34Comments

Snuffleupagus picture Snuffleupagus  路  28Comments