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

Clarity 0.7.43 breaks partytown integration #645

Open
lampask opened this issue Aug 6, 2024 · 7 comments
Open

Clarity 0.7.43 breaks partytown integration #645

lampask opened this issue Aug 6, 2024 · 7 comments

Comments

@lampask
Copy link

lampask commented Aug 6, 2024

Describe the bug
New mediaInsertRule (and mediaDeleteRule) breaks clarity deployment inside webworker. We are running clarity through partytown and CSSMediaRule is undefined there, accessing it results in error printed to console.

This is only present in version 0.7.43, where the rules first appear. Previously version 0.7.41 ran without any issues.

TypeError: CSSMediaRule is undefined
    _a https://www.clarity.ms/s/0.7.43/clarity.js:4
    start https://www.clarity.ms/s/0.7.43/clarity.js:4
    pi https://www.clarity.ms/s/0.7.43/clarity.js:4
    Ui https://www.clarity.ms/s/0.7.43/clarity.js:4
    Ui https://www.clarity.ms/s/0.7.43/clarity.js:4
    Ji https://www.clarity.ms/s/0.7.43/clarity.js:4
    Gi https://www.clarity.ms/s/0.7.43/clarity.js:4
    anonymous https://www.clarity.ms/s/0.7.43/clarity.js:4
    anonymous https://www.clarity.ms/s/0.7.43/clarity.js:4
    run http://localhost:5173/~partytown/debug/partytown-ww-sw.js?v=0.10.2:713
    receiveMessageFromSandboxToWorker http://localhost:5173/~partytown/debug/partytown-ww-sw.js?v=0.10.2:1811
    receiveMessageFromSandboxToWorker http://localhost:5173/~partytown/debug/partytown-ww-sw.js?v=0.10.2:1819

Repro Steps

  1. Setup project with partytown
  2. Add clarity snippet in script tag with type="text/partytown"
@ender336
Copy link
Contributor

ender336 commented Aug 7, 2024

thanks, have a PR coming out to fix this shortly

@nicksrandall
Copy link

@ender336 I see your PR was merged, any idea when this will go out?

@lampask
Copy link
Author

lampask commented Aug 22, 2024

The CDN now serves the version 0.7.45 and the issue still persists, I have tried to look into it, but I am not sure why it is not working.

When I console.log from within the worker:

<script type="text/partytown">
   console.log(window.CSSMediaRule);
   console.log('CSSMediaRule' in window);
   console.log(window.hasOwnProperty(CSSMediaRule));
   console.log(window.CSSMediaRule !== undefined);
</script>

I get these results:

undefined
true
true
false

It looks like the property is there but it is also set as undefined for some reason.

@ender336
Copy link
Contributor

hmmm I'll take a look thanks for the report

@ender336
Copy link
Contributor

@lampask are you still seeing this issue? I got the partytown repo running and things seemed to work - there's a test in there specifically for Clarity.

https://partytown.builder.io/tests/integrations/clarity/standard.html

I think they were going to start to polyfill CSSMediaRule: BuilderIO/partytown#614 but it looks like that didn't go in.

If you're still seeing the issue can you email the site that you're having an issue with to [email protected]

@lampask
Copy link
Author

lampask commented Aug 28, 2024

@ender336 The link you provided is a test page for standard clarity without including it in the worker. It is a bit of a confusing naming - in the standard version they just use type text/javascript to run the default clarity snippet that downloads clarity and runs it in the main thread.

The right test is here: https://partytown.builder.io/tests/integrations/clarity/

This one (just named Partytown Clarity), uses the snippet inside type text/pariytown but also has a script that intercepts the script tag injection and replaces the source with a self-hosted bundle that has an older version of clarity. Hosted here: https://partytown.builder.io/tests/integrations/clarity/clarity.bundle.js

This is the script that intercepts default behaviour:

    const observer = new MutationObserver(mutations => {
      mutations.forEach(({ addedNodes }) => {
        addedNodes.forEach(node => {
          // For each added script tag
          if (node.nodeType === 1 && node.tagName === 'SCRIPT') {
            const src = node.src || '';
            if (node.src.includes('clarity.js')) {
              node.type = 'text/partytown';
              node.src = './clarity.bundle.js';
            }
          }
        });
      });
    });
    // Starts the monitoring
    observer.observe(document.documentElement, {
      childList: true,
      subtree: true,
    });

When deploying app I could probably do the same "hack", but I wanted to avoid that in favor of serving clarity from GTM.

@anicolaides
Copy link

Hey everyone,

Is this still an issue?

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

No branches or pull requests

4 participants