nuxt-modules / partytown

Partytown integration for Nuxt. Run third-party scripts from a web worker.
MIT License
320 stars 8 forks source link

$crisp example and other does not work #98

Closed green-cats closed 1 year ago

green-cats commented 2 years ago

Hi, very cool feature, but I failed to implement any example, even direct copy - paste... Nuxt 3, In console log I can see worker, but can't see chat button, also window.$crisp return a strange function instead of the $crisp object, I tried call this function like window.$crisp() -> undefined

Thank you

danielroe commented 2 years ago

Would you provide a reproduction? 🙏

P4sca1 commented 2 years ago

@danielroe https://stackblitz.com/edit/github-u2eqr4 Comment out type: 'text/partytown' in nuxt.config.ts line 15 and you will see the crisp widget in the bottom right corner. With partytown enabled, crisp does not work.

lnfel commented 1 year ago

Apparently the same thing is happening when partytown is used in an HTML project (no framework). Was looking for similar issue and it brought me here so I might just add more info on the matter.

Sample code in my html file:

<script>
  window.$crisp=[];
  window.CRISP_WEBSITE_ID="some-id-here";
</script>
<script type="text/partytown" defer src="https://client.crisp.chat/l.js"></script>

Crisp's l.js script successfully ran by partytown but upon executing client.js (called by l.js) I receive an error:

SyntaxError: Unexpected token '(' (at client.js?de6ca11:9:30131)
    at new Function (<anonymous>)
    at run (partytown-ww-sw.js?v=0.7.3:692:9)
    at partytown-ww-sw.js?v=0.7.3:1707:37

Of course if I remove type="text/partytown" on the script tag crisp works fine.

danielroe commented 1 year ago

Yes, this is not an issue with the Nuxt module; if you are experiencing an issue in a plain HTML project, the place to raise the issue is at https://github.com/BuilderIO/partytown, not here.

marcaureln commented 7 months ago

In a matter of fact, this still doesn't work (Crisp isn't showing up).

export default defineNuxtConfig({
  modules: ['@nuxtjs/partytown'],
  partytown: {
    forward: ['$crisp', '$crisp.push'],
  },
  app: {
    head: {
      script: [
        // Insert your CRISP Script here e.g.:
        { innerHTML: 'window.$crisp = []; window.CRISP_WEBSITE_ID = "my-crisp-website-id"' },
        { src: 'https://client.crisp.chat/l.js', async: true, type: 'text/partytown' },
      ],
    },
  },
})

And, simply replacing type: 'text/partytown' with type: 'text/javascrip' fix the issue. And, nothing usefull in log even with debug: true in partytown config.

danielroe commented 7 months ago

It might be that you need now to proxy crisp.