mixpanel-js
mixpanel-js copied to clipboard
Fetch support when XMLHttpRequest isn't available
Description
Given I didn't find any official support for this to work with extensions that are implementing the manifest v3, I took this approach to support fetch.
There's still work to do here, but this works provisionally while an official solution comes out:
- We could support batching, this is only supported if
localStorage
andXHR
is enabled, which isn't true for none of these in SWs - Tests were not implemented, we should definitely implement some
How to use this in your SW:
Given you are likely looking for how to implement this for the new MV3 for Chrome Extension, you can simply download the cjs
file under dist (dist/mixpanel.cjs.js
), and put it inside your extension, and then import it in your service worker, for example:
import mixpanel from './mixpanel.js'
mixpanel.js
// ... all the code contained in the cjs file
// replace module.exports = mixpanel;
export default mixpanel;
Then you can use this as you would normally use it.