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.07k stars 435 forks source link

[🐞] CORS error while integrating google adsense #535

Closed harshit-kathuria closed 9 months ago

harshit-kathuria commented 9 months ago

Describe the bug

Integratingg Google Adsense to Partytown, throws CORS error. Works fine running it directly in main thread. As both run on the same domain, why is this happening.

Framework: Sveltekit

File: route/layout.svelte

let scriptEl
  onMount(async () => {
    if (scriptEl) {
      scriptEl.textContent = partytownSnippet()
    }
   .......
}

<svelte:head>
  <script>
    // Forward the necessary functions to the web worker layer
        partytown = {
      forward: ['dataLayer.push'],
    }
    </script>
  <script bind:this={scriptEl}></script>
  <script type="text/partytown" src="https://www.googletagmanager.com/gtm.js?id=GTM-XXXXXXX"></script>
  <script>
    window.dataLayer = window.dataLayer || [];
    function gtag() {
      dataLayer.push(arguments);
    }
    gtag("event", "gtm.js");
    gtag("gtm.start", new Date().getTime());
    gtag("gtm.uniqueEventId", 0);
  </script>
  <script type="text/partytown" src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-XXXXXXX" crossorigin="anonymous">
  </script>
</svelte:head>

Reproduction

NA

Steps to reproduce

Add Google adsense script

Browser Info

Chrome, Safari, Firefox

Additional Information

No response

gioboa commented 9 months ago

Thanks for reporting this issue. The AdSense script is loaded from a different domain. I saw you added crossorigin="anonymous too. So it's a completely different story.

gioboa commented 9 months ago

This is a duplicate of #360. Let's continue the issue there. Thanks