crxjs / chrome-extension-tools

Bundling Chrome Extensions can be pretty complex. It doesn't have to be.
https://crxjs.dev/vite-plugin
2.75k stars 182 forks source link

Cannot use firestore in background script: XMLHttpRequest is not defined #779

Open snorreks opened 1 year ago

snorreks commented 1 year ago

Build tool

Vite

Where do you see the problem?

Describe the bug

When i try to use firestore v10 in background script i get the following error:

Uncaught ReferenceError: XMLHttpRequest is not defined
    at ac.g (xmlhttp.js:170:3)
    at k.ha (xmlhttp.js:29:36)
    at ic (channelrequest.js:582:19)
    at gc (channelrequest.js:511:8)
    at k.Na (webchannelbase.js:1486:13)
    at ub (run.js:116:15)

I am very certain that firestore is now using fetch instead of XMLHttpRequest, but maybe i am wrong. Using "firebase": "10.3.1"

Reproduction

https://github.com/snorreks/crxjs-vite-firestore

Logs

xmlhttp.js:170 Uncaught ReferenceError: XMLHttpRequest is not defined

@firebase/firestore: Firestore (10.3.1): Could not reach Cloud Firestore backend. Backend didn't respond within 10 seconds.
This typically indicates that your device does not have a healthy Internet connection at the moment. The client will operate in offline mode until it is able to successfully connect to the backend.

@firebase/firestore: Firestore (10.3.1): WebChannelConnection RPC 'Listen' stream 0x814b5887 transport errored: Qd {type: 'c', target: Q, g: Q, defaultPrevented: false, status: 1}

System Info

System:
    OS: Linux 6.4 Fedora Linux 38 (Workstation Edition)
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
    Memory: 5.46 GB / 15.44 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 18.17.1 - /usr/bin/node
    Yarn: 1.22.19 - ~/.npm-global/bin/yarn
    npm: 9.6.7 - /usr/bin/npm
    pnpm: 8.7.1 - ~/.local/share/pnpm/pnpm
  Browsers:
    Brave Browser: 116.1.57.57
    Chrome: 116.0.5845.140
  npmPackages:
    @crxjs/vite-plugin: ^1.0.14 => 1.0.14 
    vite: ^4.4.9 => 4.4.9

Severity

blocking all usage of RPCE

adam-s commented 11 months ago

I am very certain that firestore is now using fetch instead of XMLHttpRequest, but maybe i am wrong.

Your error is pointing to Google's Closure library. https://github.com/google/closure-library/blob/master/closure/goog/net/xmlhttp.js#L170 This isn't a crxjs issue and likely should be labeled can't fix.