Hi, I’m trying to use Playwright in a Netlify function but I get this error on deploy (works great locally with netlify dev):
browserType.launch: Failed to launch chromium because executable doesn't exist at /home/sbx_user1051/.cache/ms-playwright/chromium-854489/chrome-linux/chrome
Try re-installing playwright with "npm install playwright"Error
at Object.captureStackTrace (/var/task/src/node_modules/playwright/lib/utils/stackTrace.js:48:19)
at Connection.sendMessageToServer (/var/task/src/node_modules/playwright/lib/client/connection.js:69:48)
at Proxy.<anonymous> (/var/task/src/node_modules/playwright/lib/client/channelOwner.js:64:61)
at /var/task/src/node_modules/playwright/lib/client/browserType.js:64:67
at BrowserType._wrapApiCall (/var/task/src/node_modules/playwright/lib/client/channelOwner.js:77:34)
at BrowserType.launch (/var/task/src/node_modules/playwright/lib/client/browserType.js:55:21)
at Runtime.exports.handler (/var/task/src/functions/points-balance-get.js:19:38)
at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)
I’ve try to empty cache, use npm instead of yarn but it does not work.
I tried to use the package playwright-aws-lambda but it weights 44MB and with other modules, it exceeded the 66MB limit.
So, how are you getting the binary in there, if the packages you’ve attempted are too large for lambdas? not being able to run it == it’s not there - so that’s the problem I think you’re trying to solve
I’ve heard from some folks that the only way they could get a browser to fit into a lambda was to use puppeteer/headless chrome rather than a normal browser like chromium, in case that is an avenue you haven’t tried yet.
Sadly, this code sample does not work locally with netlify dev command because the package is specifically designed for deployed lambda functions. And dynamic module imports based on environment is not a thing. This makes debugging very painful.