You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Script should have executed successfully like it did locally
Current Behavior
An error occurred: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string or an instance of Buffer or URL. Received undefined
at Object.readFile (node:fs:385:10)
at /opt/xssscanner/xssheresingle.js:9:12
at new Promise (<anonymous>)
at readFileAsync (/opt/xssscanner/xssheresingle.js:8:12)
at /opt/xssscanner/xssheresingle.js:250:28
at Object.<anonymous> (/opt/xssscanner/xssheresingle.js:300:3)
at Module._compile (node:internal/modules/cjs/loader:1469:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1548:10)
at Module.load (node:internal/modules/cjs/loader:1288:32)
at Module._load (node:internal/modules/cjs/loader:1104:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
Nodejs Script
const puppeteer = require('puppeteer-extra');
const chromium = require('@sparticuz/chromium');
// Stealth plugin configurations
require('puppeteer-extra-plugin-user-data-dir');
require('puppeteer-extra-plugin-user-preferences');
require('puppeteer-extra-plugin-stealth/evasions/chrome.app');
require('puppeteer-extra-plugin-stealth/evasions/chrome.csi');
require('puppeteer-extra-plugin-stealth/evasions/chrome.loadTimes');
require('puppeteer-extra-plugin-stealth/evasions/chrome.runtime');
require('puppeteer-extra-plugin-stealth/evasions/defaultArgs'); // Ensures all default args are included
require('puppeteer-extra-plugin-stealth/evasions/iframe.contentWindow');
require('puppeteer-extra-plugin-stealth/evasions/media.codecs');
require('puppeteer-extra-plugin-stealth/evasions/navigator.hardwareConcurrency');
require('puppeteer-extra-plugin-stealth/evasions/navigator.languages');
require('puppeteer-extra-plugin-stealth/evasions/navigator.permissions');
require('puppeteer-extra-plugin-stealth/evasions/navigator.plugins');
require('puppeteer-extra-plugin-stealth/evasions/navigator.vendor');
require('puppeteer-extra-plugin-stealth/evasions/navigator.webdriver');
require('puppeteer-extra-plugin-stealth/evasions/sourceurl');
require('puppeteer-extra-plugin-stealth/evasions/user-agent-override');
require('puppeteer-extra-plugin-stealth/evasions/webgl.vendor');
require('puppeteer-extra-plugin-stealth/evasions/window.outerdimensions');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());
(async () => {
try {
const executablePath = await chromium.executablePath("/opt/custom/node_modules/@sparticuz/chromium/bin/chromium");
console.log(`Using Chromium executable at: ${executablePath}`);
const browser = await puppeteer.launch({
defaultViewport: chromium.defaultViewport,
executablePath: executablePath,
headless: chromium.headless,
ignoreHTTPSErrors: true,
args: [
...chromium.args, // Spread the chromium.args array
'--no-sandbox',
'--disable-features=IsolateOrigins,site-per-process,SitePerProcess',
'--disable-notifications',
'--ignore-certificate-errors',
],
timeout: 60000
});
const page = await browser.newPage();
// Optional: Set request interception if needed
await page.setRequestInterception(true);
// Set extra HTTP headers if required
await page.setExtraHTTPHeaders({ 'Referer': 'https://google.com/' });
// Handle requests (modify or log as needed)
page.on('request', (interceptedRequest) => {
// Continue all requests without modification
interceptedRequest.continue();
});
// Navigate to the target URL
await page.goto('https://getip.pro', { waitUntil: 'domcontentloaded' });
// Retrieve and log the page title
const title = await page.title();
console.log('Page Title:', title);
await browser.close();
} catch (error) {
console.error('An error occurred:', error);
}
})();
Lambda Runtime Dockerfile:
# Define custom function directory
ARG FUNCTION_DIR="/function"
FROM python:3.11-buster as build-image
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Install aws-lambda-cpp build dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
git \
libcurl4-openssl-dev \
glibc-source
# Copy function code
RUN mkdir -p ${FUNCTION_DIR}
# Update pip
RUN pip install -U pip wheel six setuptools
# Install the function's dependencies
RUN pip install \
--target ${FUNCTION_DIR} \
awslambdaric \
boto3 \
botocore \
redis \
httplib2 \
requests \
numpy \
scipy \
pandas \
pika \
kafka-python \
cloudpickle \
ps-mem \
tblib \
delegator.py \
invoke
FROM python:3.11-buster
# Include global arg in this stage of the build
ARG FUNCTION_DIR
# Set working directory to function root directory
WORKDIR ${FUNCTION_DIR}
# Copy in the built dependencies
COPY --from=build-image ${FUNCTION_DIR} ${FUNCTION_DIR}
# Add Lithops
COPY lithops_lambda.zip ${FUNCTION_DIR}
RUN unzip lithops_lambda.zip \
&& rm lithops_lambda.zip \
&& mkdir handler \
&& touch handler/__init__.py \
&& mv entry_point.py handler/
# Install system dependencies
RUN apt-get update && \
apt-get install -y \
g++ \
make \
cmake \
unzip \
git \
libcurl4-openssl-dev \
glibc-source \
brotli \
tar \
gzip \
build-essential \
libgbm1 \
libasound2 \
libatk1.0-0 \
libc6 \
libcairo2 \
libcups2 \
libdbus-1-3 \
libexpat1 \
libfontconfig1 \
libgcc1 \
libgconf-2-4 \
libgdk-pixbuf2.0-0 \
libglib2.0-0 \
libgtk-3-0 \
libnspr4 \
libpango-1.0-0 \
libpangocairo-1.0-0 \
libstdc++6 \
libx11-6 \
libx11-xcb1 \
libxcb1 \
libxcomposite1 \
libxcursor1 \
libxdamage1 \
libxext6 \
libxfixes3 \
libxi6 \
libxrandr2 \
libxrender1 \
libxss1 \
libxtst6 \
ca-certificates \
fonts-liberation \
libappindicator1 \
libnss3 \
lsb-release \
wget \
curl \
chromium \
chromium-common \
brotli
# Install Brotli for decompression
RUN apt-get update && apt-get install -y brotli
# Install Node.js 21.x
RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \
apt-get install -y nodejs
# Create directory for the Nodejs
RUN mkdir -p /opt/custom
# Copy Nodejs custom script
COPY custom.js /opt/custom/
WORKDIR /opt/custom
# Set up Chrome and Puppeteer directories
RUN mkdir -p /tmp/.cache/puppeteer && \
chmod -R 777 /tmp/.cache
# Install Node.js dependencies with Puppeteer
RUN npm init -y
# First attempt at installing dependencies
RUN PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true npm install \
[email protected] \
[email protected] \
puppeteer-extra \
puppeteer-extra-plugin-stealth \
@sparticuz/[email protected] \
node-fetch \
fs \
url \
async \
utf8 \
path \
minimist --save --legacy-peer-deps
RUN chmod -R 777 "/opt/custom"
RUN chmod -R 777 "/opt/custom/node_modules"
# Create necessary directories with correct permissions
ENV HOME="/tmp"
RUN mkdir -p "/tmp/.config" "/tmp/.cache" "/tmp/.local" && \
chmod -R 777 "/tmp"
# Decompress Chromium binaries
RUN cd /opt/custom/node_modules/@sparticuz/chromium/bin && \
for file in *.br; do \
if [ -f "$file" ]; then \
brotli -d "$file" && \
if [[ $file == *.tar.br ]]; then \
tar xf "${file%%.br}"; \
rm "${file%%.br}"; \
fi; \
fi; \
done
RUN chmod -R 777 "/opt"
RUN chmod -R 777 "/opt/custom"
RUN chmod -R 777 "/opt/custom/node_modules"
# Make the Chromium binary executable
RUN chmod -R 777 /opt/custom/node_modules/@sparticuz/chromium/bin
RUN chmod 777 /opt/custom/node_modules/@sparticuz/chromium/bin/chromium
# Set required environment variables
ENV PUPPETEER_EXECUTABLE_PATH=/opt/custom/node_modules/@sparticuz/chromium/bin/chromium
ENV CHROME_PATH=/opt/custom/node_modules/@sparticuz/chromium/bin/chromium
ENV NODE_PATH=/opt/custom/node_modules
ENV PUPPETEER_CACHE_DIR=/tmp/.cache/puppeteer
# Switch back to function directory
WORKDIR ${FUNCTION_DIR}
ENTRYPOINT [ "/usr/local/bin/python", "-m", "awslambdaric" ]
CMD [ "handler.entry_point.lambda_handler" ]
@Sparticuz I am using lithops to deploy the docker image and to run commands on aws lambda. Idk if this issue is related to puppeteer-extra or @sparticuz/chromium but I have tried everything to run this simple script on aws lambda and every try have failed. If anyone knows a solution please help.
The text was updated successfully, but these errors were encountered:
Environment
chromium
Version:@sparticuz/[email protected]
puppeteer
/puppeteer-core
Version:[email protected]
Expected Behavior
Script should have executed successfully like it did locally
Current Behavior
Nodejs Script
Lambda Runtime Dockerfile:
@Sparticuz I am using lithops to deploy the docker image and to run commands on aws lambda. Idk if this issue is related to
puppeteer-extra
or@sparticuz/chromium
but I have tried everything to run this simple script on aws lambda and every try have failed. If anyone knows a solution please help.The text was updated successfully, but these errors were encountered: