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.

TypeError: Cannot read properties of null (reading 'parentNode')

See original GitHub issue

Hi @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:open
  • Created 9 months ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
kemskycommented, Dec 16, 2022

@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.

0reactions
stephanrauhcommented, Dec 16, 2022

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.

Read more comments on GitHub >

github_iconTop 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 >

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