belaviyo / json-beautifier

Convert JSON Strings to a Friendly Readable Format
https://webextension.org/listing/json-beautifier.html
57 stars 14 forks source link

Issue parsing JSON with the "Selection Highlighter" plugin also installed #16

Closed macintacos closed 1 year ago

macintacos commented 1 year ago

When the "Selection Highlighter" plugin is installed, the call here fails with something similar to the following:

SyntaxError: Unexpected non-whitespace character after JSON at position 2074
    at JSON.parse (<anonymous>)
    at inject.js:166:21

When I went into the console to run document.body.textContent.trim(), I saw the following extra bits at the end of what should've been just the JSON content:

<...JSON content here...>    ::highlight(selection_highlighter_highlighted_selection) {\n      background-color: rgba(255,255,0,1);\n    }\n    .selection_highlighter_scroll_markers {\n      pointer-events: none;\n      position: fixed;\n      z-index: 2147483647;\n      top: 0;\n      right: 0;\n      width: 16px;\n      height: 100vh;\n    }

I think this could be resolved by changing this:

  const content = document.body.textContent.trim();

to something like:

  const content = document.querySelector("body > pre").innerText;
belaviyo commented 1 year ago

Thanks @macintacos