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

"accountsChanged" event not fired upon logout (Chrome) #7101

Closed
lnbc1QWFyb24 opened this issue Sep 4, 2019 · 1 comment · Fixed by #7161
Closed

"accountsChanged" event not fired upon logout (Chrome) #7101

lnbc1QWFyb24 opened this issue Sep 4, 2019 · 1 comment · Fixed by #7161
Labels

Comments

@lnbc1QWFyb24
Copy link

Describe the bug

The accountsChanged event does not fire when a user logs out of MetaMask on Chrome, but works correctly on FireFox.

To Reproduce

  • Open up Chrome
  • Register a callback for the accountsChanged event:
window.ethereum.on('accountsChanged', console.log)
  • Login to MetaMask
  • Logout of MetaMask
  • Chrome will not show a log, but Firefox will

Expected behavior

The accountsChanged event should call the callback when the user logs out as it does in Firefox.

Browser details (please complete the following information):

  • OS: OS X
  • Browser: chrome
  • MetaMask Version: 7.1.0
@Gudahtt
Copy link
Member

Gudahtt commented Sep 10, 2019

I was able to reproduce this. Both Chrome and Firefox correctly trigger this event upon the initial connect request/login, but the behavior differs when you log out and back in again.

Firefox will fire an event for logout (with [ undefined ]), and will fire another event for the login. Chrome doesn't fire the event for the logout or the second login.

Gudahtt added a commit that referenced this issue Sep 12, 2019
The `runtime.Port.postMessage` API will drop keys with a value of
`undefined` on Chrome, but not on Firefox. This was a problem for the
`publicConfig` stream, which passed the key `selectedAddress` with the
value of `undefined` to communicate to dapps that the user had logged
out.

Instead a `null` is now passed for `selectedAddress` upon logout, which
is correctly sent by the `runtime.Port.postMessage` API on both Chrome
and Firefox.

closes #7101
closes #7109
Gudahtt added a commit that referenced this issue Sep 13, 2019
* Replace `undefined` selectedAddress with `null`

The `runtime.Port.postMessage` API will drop keys with a value of
`undefined` on Chrome, but not on Firefox. This was a problem for the
`publicConfig` stream, which passed the key `selectedAddress` with the
value of `undefined` to communicate to dapps that the user had logged
out.

Instead a `null` is now passed for `selectedAddress` upon logout, which
is correctly sent by the `runtime.Port.postMessage` API on both Chrome
and Firefox.

closes #7101
closes #7109

* Update `metamask-inpage-provider` to v3.0.0

The v3.0.0 update includes a change to the `accountsChanged` event. The
event will now emit an empty array instead of an array with `undefined`
or `null`.

The previous behavior was to emit `[undefined]`. The previous commit
would have changed that to `[null]` anyway, so we figured if we're
going to make a public-facing change to the event anyway we should
change it to be correct. `[undefined]` was never intended, and it
technically violates EIP-1193, which states that the `accountsChanged`
event should emit an array of strings.
Gudahtt added a commit that referenced this issue Sep 13, 2019
* Replace `undefined` selectedAddress with `null`

The `runtime.Port.postMessage` API will drop keys with a value of
`undefined` on Chrome, but not on Firefox. This was a problem for the
`publicConfig` stream, which passed the key `selectedAddress` with the
value of `undefined` to communicate to dapps that the user had logged
out.

Instead a `null` is now passed for `selectedAddress` upon logout, which
is correctly sent by the `runtime.Port.postMessage` API on both Chrome
and Firefox.

closes #7101
closes #7109

* Update `metamask-inpage-provider` to v3.0.0

The v3.0.0 update includes a change to the `accountsChanged` event. The
event will now emit an empty array instead of an array with `undefined`
or `null`.

The previous behavior was to emit `[undefined]`. The previous commit
would have changed that to `[null]` anyway, so we figured if we're
going to make a public-facing change to the event anyway we should
change it to be correct. `[undefined]` was never intended, and it
technically violates EIP-1193, which states that the `accountsChanged`
event should emit an array of strings.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants