json-viewer
json-viewer copied to clipboard
Uncaught TypeError: Cannot read property 'childNodes' of null
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)
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.
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
I think this is the same case of issue #137
When a url returns XML, this extension is causing the chrome's default xml viewer to not function