dappeteer icon indicating copy to clipboard operation
dappeteer copied to clipboard

RPC Error: User rejected the request. Object code: 4001 message: "User rejected the request." [[Prototype]]: Object

Open mzahirr opened this issue 2 years ago • 10 comments

Describe the bug MetaMask - RPC Error: User rejected the request. Object code: 4001 message: "User rejected the request." [[Prototype]]: Object To Reproduce

Steps to reproduce the behavior: const browser = await dappeteer.launch(puppeteer, {headless: false, metamaskVersion: 'v10.8.1', defaultViewport: null, args: ['--start-maximized'] }); const metamask = await dappeteer.setupMetamask(browser,{seed: "bla bla"}); await metamask.addNetwork({networkName: "Avalanche Network",rpc: "https://api.avax.network/ext/bc/C/rpc",chainId: "43114",symbol: "AVAX", explorer : "https://snowtrace.io/"}) await metamask.switchNetwork('Avalanche Network') await metamask.addToken('blabla')

const page = await browser.newPage()
await page.goto('https://website.com')
await sleep(3000)
await page.waitForXPath('//*[@id="root"]/div/div/section/main/div[1]/div[1]/a/div/div');
var originSelector = await page.$x('//*[@id="root"]/div/div/section/main/div[1]/div[1]/a/div/div');
await originSelector[0].click();

await page.waitForXPath('/html/body/div[2]/div/div[2]/div/div[2]/div/div/div[2]/button');
var connectWallet = await page.$x('/html/body/div[2]/div/div[2]/div/div[2]/div/div/div[2]/button');
await connectWallet[0].click();
await sleep(3000)
await metamask.confirmTransaction();
console.log("Connected wallet")

Expected behavior pop up shown and confirm and connect website.

Is there any fixed for this problem ?

mzahirr avatar Mar 20 '22 16:03 mzahirr

https://github.com/MetaMask/metamask-extension/pull/12643

warsmit avatar Mar 25 '22 10:03 warsmit

I am also facing this bug

wtesler avatar Apr 07 '22 21:04 wtesler

I am also facing this bug

wtesler avatar Apr 07 '22 21:04 wtesler

You have to call await metamask.approve(); after clicking the connect wallet button

wtesler avatar Apr 08 '22 01:04 wtesler

hmm .. having the same problem . I tried the approve, but no luck

fransyozef avatar Apr 28 '22 16:04 fransyozef

+1, same problem.

Metamask popup is immediately closed with:

MetaMask - RPC Error: User rejected the request. Object code: 4001 message: "User rejected the request."

ross-weir avatar Apr 30 '22 06:04 ross-weir

Anyone get any resolution with this?

alaaan avatar May 03 '22 04:05 alaaan

Well the only way I solved it was to try catch the timeout

 try {
        await metamask.confirmTransaction();
        await metamask.approve()
    } catch {
        console.error("Metamask selector timeout")
       
    }

Sucks only that its 30 sec and then it continues

mikklaos avatar May 03 '22 19:05 mikklaos

Struggling with the same issue when using Jest + Dappeteer.

What is interesting, when a new test suite is run, the Metamask pop-ups work correctly. They only break right after the extension & account init.

MikeyZat avatar May 10 '22 09:05 MikeyZat

I struggled with this issue too and I found that it happens because there is a browser "targetcreated" event who listen to creation of "/notification.html" , what is the Popup show by MetaMask. still didn't know why this code is use for but you actually able to comment the page.close and then it will no longer close immediately.

async function closeNotificationPage(browser: puppeteer.Browser): Promise<void> {
  browser.on('targetcreated', async target => {
    if (target.url().match('chrome-extension://[a-z]+/notification.html')) {
      try {
        const page = await target.page()
        await page.close()
      } catch {
        return
      }
    }
  })
}

yovelsapir avatar May 29 '22 06:05 yovelsapir

This should be solved by #181

Tbaut avatar Dec 01 '22 18:12 Tbaut