Ng2-pdf-viewer: Cannot read property 'sendWithPromise' of null error

Created on 18 Sep 2018  路  4Comments  路  Source: VadimDez/ng2-pdf-viewer

Bug Report or Feature Request (mark with an x)
- [ ] Regression (a behavior that used to work and stopped working in a new release)
- [X] Bug report -> please search issues before submitting
- [ ] Feature request
- [ ] Documentation issue or request

I've got an error log from one of customers.

TypeError: Cannot read property 'sendWithPromise' of null
  at e.getPage(/main.fcbd366b59adeaccde73.js:1:2580545)
  at e.getPage(/main.fcbd366b59adeaccde73.js:1:2562311)
  at e.renderPage(/main.fcbd366b59adeaccde73.js:1:2100087)
  at e.updateSize(/main.fcbd366b59adeaccde73.js:1:2098625)
  at ? (/main.fcbd366b59adeaccde73.js:1:2095964)
  at i(/main.fcbd366b59adeaccde73.js:1:2155073)
  at t.invokeTask(/polyfills.6daafc40a5cb42269e22.js:1:8745)
  at Object.onInvokeTask(/main.fcbd366b59adeaccde73.js:1:313689)
  at t.invokeTask(/polyfills.6daafc40a5cb42269e22.js:1:8666)
  at e.runTask(/polyfills.6daafc40a5cb42269e22.js:1:3929)
  at e.invokeTask(/polyfills.6daafc40a5cb42269e22.js:1:9835)
  at invoke(/polyfills.6daafc40a5cb42269e22.js:1:9726)
  at n.args.(anonymous function)(/polyfills.6daafc40a5cb42269e22.js:1:25027)

I couldn't reproduce the issue but here are my thoughts.

It seems that this error appears after a user tries to change page index in the PDF preview.
The piece of code where the issue happenes looks like this

var l=this.messageHandler.sendWithPromise("GetPage",{pageIndex:t}).then(function(e){if(n.destroyed)throw new Error("Transport destroyed");var l=new M(t,e,n,n._params.pdfBug);

Since the issue happens after renderPage and getPage my guess is that the source of issue is the not initialized _pdf variable which is at 388 line of this file
https://github.com/VadimDez/ng2-pdf-viewer/blob/master/src/app/pdf-viewer/pdf-viewer.component.ts

Could it be that I'm right and that additional check like this

if (!this._pdf) {
      return;
    }

could fix the issue?
Thanks

stale

All 4 comments

Did you ever solve this issue?

I am curious, too. I do encounter that error in our application sometimes. Unfortunately it is not consistently to reproduce at all.

I have the same behavior, but on a Vue project! So it has to do something with pdf-js

https://github.com/FranckFreiburger/vue-pdf/

I found a solution for my problem, probably will be the same for Angular.

I assume you display the pdf in a modal and close it, then trying to open another file which leads to this error. Before displaying another file I unset the file variable. The pdf component renders in a block with an if statement checking for the existence of it.

<template v-if="file">
   <pdf...... />
</template>
onClose(){
    this.file = null
}

This will destroy the pdf component and re-renders it with new data.

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xmran picture xmran  路  4Comments

asadullazadeh picture asadullazadeh  路  4Comments

ShayShaked picture ShayShaked  路  5Comments

GarciaFreelancer picture GarciaFreelancer  路  6Comments

VadimDez picture VadimDez  路  5Comments