dappeteer
dappeteer copied to clipboard
Connect options for a page
I do have one idea, which I am not sure how other people are currently overcoming the issue it stems from. Currently, I am not sure how to prompt metamask to show the connection screen below past the first time I access metamask with my dapp.
In a normal circumstance, there is either a popup in the metamask widget, or if the user has that setting disabled, there is a button that says 'not connected' as seen below.
And you can click that button to then access the connection popup in the widget and connect to a site, but this option isn't available in the page view of metamask, and the popup doesn't appear in the page view either. Considering that the metamask popup widget is closed automatically, I had to find a new way to connect more than one account in a wallet to a site.
I settled upon importing both wallets at the beginning of the settion (using importPk) then writing this function to connect all accounts to the dapp when the connection window appears for the first time.
export async function approve(page: puppeteer.Page, selectAll: boolean = false, version?: string): Promise<void> {
await page.bringToFront();
await page.reload();
try {
if (selectAll) {
const checkbox = await page.waitForSelector(".permissions-connect-choose-account__select-all > input", {
timeout: 3000,
});
if (checkbox) await checkbox.click({ clickCount: 2 });
}
} catch (error) {
console.log("Couldnt select all, maybe there is only one available.");
}
const button = await page.waitForSelector("button.button.btn-primary", { timeout: 3000 });
if (button) await button.click();
const connectButton = await page.waitForSelector("button.button.btn-primary", { timeout: 3000 });
if (connectButton) await connectButton.click();
}
Which really it's just a modification to the approve function from dappeteer, but instead of connecting the first account, there is an optional param that allows you to click the select all button to connect all accounts at once. This would be a useful feature out the box for dappeteer.
EDIT: After giving it some thought I realize that the connection screen on the page view of metamask appears when using wallet connect then selecting metamask with the metamask page already open. In my dapp though, the provider is locally stored and defaults to metamask after the first wallet is connected with metamask, so I would have to write a function to delete local storage whenever I want to connect a new account to get the connection screen to appear again. . . meh
Originally posted by @keithfrazier98 in https://github.com/ChainSafe/dappeteer/issues/98#issuecomment-1058466295
@BeroBurny Go
and disconnect from page. This will trigger this page again