This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 154
feat: speedup initializing MetaMask #238
Merged
Merged
Changes from all commits
Commits
Show all changes
51 commits
Select commit
Hold shift + click to select a range
4de874a
chore: update CI for unstable branch
mpetrunic 00f9857
fix!: casing of MetaMask (#132)
Mrtenz d18efa4
fix: update ganache, fix test depending on goerli (#144)
mpetrunic dc9b5fe
fix: selector issues, useless timeouts, reorganise tests (#145)
mpetrunic c90db41
fix: import token flaky (#149)
mpetrunic 0c5dc17
feat!: update recommended metamask version (#151)
mpetrunic 9ab9b4c
chore: change eslint config to chainsafe shared (#152)
mpetrunic 07775a7
feat: add support for installing metamask flask (#153)
mpetrunic 564aa4b
feat: ability to install snap (#154)
mpetrunic d1a3ec4
fix: snap install faster, run all tests (#163)
mpetrunic e7d8435
feat: Add invokeSnap method; update installSnap method parameter; (#159)
Lykhoyda 2661323
feat: add ability to accept dialogs (#138) (#164)
Lykhoyda c25c66f
feat!: add playwright support (#167)
mpetrunic 4804b88
feat: added notification snap to methods-snap #137 (#166)
Lykhoyda 708c87b
Merge remote-tracking branch 'origin/master' into unstable
mpetrunic ba9745f
feat: method to bootstrap snap env (#180)
mpetrunic b01e8d2
chore: node engine requirements (#184)
BeroBurny d9e4a4c
chore: remove metamask dir (#185)
mpetrunic a4c2031
fix: remove page param from install snap (#188)
mpetrunic 4171ea4
feat!: replace outdated methods (#189)
mpetrunic e382c4c
chore: Ci enhancement (#193)
Tbaut d63f9e4
feat: allow signing typed data (#191)
Tbaut d9db933
fix: fix prompt clicking flakiness, fix multiple snap key permissions…
mpetrunic 10c116e
feat: snap notifications 137 (#187)
Lykhoyda ef70dae
chore: Deprecate button clicks for tests (#195)
Tbaut 3ed2f18
chore: Update documentation and Readme (#202)
Tbaut 902b035
chore: Remove local server for dapp (#203)
Tbaut 31ca258
move temporary user data dir in upper scope
BeroBurny ac43675
implement exporting state and running from a state
BeroBurny 08deead
implement userDataDir for puppeteer
BeroBurny d82f84f
implement tests
BeroBurny 05f4ae3
fix setupBootstrappedMetaMask for flask
BeroBurny 7806714
fix flask
BeroBurny c75b302
implement addKeyToMetaMaskManifest
BeroBurny 7f7ea85
Merge branch 'master' into beroburny/speedup-init
BeroBurny 03df940
small fixes
BeroBurny 6a814ab
improve userData testing
BeroBurny 76758d7
fix jest config
BeroBurny baad180
implement default user profile
BeroBurny daa7223
small quality of life improvements
BeroBurny 0a17923
improve documentation
BeroBurny e662a60
Merge branch 'master' into beroburny/speedup-init
BeroBurny 8072c86
fix headless issues whit handling files
BeroBurny 9fba7d2
Merge branch 'master' into beroburny/speedup-init
BeroBurny ce421ef
improve ci
BeroBurny 51e4498
fix yml
BeroBurny 63651eb
fix ci
BeroBurny 0acc1be
improve ci
BeroBurny 61bc018
Merge branch 'master' into beroburny/speedup-init
BeroBurny 87caf77
fix export
BeroBurny 30f7e66
address comments
BeroBurny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,6 @@ dist | |
/.metamask | ||
.idea | ||
*.log | ||
*.png | ||
*.png | ||
|
||
!userData/**/*.log |
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,163 @@ | ||
# dAppeteer Browser | ||
|
||
- [Methods](#methods) | ||
- [isMetaMaskFlask](#isMetaMaskFlask) | ||
- [pages](#pages) | ||
- [newPage](#newPage) | ||
- [getSource](#getSource) | ||
- [close](#close) | ||
- [wsEndpoint](#wsEndpoint) | ||
- [getUserDataDirPath](#getUserDataDirPath) | ||
- [storeUserData](#storeUserData) | ||
- [Advance Usages](#advanced) | ||
- [Storing and lunching browser from specific state](#storeAndRun) | ||
- [Storing state](#storeAndRun-storing) | ||
- [Starting from state](#storeAndRun-start) | ||
|
||
<a name="methods"></a> | ||
# dAppeteer Browser methods | ||
|
||
<a name="isMetaMaskFlask"></a> | ||
## `browser.isMetaMaskFlask(): boolean` | ||
returns if browser runs MetaMask flask version | ||
|
||
<a name="pages"></a> | ||
## `browser.pages(): Promise<DappeteerPage<Page>[]>` | ||
returns list of open DappeteerPages | ||
|
||
<a name="newPage"></a> | ||
## `browser.newPage(): Promise<DappeteerPage<Page>>` | ||
open new blank page in browser and return DappeteerPage of it | ||
|
||
<a name="getSource"></a> | ||
## `browser.getSource(): Browser` | ||
returns underlying browser instance of browser runner | ||
|
||
<a name="close"></a> | ||
## `browser.close(): Promise<void>` | ||
it closes browser and clears temporary data | ||
|
||
<a name="wsEndpoint"></a> | ||
## `browser.wsEndpoint(): string` | ||
returns web socket address | ||
|
||
<a name="getUserDataDirPath"></a> | ||
## `browser.getUserDataDirPath(): string` | ||
return path of temporary dir of browsers user data | ||
|
||
<a name="storeUserData"></a> | ||
## `browser.storeUserData(destination: string): boolean` | ||
copy current user data on desired destination | ||
|
||
<a name="advanced"></a> | ||
# Advanced usages | ||
|
||
<a name="storeAndRun"></a> | ||
## Storing and lunching browser from specific state | ||
In situations when you want to skip setup or have state to fallback. | ||
For an example, you can look at [`test/userData.spec.ts`](../test/userData.spec.ts) | ||
|
||
<a name="storeAndRun-storing"></a> | ||
### Storing state | ||
There is few approach's storing a state. | ||
Best one is with help with using browser method [`browser.storeUserData`](#storeUserData). | ||
|
||
```js | ||
import dappeteer from "@chainsafe/dappeteer"; | ||
|
||
async function store() { | ||
const { metaMask, browser } = await dappeteer.bootstrap(); | ||
|
||
const dappPage = browser.newPage(); | ||
await dappPage.goto("https://chainsafe.io/"); | ||
|
||
// add custom network to a MetaMask | ||
dappPage.evaluate(() => { | ||
window.ethereum.request({ | ||
method: "wallet_addEthereumChain", | ||
params: [ | ||
{ | ||
chainId: "0xa", | ||
chainName: "Optimism", | ||
nativeCurrency: { | ||
name: "ETH", | ||
symbol: "ETH", // 2-6 characters long | ||
decimals: 18, | ||
}, | ||
rpcUrls: ["https://mainnet.optimism.io"], | ||
}, | ||
], | ||
}); | ||
}); | ||
await metaMask.acceptAddNetwork(true); | ||
|
||
// add custom token to a MetaMask | ||
dappPage.evaluate(() => { | ||
window.ethereum.request({ | ||
method: "wallet_watchAsset", | ||
params: { | ||
type: "ERC20", | ||
options: { | ||
address: "0x94b008aA00579c1307B0EF2c499aD98a8ce58e58", | ||
symbol: "USDT", | ||
decimals: 18, | ||
}, | ||
}, | ||
}); | ||
}); | ||
await metaMask.acceptAddToken(); | ||
|
||
// we are almost ready to store state | ||
// but at first we need to give a bit of time to metamask to store state | ||
await dappPage.waitForTimeout(1000); | ||
|
||
// now we can store on desiered location | ||
browser.storeUserData("./location-path"); | ||
|
||
// done! | ||
await browser.close(); | ||
} | ||
|
||
store(); | ||
``` | ||
|
||
<a name="storeAndRun-start"></a> | ||
### Starting from state | ||
For loading state from a stored configuration just need to include option `userDataDir` with path to a previously stored state. | ||
|
||
```js | ||
import dappeteer from "@chainsafe/dappeteer"; | ||
|
||
async function resume() { | ||
const { metaMask, browser } = await dappeteer.bootstrap({ | ||
userDataDir: "./location-path", | ||
}); | ||
|
||
const dappPage = browser.newPage(); | ||
await dappPage.goto("https://chainsafe.io/"); | ||
|
||
// done! | ||
} | ||
|
||
resume(); | ||
``` | ||
|
||
dAppeteer provides state for default `MetaMaskOptions` to get path for it, you need to use constants `DEFAULT_METAMASK_USERDATA` and for a flask | ||
`DEFAULT_FLASK_USERDATA`. | ||
|
||
```js | ||
import dappeteer from "@chainsafe/dappeteer"; | ||
|
||
async function resume() { | ||
const { metaMask, browser } = await dappeteer.bootstrap({ | ||
userDataDir: dappeteer.DEFAULT_METAMASK_USERDATA, | ||
}); | ||
|
||
const dappPage = browser.newPage(); | ||
await dappPage.goto("https://chainsafe.io/"); | ||
|
||
// done! | ||
} | ||
|
||
resume(); | ||
``` |
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 |
---|---|---|
@@ -1 +1,15 @@ | ||
import path from "path"; | ||
import { getDappateerPath } from "./helpers/utils"; | ||
|
||
export const EXAMPLE_WEBSITE = "http://example.org"; | ||
|
||
export const RECOMMENDED_METAMASK_VERSION = "v10.23.0"; | ||
|
||
export const DEFAULT_METAMASK_USERDATA = path.join( | ||
getDappateerPath(), | ||
"userData/chrome-mm" | ||
mpetrunic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); | ||
export const DEFAULT_FLASK_USERDATA = path.join( | ||
getDappateerPath(), | ||
"userData/chrome-flask" | ||
mpetrunic marked this conversation as resolved.
Show resolved
Hide resolved
|
||
); |
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How are we using the boolean returned from the method?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It returns
true
if successfalse
if fails somewhereFor future proofing and for users
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it better to throw the error if the data is not stored? Can we assume the case that we can continue even if the method is failed?