toncenter / ton-wallet

Web Wallet and Browser Extension for TON (The Open Network)
https://wallet.ton.org
GNU General Public License v3.0
192 stars 70 forks source link

Extension have conflicts with other extensions #127

Open dariotarantini opened 2 years ago

dariotarantini commented 2 years ago

I'm prototyping a simple dapp but i can't get it to work well. I don't understand why, but sometimes the extension returns errors when I try to request accounts. When the page loads, it returns this to me:

Uncaught TypeError: window.ton._destroy is not a function
    at new TonProvider (provider.js:17:40)

also, when i call provider.send('ton_requestAccounts') it returns

Uncaught TypeError: provider.send is not a function
    at <anonymous>:1:10
dariotarantini commented 2 years ago

Is this a typo? https://github.com/toncenter/ton-wallet/blob/master/src/js/extension/provider.js#L268

dariotarantini commented 2 years ago

Here is an example which fail https://gist.github.com/dariotarantini/927ba5ea9556271928fda6274e9fea20 (tonwebjs taken from here https://raw.githubusercontent.com/toncenter/tonweb/master/dist/tonweb.js)

dariotarantini commented 2 years ago

Looks like there was some conficts with another wallet i had, so after removing it everything seems to work.

slavafomin commented 2 years ago

Looks like there was some conficts with another wallet i had, so after removing it everything seems to work.

Could you please give a link to the conflicting extension and state it's version? Also, please update the issue's title to better reflect the problem.

dariotarantini commented 2 years ago

I think the problem was this extension: https://chrome.google.com/webstore/detail/ever-wallet/cgeeodpfagjceefieflmdfphplkenlfk

slavafomin commented 2 years ago

The problem is in this line: https://github.com/broxus/ever-wallet-browser-extension/blob/d1474f63a236f347bb1fde200773c9b50b302dfb/src/app/provider/index.ts#L41

slavafomin commented 2 years ago

This should fix it:

const tonNamespaceObject = { /** define ton object here */ };

const reportConflict = () => console.warn(
  `TON extension conflict detected. ` +
  `Make sure that you are running only one TON extension.`
);

if ('ton' in window) {
  reportConflict();
  delete window.ton;
}

Object.defineProperty(window, 'ton', {
  get: () => tonNamespaceObject,
  set: reportConflict,
});

The browser support is quite good: 94.42%.

WinGood commented 8 months ago

The issue is quite easy to reproduce if you install Chrome extension of MyTonWallet, using Ton Wallet along with MyTonWallet chrome extension is not possible.