Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

feat: custom automation#332

Merged
BeroBurny merged 3 commits intomasterfrom
beroburny/plugins
May 31, 2023
Merged

feat: custom automation#332
BeroBurny merged 3 commits intomasterfrom
beroburny/plugins

Conversation

@BeroBurny
Copy link
Contributor

@BeroBurny BeroBurny commented May 18, 2023

Due to the request from the community for "plugins", this is one experimentation approach to it. It will not be covered by the test and the wound not provides support, so use it at your own risk.


Usages Example

It is recommended to use typescript.

import dappeteer from '@chainsafe/dappeteer';
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import {DPuppeteerBrowser} from "@chainsafe/dappeteer/dist/puppeteer";

async function main() {
  const { metaMask, browser } = await dappeteer.bootstrap({
    automation: "custom",
    customAutomation: async (metamaskPath, userDataDir, options) => {
      puppeteer.use(StealthPlugin());
      const browser = puppeteer.launch({
        userDataDir,
        args: [
           `--disable-extensions-except=${metamaskPath}`,
           `--load-extension=${metamaskPath}`,
        ],
      });
      return DPuppeteerBrowser(browser, userDataDir, options.metaMaskFlask);
    },
  });

  // create a new page and visit your dapp
  const dappPage = await browser.newPage();
  await dappPage.goto('http://my-dapp.com');

  // you can change the network if you want
  await metaMask.switchNetwork('goerli');

  // do something in your dapp that prompts MetaMask to add a Token
  const addTokenButton = await dappPage.$('#add-token');
  await addTokenButton.click();
  // instruct MetaMask to accept this request
  await metaMask.acceptAddToken();

  // do something that prompts MetaMask to confirm a transaction
  const payButton = await dappPage.$('#pay-with-eth');
  await payButton.click();

  // 🏌
  await metaMask.confirmTransaction();
}
main();

@BeroBurny BeroBurny added this pull request to the merge queue May 31, 2023
Merged via the queue into master with commit e25032f May 31, 2023
@BeroBurny BeroBurny deleted the beroburny/plugins branch May 31, 2023 14:02
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants