UnhandledPromiseRejectionWarning: Error: Request is already handled!
See original GitHub issueI 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:
- Created 4 years ago
- Reactions:14
- Comments:32 (1 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Same here, still waiting for a fix…
Same