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

Connect to existing instance of browser #299

Open
Velkonost opened this issue Apr 2, 2023 · 4 comments
Open

Connect to existing instance of browser #299

Velkonost opened this issue Apr 2, 2023 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@Velkonost
Copy link

Velkonost commented Apr 2, 2023

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:

  • OS: Linux Kali
  • NodeJs version v18.13.0
  • dappeteer version 5.0.1
  • puppeteer version 19.8.1

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

@Velkonost Velkonost added the help wanted Extra attention is needed label Apr 2, 2023
@BeroBurny
Copy link
Contributor

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
Copy link

KIttojo commented May 19, 2023

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
Copy link

KIttojo commented May 19, 2023

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
Copy link

@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);

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants