"errorType": "Error", "errorMessage": "Protocol error (Target.createTarget): Target closed.",
const chromium = require('chrome-aws-lambda'); const { addExtra } = require("puppeteer-extra"); const puppeteerExtra = addExtra(chromium.puppeteer); const proxyChain = require('proxy-chain'); const StealthPlugin = require("puppeteer-extra-plugin-stealth"); puppeteerExtra.use(StealthPlugin()); exports.handler = async (event, context, callback) => { let finalResult = []; const url = ``; let browser; const oldProxyUrl = ''; // --> bright data proxy const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl); console.log("newProxyUrl", newProxyUrl) try { browser = await puppeteerExtra.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox', `--proxy-server=${newProxyUrl}`], defaultViewport: chromium.defaultViewport, executablePath: await chromium.executablePath, headless: chromium.headless }); const page = await browser.newPage(); await page.goto(url); finalResult = await extractElements(page); } catch (error) { return callback(error); } finally { await browser.close(); } return callback(null, finalResult); };
const puppeteer = require('puppeteer'); const proxyChain = require('proxy-chain'); (async () => { const oldProxyUrl = 'http://auto:apify_proxy_XXXXXXX@proxy.apify.com:8000'; const newProxyUrl = await proxyChain.anonymizeProxy(oldProxyUrl); console.log(newProxyUrl); const browser = await puppeteer.launch({ args: [`--proxy-server=${newProxyUrl}`], }); // Do your magic here... const page = await browser.newPage(); await page.goto('https://www.example.com'); })();
Error: net::ERR_TUNNEL_CONNECTION_FAILED at https://www.google.com/
Reclaiming failed request back to the list or queue. Protocol error (Target.setAutoAttach): Target closed.
exports.handler = async (event, context, callback) => { const finalResult = []; const url = ``; try { const crawler = new PuppeteerCrawler({ launchContext: { useIncognitoPages: true, launchOptions: { executablePath: await chromium.executablePath(), args: ['--no-sandbox', '--disable-setuid-sandbox'] }, launcher: puppeteer }, useSessionPool: true, requestHandlerTimeoutSecs: 60, browserPoolOptions: { useFingerprints: true, fingerprintOptions: { fingerprintGeneratorOptions: { browsers: ['chrome'], operatingSystems: ['windows'], devices: ['desktop'], locales: ['en-US', 'en'] }, }, }, headless: true, async requestHandler({ request, page, enqueueLinks }) { log.info(`Processing ${request.url}...`); }, // This function is called if the page processing failed more than maxRequestRetries+1 times. failedRequestHandler({ request }) { log.error(`Request ${request.url} failed too many times.`); }, }); // Run the crawler and wait for it to finish. await crawler.run([url]); log.info('Crawler finished.'); } catch (error) { return callback(error); } finally { } return callback(null, finalResult); };