json-viewer icon indicating copy to clipboard operation
json-viewer copied to clipboard

Uncaught TypeError: Cannot read property 'childNodes' of null

Open remcohaszing opened this issue 6 years ago • 4 comments

I have created the following index.html:

<!doctype html>
<html>
  <head>
    <meta charset="utf-8"/>
    <link rel="stylesheet" href="style.css" />
    <title>Test</title>
  </head>
  <body>
    <a href="https://www.google.com">Click me</a>
    <script src="script.js"></script>
  </body>
</html>

And the following script.js:

(() => {
  function create(type, text = '', attributes = {}) {
    const element = document.createElement(type);
    element.innerText = text;
    Object.entries(attributes).forEach(([name, value]) => {
      element.setAttribute(name, value);
    });
    return element;
  }

  const removed = create('a');
  document.body.append(removed);
  document.body.remove(removed);  // This causes the error.
})();

When this page is opened, an error occurs in the JSON Viewer extension:

Uncaught TypeError: Cannot read property 'childNodes' of null
    at i (viewer.js:1)
    at a (viewer.js:1)
    at HTMLDocument.r (viewer.js:7)

remcohaszing avatar Aug 02 '17 11:08 remcohaszing

I see now that my code was incorrect. Apparently this line causes the error:

document.body.remove()

I don't see any valid use cases for this line of code, but I wouldn't expect an extension to throw an error because of this.

remcohaszing avatar Aug 02 '17 11:08 remcohaszing

Nice, thanks. I ran your test in development and JSON Viewer is failing here: https://github.com/tulios/json-viewer/blob/master/extension/src/json-viewer/check-if-json.js#L10

I'll try to take a look at this today. Thanks again

tulios avatar Aug 02 '17 12:08 tulios

I think this is the same case of issue #137

tulios avatar Aug 02 '17 12:08 tulios

When a url returns XML, this extension is causing the chrome's default xml viewer to not function image image

saisuryakat avatar Aug 30 '21 10:08 saisuryakat