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

Can't integrate Mixpanel in a chrome extension under manifest v3 #438

Open
brloman opened this issue Aug 2, 2024 · 8 comments
Open

Can't integrate Mixpanel in a chrome extension under manifest v3 #438

brloman opened this issue Aug 2, 2024 · 8 comments

Comments

@brloman
Copy link

brloman commented Aug 2, 2024

Im migrating a chrome extension from manifest v2 to manifest v3, which moves from background pages to service workers. As service workers don't have access to DOM, window, or document, loading mixpanel library now causes an error 'document undefined'.

Is there any solution to integrate Mixpanel in a chrome extension now that MV2 is deprecated?

Screenshot 2024-08-02 at 09 52 28 Screenshot 2024-08-02 at 09 52 20
@ba32107
Copy link

ba32107 commented Aug 4, 2024

I'm having the same issue. #304 has some ideas on how to work around this. I'm currently debating using the code in that issue or just using the ingestion API and writing the client myself

@brloman
Copy link
Author

brloman commented Aug 4, 2024

I'm having the same issue. #304 has some ideas on how to work around this. I'm currently debating using the code in that issue or just using the ingestion API and writing the client myself

Im wondering how no one else mentioned that issue in #304.

@ba32107
Copy link

ba32107 commented Aug 4, 2024

Probably depends on which exact config you pass to mixpanel, based on those it may or may not attempt to access document.

@brloman
Copy link
Author

brloman commented Aug 5, 2024

Interesting. Do you know which config could be changed to prevent accessing document?

I don't pass any specifc config upon initializing. I call init like this:

mixpanel.init("TOKEN", {api_host:"https://api.mixpanel.com"});

@ba32107
Copy link

ba32107 commented Aug 5, 2024

Do you know which config could be changed to prevent accessing document?

You can check the source to see what's happening, but I don't think it's a good idea to try to guess this. You would essentially be relying on the internal implementation details of the library.

It's better to use the ingestion API, it's not hard. Take a look at https://developer.mixpanel.com/reference/track-event

@doc-han
Copy link

doc-han commented Aug 11, 2024

My comment here #304 (comment) gives you a good idea of why mixpanel doesn't work in MV3. The issue isn't just DOM access.

@coccoalberto97
Copy link

coccoalberto97 commented Sep 20, 2024

Hey, there is something else that I think it's worth mentioning. I have an extension and I use it to inject a content-script in the dom. I can't use this library in the content script because it injects external code, which is not allowed.

I received a Blue Argon strike from the chrome dev team (Blue Argon docs).
I was using an older version of this plugin and this was flagged:

Violating Content:
Code snippet:overlay.js: "var r = document.createElement("script"); r.src = e.resource_protocol + "[www.youtube.com/iframe_api](http://www.youtube.com/iframe_api)"; var i = document.getElementsByTagName("script")[0]; i.parentNode.insertBefore(r, i)"

I updated to v2.55.1 and that snipped is gone, but external script injection is still present in the bundle, I suppose it's just a matter of time before this one gets flagged as well:

var script = document.createElement('script');

var script = document$1.createElement('script');
script.type = 'text/javascript';
script.async = true;
script.defer = true;
script.src = url;
var s = document$1.getElementsByTagName('script')[0];
s.parentNode.insertBefore(script, s);

@brloman
Copy link
Author

brloman commented Oct 28, 2024

Any updates on this?

Would be great if someone from Mixpanel can confirm if Mixpanel-browser library works in a service worker in an MV3 browser extension or not.

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