Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
zddyx258 opened this issue May 23, 2022 · 9 comments

Comments

@zddyx258
Copy link

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

@ujjwalbishnoi
Copy link

Same error occured in production using vite react-ts

@marherb
Copy link

marherb commented Jun 28, 2022

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;

@Arslan-95
Copy link

Arslan-95 commented Oct 7, 2022

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?

@finessevanes
Copy link
Contributor

Is this still an issue?

@MacroChip
Copy link

MacroChip commented Mar 14, 2023

@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
Copy link

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

@finessevanes
Copy link
Contributor

@MacroChip what API are you using?

@MacroChip
Copy link

@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 perawallet/connect#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.

@glitch-txs
Copy link

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 :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants