Skip to content

Commit 51e207f

Browse files
committed
catch error when ethereum provider is set before our attempt to set
1 parent f0ca94b commit 51e207f

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/initializeInpageProvider.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,15 @@ export function initializeProvider({
9898
export function setGlobalProvider(
9999
providerInstance: MetaMaskInpageProvider,
100100
): void {
101-
(window as Record<string, any>).ethereum = providerInstance;
102-
window.dispatchEvent(new Event('ethereum#initialized'));
101+
try {
102+
(window as Record<string, any>).ethereum = providerInstance;
103+
window.dispatchEvent(new Event('ethereum#initialized'));
104+
} catch (error) {
105+
console.error(
106+
'MetaMask encountered an error setting the global Ethereum provider - this is likely due to another Ethereum wallet extension also setting the global Ethereum provider:',
107+
error,
108+
);
109+
}
103110
}
104111

105112
/**

0 commit comments

Comments
 (0)