nodejs-storage icon indicating copy to clipboard operation
nodejs-storage copied to clipboard

Feature request: Browser support

Open shaffeeullah opened this issue 2 years ago • 2 comments

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

shaffeeullah avatar Apr 20 '22 17:04 shaffeeullah

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:

  • jws (deprecated safe-buffer dependency)
    • The browser version on jws should work in Node.js
  • Pumpify (Also has a safe-buffer dependency)

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 avatar Apr 20 '22 17:04 FossPrime

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

FossPrime avatar Jun 15 '22 06:06 FossPrime