-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Workaround to make Metamask inject window.ethereum with strict CSP
- Loading branch information
1 parent
fa121e4
commit fd2b850
Showing
6 changed files
with
250 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import * as env from 'detect-browser'; | ||
import { WindowPostMessageStream } from '@metamask/post-message-stream'; | ||
import { initializeProvider } from '@metamask/providers'; | ||
|
||
export function checkInjectedProvider() { | ||
const injectedAvailable = !!window.ethereum; | ||
|
||
if (!injectedAvailable) { | ||
const browser = env.detect(); | ||
if (browser && browser.name === 'firefox') { | ||
// Due to https://github.com/MetaMask/metamask-extension/issues/3133 | ||
// setup background connection | ||
const metamaskStream = new WindowPostMessageStream({ | ||
name: 'metamask-inpage', | ||
target: 'metamask-contentscript' | ||
}); | ||
|
||
// this will initialize the provider and set it as window.ethereum | ||
initializeProvider({ | ||
connectionStream: metamaskStream, | ||
shouldShimWeb3: true | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.