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

Websocket Provider's btoa helper's context [browser only] #3508

Closed
vsleibenko opened this issue May 8, 2020 · 0 comments · Fixed by #3509
Closed

Websocket Provider's btoa helper's context [browser only] #3508

vsleibenko opened this issue May 8, 2020 · 0 comments · Fixed by #3509
Labels
1.x 1.0 related issues Bug Addressing a bug

Comments

@vsleibenko
Copy link
Contributor

Expected behavior

I can connect via Websocket Provider using url with credentials 'wss://USERNAME:PASSWORD@WSS_ENDPOINT'

Actual behavior

Received TypeError: Illegal invocation

Seems like 'btoa' this isn't pointing to Window object as it should but to WebsocketProvider's object

NOTE: Binding 'btoa' to Window object in 'helpers.js' solves the issue
_btoa = btoa.bind(window); (web3-providers-ws/src/helpers.js:21)
Locking context with arrow function also works
_btoa = (str) => btoa(str); (web3-providers-ws/src/helpers.js:21)

Steps to reproduce the behavior

  1. Try to connect to url type of 'wss://USERNAME:PASSWORD@WSS_ENDPOINT' using WebsocketProvider (web version)

Logs

TypeError: Illegal invocation
new WebsocketProvider
node_modules/web3-providers-ws/src/index.js:73

70 | var parsedURL = helpers.parseURL(url);
71 |
72 | if (parsedURL.username && parsedURL.password) {
73 | this.headers.authorization = 'Basic ' + helpers.btoa(parsedURL.username + ':' + parsedURL.password);

Environment

web3.js: 1.2.7
Chrome: 81.0
OS: MacOS Catalina (10.15.4 )

@vsleibenko vsleibenko changed the title Websocket Provider's btoa helper's context [BROWSER ONLY] Websocket Provider's btoa helper's context [browser only] May 8, 2020
@cgewecke cgewecke added 1.x 1.0 related issues Bug Addressing a bug labels May 8, 2020
@ryanio ryanio mentioned this issue May 8, 2020
13 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1.x 1.0 related issues Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants