Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
macintacos opened this issue Aug 24, 2023 · 1 comment · Fixed by #17
Closed

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

macintacos opened this issue Aug 24, 2023 · 1 comment · Fixed by #17

Comments

@macintacos
Copy link
Contributor

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 added a commit that referenced this issue Aug 26, 2023
fix: use the more-targeted `querySelector` to get JSON contents to parse
@belaviyo
Copy link
Owner

Thanks @macintacos

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants