when I try to access my API uploaded on vercel server, I'm getting this error.
Did anyone have the same error?
When I run it locally, it works fine.
2021-02-15T19:38:59.218Z 0109b575-a2e7-478e-aefe-aa3335b5b6b8 ERROR Error: Failed to launch the browser process! /tmp/chromium: error while loading shared libraries: libnss3.so: cannot open shared object file: No such file or directory TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md at onClose (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:193:20) at Interface. (/var/task/node_modules/puppeteer-core/lib/cjs/puppeteer/node/BrowserRunner.js:183:68) at Interface.emit (events.js:327:22) at Interface.close (readline.js:424:8) at Socket.onend (readline.js:202:10) at Socket.emit (events.js:327:22) at endReadableNT (internal/streams/readable.js:1327:12) at processTicksAndRejections (internal/process/task_queues.js:80:21)
code
import puppeteer, { Page } from 'puppeteer-core'
import chrome from 'chrome-aws-lambda'
export async function getOptions() {
const isDev = !process.env.AWS_REGION
let options;
const chromeExecPaths = {
win32: 'C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe',
linux: '/usr/bin/google-chrome',
darwin: '/Applications/Google Chrome.app/Contents/MacOS/Google Chrome'
}
const exePath = chromeExecPaths[process.platform]
if (isDev) {
options = {
args: [],
executablePath: exePath,
headless: true
}
} else {
options = {
args: chrome.args,
executablePath: await chrome.executablePath,
headless: chrome.headless
}
}
return options
}
let _page: Page | null
async function getPage(): Promise<Page> {
if (_page) {
return _page
}
const options = await getOptions()
const browser = await puppeteer.launch(options)
_page = await browser.newPage()
return _page
}
export async function getScreenshot(html: string, { width, height } = { width: 800, height: 800 }) {
const page = await getPage();
await page.setContent(html);
await page.setViewport({ width, height });
const file = await page.screenshot({ type: 'png' });
return file;
}