walletconnect-monorepo icon indicating copy to clipboard operation
walletconnect-monorepo copied to clipboard

use Standalone Client Tips: Error: ws does not work in the browser. Browser clients must use the native WebSocket object

Open zddyx258 opened this issue 3 years ago • 2 comments

Error: ws does not work in the browser. Browser clients must use the native WebSocket object

zddyx258 avatar May 23 '22 03:05 zddyx258

Same error occured in production using vite react-ts

ujjwalbishnoi avatar Jun 09 '22 08:06 ujjwalbishnoi

Same error occured in production using vite react-ts

error is global is not define may edit vite.config.js export default defineConfig({ ..., define: { global: "globalThis", }, }); and then add Buffer in main.ts import { Buffer } from "buffer"; window.Buffer = Buffer;

marherb avatar Jun 28 '22 07:06 marherb

error Error: ws does not work in the browser. Browser clients must use the native WebSocket object
    at new module.exports (...\node_modules\@walletconnect\socket-transport\node_modules\ws\browser.js:4:1)

I cant fix it. Who know, how to do it?

Arslan-95 avatar Oct 07 '22 08:10 Arslan-95

Is this still an issue?

finessevanes avatar Feb 16 '23 09:02 finessevanes

@finessevanes yes for vite projects (maybe not vite 4 tho). @marherb 's solution does work, but is a little heavy handed (i.e. the string "global" is replaced with "globalThis" so things like "global-warming" become "globalThis-warming".

MacroChip avatar Mar 14 '23 22:03 MacroChip

A slightly more surgical approach is to use "global.WebSocket": "globalThis.WebSocket", instead of global: "globalThis" @marherb if you want, edit your post if it works for you

MacroChip avatar Mar 14 '23 23:03 MacroChip

@MacroChip what API are you using?

finessevanes avatar Mar 15 '23 02:03 finessevanes

@finessevanes Did some diving because I am not using it directly. TLDR I think walletconnect v2 fixed this. I am also integrating Pera (linked above at https://github.com/perawallet/connect/issues/101) Only moderate confidence on the following: Pera connect ultimately gets to @walletconnect/http which seems to have disappeared in walletconnect v2. The spiritual successor is https://github.com/WalletConnect/walletconnect-utils/blob/24f59297429ee351d741d3fb84e558f0a1ede159/jsonrpc/ws-connection/src/ws.ts#L21 which, I believe, would not cause an error.

MacroChip avatar Mar 15 '23 20:03 MacroChip

I’m closing this issue because it has been inactive for a few months.

Please reopen if you still encounter this issue with the latest version :)

glitch-txs avatar Aug 08 '23 17:08 glitch-txs