-
Notifications
You must be signed in to change notification settings - Fork 154
metamask gets stuck on the "Let's get started" screen #344
Comments
try this const browser = await dappeteer.launch({
metaMaskVersion: "latest",
automation: "puppeteer",
headless: false,
});
const sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
await sleep(2000);
const pages = await browser.pages();
for (const page of pages) {
if (page.url().startsWith("chrome-extension")) {
await page.reload();
}
}
const metaMask = await dappeteer.setupMetaMask(browser, {
seed: "test test test test test test test test", // 24 words
password: "xxxx",
showTestNets: true,
automation: "puppeteer",
}); |
The issue you're encountering where MetaMask gets stuck on the "Let's get started" screen might be due to the browser not having enough time to fully load the MetaMask extension. you can try to add a delay after launching the browser and before setting up MetaMask. This can be achieved by creating a sleep function and waiting for a certain amount of time (e.g., 2000 milliseconds). Try run this updated code in the file below: |
This works (almost) but there's another error which says Adding an |
Hi, with reference to the above answers and the testcase here, I got it to work export const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
// Ensure ganache is running first (can skip this if you're not using localhost testnet)
const addNetwork = async () => {
const addNetworkRequest = window.ethereum.request({
method: "wallet_addEthereumChain",
params: [
{
chainId: "0x539",
chainName: "Localhost 8545",
nativeCurrency: {
name: "ETH",
symbol: "ETH",
decimals: 18,
},
rpcUrls: ["http://localhost:8545"],
},
],
});
return new Promise((resolve) => {
addNetworkRequest
.then(() => {
resolve(true);
})
.catch(() => {
resolve(false);
});
});
};
// get browser
const browser = await dappeteer.launch({
metaMaskVersion: "v10.31.0",
automation: "puppeteer",
headless: false,
});
await sleep(2000);
const pages = await browser.pages();
for (const page of pages) {
if (page.url().startsWith("chrome-extension")) {
await page.reload();
}
}
// get metamask
const metamask = await dappeteer.setupMetaMask(browser, {
seed: "<your seed>",
showTestNets: true,
});
// code to switch network to local, or you can just skip this and use `metamask.switchNetwork("<testnet name>")`
const dappPage = await browser.newPage();
// can goto any valid website
await dappPage.goto("https://chainsafe.io", { waitUntil: "networkidle" });
const addNetworkPromise = dappPage.evaluate(addNetwork);
try {
// this part hangs my browser, its a temp workaround to absorb the error and move on
await metamask.acceptAddNetwork(true);
} catch (e) {
// ignore error to prevent hanging
for (const page of pages) {
if (page.url().startsWith("chrome-extension")) {
await page.reload();
}
}
}
const res = await addNetworkPromise;
// (end of) code to switch network to local, or you can just skip this and use metamask.switchNetwork("<testnet name>") Hope this helps! |
import dappeteer from '@chainsafe/dappeteer';
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
async function main() {
const browser = await dappeteer.launch({
metaMaskVersion: "v10.31.0",
automation: "puppeteer",
headless: false,
});
await sleep(5000);
const pages = await browser.pages();
for (const page of pages) {
if (page.url().startsWith("chrome-extension")) {
await page.reload();
}
}
const metaMask = await dappeteer.setupMetaMask(browser, {
seed: 'test test test test test test test test test test test test test test test test test test test test test test test test ', // 24 words
password: 'my_password',
showTestNets: true,
});
// create a new page and visit your dapp
const dappPage = await browser.newPage();
await dappPage.goto("https://my-dapp.com");
// you can change the network if you want
await metaMask.switchNetwork('goerli');
}
main(); Damn I tried all the solutions but still couldn't connect.
|
Maybe you could try a valid website like |
I just started the dappeteer topic and wanted to test the codes on the home page as an example. I do not receive any errors when I run the codes, but after opening the Metamask page, the page hangs and closes without logging in.
My Code:
SS:
The text was updated successfully, but these errors were encountered: