TypeError: Cannot read properties of null (reading 'parentNode')
See original GitHub issueHi @stephanrauh
Occasionally we receive crash reports that look like this:
TypeError: Cannot read properties of null (reading 'parentNode')
at webViewerWheel(/assets/pdf-viewer/viewer-2.16.451.min.js:44:61771)
We use ngx-extended-pdf-viewer
in a popup and this error appears right after popup is closed.
Most probably it happens because some listeners are not yet removed while html node is already destroyed.
We tried the following hack in close event handler:
protected close(result?: void) {
// wait for scripts to load
if (!this.componentInitialized && this.pdfSrc != null) {
this.warn('PDF engine is not initialized yet');
return;
}
// unbind offending event listeners
const application = (window as any).PDFViewerApplication;
const unbindWindowEvents = application?.unbindWindowEvents?.bind(application);
if (typeof unbindWindowEvents === 'function') {
unbindWindowEvents();
} else {
this.warn('unbindWindowEvents failed');
}
super.close(result);
}
but crash report contains log entry unbindWindowEvents failed
, it means that viewer is in some intermediate state when PDFViewerApplication
is null but it is running.
It is minor issue but we would like to know what are possible options to avoid this error?
Version info
- Version of ngx-extended-pdf-viewer 15.2.0
Desktop (please complete the following information):
- Browser Chrome 108.0.0
Issue Analytics
- State:
- Created 9 months ago
- Comments:8 (5 by maintainers)
Top Results From Across the Web
Javascript error: Cannot read property 'parentNode' of null
There are two possibilities: editInput is a typo, and the actual id of that element is different (ids are case-sensitive).
Read more >Cannot read properties of null (reading 'parentNode') · Issue ...
I've been pulling my hair out trying to figure out what was throwing this error and in my case I was able to...
Read more >"Cannot read property parentNode" error - Vue Forum
Given the mention of parentNode in the error message, my only guess would be that it is somehow related to the use of...
Read more >Cannot read property parentNode of null — DataTables forums
To summarize it: 1. The problem is with datatables which are hidden in tabs. 2. There is an exception in a code that...
Read more >Cannot read properties of null (reading 'parentNode')
Cannot read properties of null (reading 'parentNode') · Reproduce the problem in our shared sample or · Share a simple issue reproducing sample...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@stephanrauh it does work, I made obvious mistake in condition (
typeof
was missing), but now when error is corrected, everything works as expected. Since PDFViewerApplication is singleton, the correct fix in the library itself may be too convoluted so I’m not sure if it is worth it.Exposing a method allowing you to unbind the event listeners isn’t that much work, so it might be worth it. To be honest, documenting the feature is more work than implementing it. I wonder if I should add a page dedicated to popups to the showcase.