mixpanel-js icon indicating copy to clipboard operation
mixpanel-js copied to clipboard

Fetch support when XMLHttpRequest isn't available

Open juanfer0002 opened this issue 2 years ago • 2 comments

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:

  1. We could support batching, this is only supported if localStorage and XHR is enabled, which isn't true for none of these in SWs
  2. 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.

Evidence

image

juanfer0002 avatar Oct 21 '22 15:10 juanfer0002