question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

UnhandledPromiseRejectionWarning: Error: Request is already handled!

See original GitHub issue

I trying use puppeteer to crawler but I have a problem when I call request to “Kick out login!”. someone can help me! thanks

`const puppeteer = require(“puppeteer”); ( async () => { const browser = await puppeteer.launch() const page = await browser.newPage() await page.setRequestInterception(true) await page.setUserAgent(process.env.USER_AGENT)

page.on('request', interceptedRequest => {
    interceptedRequest.continue({
    method: 'POST',
    postData: 'account=' + process.env.EMAIL + '&password=' + process.env.PASSWORD,
    headers: {
        ...interceptedRequest.headers(),
        'Content-Type': 'application/x-www-form-urlencoded',
        'Cookie': process.env.COOKIE_FAKE
        }
    })
})
const response = await page.goto(process.env.LOGIN_URL)
const body = await response.json()
const token = body.result.token
// return
if (body.result.statusCode !== 200) {
    return
} else if (body.result.type === 'login') {
    console.log('Login success!')
    // do something
}
else if (body.result.type === 'overLogin') {
    console.log('Kick out login!')
    page.on('request', interceptedRequest => {
        interceptedRequest.continue({
        method: 'POST',
        postData: 'account=' + process.env.EMAIL + '&token=' + token,
        headers: {
            ...interceptedRequest.headers(),
            'Cookie': process.env.COOKIE_FAKE
            }
        })
    })

    const response = await page.goto(process.env.LOGOUT_URL)
    let body = await response.json()

    if (body.result.statusCode !== 200) {
        return
    } else if (body.result.type === 'login') {
        console.log('Login success!')
        // do something
    } else {
        return
    }
}

})()`

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:32 (1 by maintainers)

github_iconTop GitHub Comments

9reactions
mesoarcommented, Feb 7, 2020

Same here, still waiting for a fix…

8reactions
weibingzhucommented, Apr 29, 2020

Same

Read more comments on GitHub >

github_iconTop Results From Across the Web

UnhandledPromiseRejectionWar...
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not...
Read more >
[help] Puppeteer “Request already handled” : r/node - Reddit
It works fine for the first try, then, in the second request, app crashes and gives me a “Request already handled” error.
Read more >
Request Interception - Puppeteer
By default Puppeteer will raise a Request is already handled! exception if request.abort , request.continue , or request.respond are called after any of ......
Read more >
Handling those unhandled promise rejections with JS async ...
In the first case, the key is this part of the error message: … by rejecting a promise which was not handled with...
Read more >
Node.js v19.3.0 Documentation
Making handle lifespan shorter than that of the native method ... request.cork(); request.end([data[, encoding]][, callback]); request.destroy([error]).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found