Skip to content

Instantly share code, notes, and snippets.

Last active January 10, 2023 13:40
What would you like to do?

I am trying to run puppeteer with proxy chain package on aws lambda but I am getting this error message:

"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");
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();
await proxyChain.closeAnonymizedProxy(newProxyUrl, true);
return callback(null, finalResult);
Copy link

@aditodkar Did you test well at local? If yes, maybe AWS lambda block proxy. let's try to config allow proxy on lambda

Copy link

Sorry did not get you. Are you saying I have to enable proxy settings for lambda function?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment