Last active
February 28, 2022 03:57
-
-
Save joseabraham/17a2a2d5676ce6b9edce87320db6bab9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* Launch Puppeteer chromium instance with MetaMask plugin installed | |
* */ | |
export async function launch(puppeteerLib: typeof puppeteer, options: LaunchOptions): Promise<puppeteer.Browser> { | |
if (!options || !options.metamaskVersion) | |
throw new Error( | |
`Pleas provide "metamaskVersion" (use recommended "${RECOMMENDED_METAMASK_VERSION}" or "latest" to always get latest release of MetaMask)`, | |
); | |
const { args, metamaskVersion, metamaskLocation, ...rest } = options; | |
/* eslint-disable no-console */ | |
console.log(); // new line | |
if (metamaskVersion === 'latest') | |
console.warn( | |
'\x1b[33m%s\x1b[0m', | |
`It is not recommended to run metamask with "latest" version. Use it at your own risk or set to the recommended version "${RECOMMENDED_METAMASK_VERSION}".`, | |
); | |
else if (isNewerVersion(RECOMMENDED_METAMASK_VERSION, metamaskVersion)) | |
console.warn( | |
'\x1b[33m%s\x1b[0m', | |
`Seems you are running newer version of MetaMask that recommended by dappeteer team. | |
Use it at your own risk or set to the recommended version "${RECOMMENDED_METAMASK_VERSION}".`, | |
); | |
else if (isNewerVersion(metamaskVersion, RECOMMENDED_METAMASK_VERSION)) | |
console.warn( | |
'\x1b[33m%s\x1b[0m', | |
`Seems you are running older version of MetaMask that recommended by dappeteer team. | |
Use it at your own risk or set the recommended version "${RECOMMENDED_METAMASK_VERSION}".`, | |
); | |
else console.log(`Running tests on MetaMask version ${metamaskVersion}`); | |
console.log(); // new line | |
/* eslint-enable no-console */ | |
// eslint-disable-next-line @typescript-eslint/naming-convention | |
/* METAMASK CONTANIER MOUNTED DIRECTORY WHERE WE DOWNLOADED THE EXTENSION */ | |
const METAMASK_PATH = '/home/browserless/metamask/v10_1_1'; | |
console.log('METAMASK_PATH', METAMASK_PATH) | |
return puppeteerLib.connect({ | |
browserWSEndpoint: `ws://${BROWSERLESS_PATH}&--disable-extensions-except=${METAMASK_PATH}&--load-extension=${METAMASK_PATH}&headless=false` | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment