tulios / json-viewer

It is a Chrome extension for printing JSON and JSONP.
https://chrome.google.com/webstore/detail/json-viewer/gbmdgpbipfallnflgajpaliibnhdgobh
MIT License
3.31k stars 678 forks source link

Uncaught TypeError: Cannot read property 'childNodes' of null #160

Open remcohaszing opened 7 years ago

remcohaszing commented 7 years ago

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 commented 7 years ago

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.

tulios commented 7 years ago

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 commented 7 years ago

I think this is the same case of issue #137

saisuryakat commented 3 years ago

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