BuilderIO / partytown

Relocate resource intensive third-party scripts off of the main thread and into a web worker. 🎉
https://partytown.builder.io
MIT License
13.06k stars 434 forks source link

Unexpected SyntaxError: Unexpected end of JSON input #160

Closed phoebelmno closed 2 years ago

phoebelmno commented 2 years ago

Trying to implement GTM through partytown and am getting this error:

image

In the network tab there's one url which is returning a 403 error, and the url just returns the string '1d':

image image I think partytown is attempting to parse this string as json which is causing the error, but they might be unrelated issues.

Should partytown be able to handle non json responses better - should this be a warning instead?

Does anyone have any suggestions on how to resolve?

steve8708 commented 2 years ago

hey @phoebelmno - we've just created an issue template, could you update your issue here to provide all the information the template asks for? it'll help us look into your issue https://github.com/BuilderIO/partytown/issues/new?assignees=&labels=&template=bug_report.md&title=

pasting below to make things easier:


Describe the bug A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to '...'
  2. Click on '....'
  3. Scroll down to '....'
  4. See error

Reproduction link Please include a link to a Stackblitz or Codesandbox reproducing the issue. We will need to see the issue reproduced with hand-written code - we can't debug giant minified third party scripts directly. If you do not include a clean and simple reproduction of your issue, we won't be able to look into it until you do.

Expected behavior A clear and concise description of what you expected to happen.

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Add any other context about the problem here.

garethweaver commented 2 years ago

I've figured it out, this was caused by us injecting

<script type="application/ld+json">{"@context": "https://schema.org", "@type": "FAQPage", "mainEntity": [{"@type":"Question", ...}]}</script>

into our page to provide indexing to Google for our FAQ's. Partytown is trying to parse this and for some reason somehow erroring. I'm guessing we need partytown to ignore these types of JSON-LD scripts inside the DOM?

https://developers.google.com/search/docs/advanced/structured-data/faqpage

phoebelmno commented 2 years ago

Looked into this some more and have found our issue. We have a tag in GTM which searches for all JSON+LD blocks on the page. It then parses the content of each one to check for a specific block of JSON+LD. If it does not find that block it injects the block into the head of the page.

When GTM was being run inside the partyTown service worker, it was erroring because we couldn’t access the .innerHTML of any Githubissues.

  • Githubissues is a development platform for aggregating issues.