'puppeteer-extra' : ProtocolError: Protocol error (Network.getCookies): Target closed.
NabiKAZ opened this issue · comments
I use puppeteer-extra
.
It don't have problem in normal use.
But when I set proxy: await useProxy(page, 'socks5://127.0.0.1:8080');
Complete code:
import puppeteer from 'puppeteer-extra';
import StealthPlugin from 'puppeteer-extra-plugin-stealth';
import useProxy from 'puppeteer-page-proxy';
puppeteer.use(StealthPlugin());
let options = {
headless: false,
devtools: true,
};
const browser = await puppeteer.launch(options);
const page = await browser.newPage();
await useProxy(page, 'socks5://127.0.0.1:8080');
await page.goto('http://api.ipify.org/');
var result = await page.content();
console.log(result);
await browser.close();
I get this error:
C:\>node test_proxy.mjs
<html><head></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">x.x.x.x</pre></body></html>
C:\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:230
error: new Errors_js_1.ProtocolError(),
^
ProtocolError: Protocol error (Network.getCookies): Target closed.
at C:\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:230:24
at new Promise (<anonymous>)
at CDPSession.send (C:\node_modules\puppeteer\lib\cjs\puppeteer\common\Connection.js:226:16)
at next (C:\node_modules\puppeteer-extra-plugin-stealth\evasions\sourceurl\index.js:32:41)
at CDPSession.send (C:\node_modules\puppeteer-extra-plugin-stealth\evasions\sourceurl\index.js:57:18)
at Object.getCookies (C:\node_modules\puppeteer-page-proxy\src\lib\cdp.js:6:38)
at CookieHandler.getCookies (C:\node_modules\puppeteer-page-proxy\src\lib\cookies.js:84:51)
at requestHandler (C:\node_modules\puppeteer-page-proxy\src\core\proxy.js:15:40)
at $ppp_request_listener (C:\node_modules\puppeteer-page-proxy\src\core\proxy.js:82:15)
at C:\node_modules\puppeteer\lib\cjs\puppeteer\common\Page.js:219:52 {
originalMessage: ''
}
Node.js v17.2.0
Of course, the code works, but at the end of it, an error appears when closing the browser.
There seems to be a problem closing the browser, because when I use it and cause a delay, there is no problem:
setTimeout(async function() {
await browser.close();
}, 1000);
And also, when I use this, no problem:
await useProxy(page, null);
await browser.close();
But I do not know if this is a principle to prevent problems or if the error does not appear due to the delay in executing the command.