ChainSafe / dappeteer

[DEPRECATED]🏌🏼‍E2E testing for dApps using Puppeteer + MetaMask
Other
490 stars 152 forks source link

Connect to existing instance of browser #299

Open Velkonost opened 1 year ago

Velkonost commented 1 year ago

Describe the problem I launch browser's instance from an anty dolphin and I have port, wsEndpoint of it. How can I connect dappeteer to this instance?

System:

Part of code:

const {port, wsEndpoint} = await openBrowser(profileId)
const browser = await puppeteer.connect({
        browserWSEndpoint: `ws://127.0.0.1:${port}${wsEndpoint}`
})

I've tried to setup like this:

const metamask = await dappeteer.setupMetaMask(browser)

but no effect

BeroBurny commented 1 year ago

Hey, thanks for reaching out.

The issue is you are sending a Browser instance not a DappeteerBrowser. To solve your issue you can initialize DPuppeteerBrowser class for example

const browserInstance = new DPuppeteerBrowser(browser, userData, false);
const metamask = await dappeteer.setupMetaMask(browserInstance)
KIttojo commented 1 year ago

Hey, thanks for reaching out.

The issue is you are sending a Browser instance not a DappeteerBrowser. To solve your issue you can initialize DPuppeteerBrowser class for example

const browserInstance = new DPuppeteerBrowser(browser, userData, false);
const metamask = await dappeteer.setupMetaMask(browserInstance)

How can we call new DPuppeteerBrowser()? What should we import to file?

I tried to add export { DPuppeteerBrowser } from "./puppeteer/browser.js" to file @/node_modules/@chainsafe/dappeteer/dist/index.d.ts manually, but it didn't help me

KIttojo commented 1 year ago

I solved it, just need to import const { DPuppeteerBrowser } = require('@chainsafe/dappeteer/dist/puppeteer/browser');

But what does userData prop means? It has a string type, but what should I put here?

openluminus commented 1 year ago

@BeroBurny, same issues on my side, I'm trying to do exactly the same thing as @Velkonost.

I this piece of code, but nothing happens:

const dappeteer = require("@chainsafe/dappeteer");
const {
  DPuppeteerBrowser,
} = require("@chainsafe/dappeteer/dist/puppeteer/browser");

// function 
  const { port, wsEndpoint } = await openBrowser(profileId);

  const browser = await puppeteer.connect({
    browserWSEndpoint: `ws://127.0.0.1:${port}${wsEndpoint}`,
  });

  const browserInstance = new DPuppeteerBrowser(browser, "", false);

  const metamask = await dappeteer.setupMetaMask(browserInstance);
  await metamask.unlock(getMetamaskPassword(profileId));

What I'm trying to achieve might be different from @Velkonost, since I don't want to setup a new metamask, but rather unlock the existing instance.

I ask myself the same questions as @KIttojo: What parameters should we use in this function? new DPuppeteerBrowser(browser, userData, false);