googleapis / nodejs-storage

Node.js client for Google Cloud Storage: unified object storage for developers and enterprises, from live data serving to data analytics/ML to data archiving.
https://cloud.google.com/storage/
Apache License 2.0
889 stars 367 forks source link

Feature request: Browser support #1883

Open shaffeeullah opened 2 years ago

shaffeeullah commented 2 years ago

This client library is not currently supported in the browser. We have received many requests for this feature and are working toward supporting this. We'll keep this issue updated with any progress we're able to share.

Existing requests: https://github.com/googleapis/nodejs-storage/issues?q=is%3Aissue+label%3Aweb

FossPrime commented 2 years ago

I've made a sample sandbox with both a WebContainer and a browser implemation that will currently fail but should start working once fixes are implemented and published to npm under the latest tag

https://stackblitz.com/edit/public-bug-gcs-uploader

Dependencies that would need to be upgraded or made optional:

Screenshot 2022-04-20 12 09 12

WebContainers

Wrapping this in WebContainers might work quickly if the deprecated Node Crypto dependencies were dropped in favor of the Node 16 WHATWG WebCrypto api. The following error is what I got in my attempt to work around the lack of Chrome support.

TypeError: this[D].init is not a function
    at new Sign (https://vitejs-vite-tgnfu8.w.staticblitz.com/blitz.49c6d2ee58ce7c1528881cc6d46ebf056b3b42bf.js:6:1135213)
    at Object.createSign (https://vitejs-vite-tgnfu8.w.staticblitz.com/blitz.49c6d2ee58ce7c1528881cc6d46ebf056b3b42bf.js:6:808195)
    at Object.sign (/home/projects/vitejs-vite-tgnfu8/node_modules/jwa/index.js:151:25)
    at Object.jwsSign [as sign] (/home/projects/vitejs-vite-tgnfu8/node_modules/jws/lib/sign-stream.js:32:24)
    at GoogleToken.requestToken (/home/projects/vitejs-vite-tgnfu8/node_modules/gtoken/build/src/index.js:225:31)
    at GoogleToken.getTokenAsyncInner (/home/projects/vitejs-vite-tgnfu8/node_modules/gtoken/build/src/index.js:163:21)
    at GoogleToken.getTokenAsync (/home/projects/vitejs-vite-tgnfu8/node_modules/gtoken/build/src/index.js:142:55)
    at GoogleToken.getToken (/home/projects/vitejs-vite-tgnfu8/node_modules/gtoken/build/src/index.js:94:21)
    at JWT.refreshTokenNoCache (/home/projects/vitejs-vite-tgnfu8/node_modules/google-auth-library/build/src/auth/jwtclient.js:171:36)
    at JWT.refreshToken (/home/projects/vitejs-vite-tgnfu8/node_modules/google-auth-library/build/src/auth/oauth2client.js:152:24)
FossPrime commented 2 years ago

Relevant update, Bun bundler uses WebStreams for a 3x performance improvement over Node Streams

https://gist.github.com/Jarred-Sumner/90db1a06c5e7b1c1ab55b5581c62a86d

https://twitter.com/jarredsumner/status/1532322146713710592?s=20&t=yCa_LXu67NnPqzd5eFDsHg