Tuesday 25 February 2020

Trying Lambda Functions with Puppeteer and getting Browser error

Hey, I wasn’t sure if this is related to Netlify or Puppeteer, but does someone know what’s causing the following error: Browser is not downloaded. Run "npm install" or "yarn install".It’s from a catch block in the the following codeconst chromium = require('chrome-aws-lambda'); const puppeteer = require('puppeteer-core'); exports.handler = async function (event, context, callback) { const molUrl = 'https://paikat.te-palvelut.fi/tpt/?searchPhrase=web%20developer&locations=Oulu&announced=0&leasing=0&english=false&sort=1'; let browser = null; let urls = null; try { // setup browser = await chromium.puppeteer.launch({ executablePath: await chromium.executablePath, args: chromium.args, headless: chromium.headless, //ignoreDefaultArgs: ['--disable-extensions'], defaultViewport: chromium.defaultViewport, }); // Do stuff with headless chrome const page = await browser.newPage(); await page.goto(molUrl); await page.waitForSelector('.resultsList a'); urls = await page.evaluate(() => { let results = []; let items = document.querySelectorAll('.resultsList a'); items.forEach((item) => { const itemShortUrlArray = /^.+[\?]/.exec(item.getAttribute('href')); const itemShortUrl = itemShortUrlArray[0].slice(0, -1); results.push({ url: itemShortUrl, text: item.innerText, }); }); return results; }); console.log('urls', {urls}); } catch (err) { console.error('Catch error:', err.message); } finally { if (browser !== null) { await browser.close() } } return { statusCode: 200, body: JSON.stringify({ urls: urls }) }; } Here’s the full local server log$ npm run lambda-serve > mol-job-search-automation@1.0.0 lambda-serve C:\xampp\htdocs\mol-job-search-automation > netlify-lambda serve functions netlify-lambda: Starting server Hash: e27c2e9de00b1c3503e6 Version: webpack 4.41.6 Time: 2550ms Built at: 2020-02-24 23:56:25 Asset Size Chunks Chunk Names scrapeMol.js 679 KiB 0 [emitted] scrapeMol Entrypoint scrapeMol = scrapeMol.js [0] external "fs" 42 bytes {0} [built] [1] external "path" 42 bytes {0} [built] [4] ../node_modules/puppeteer/lib/helper.js 8.62 KiB {0} [built] [5] ../node_modules/puppeteer-core/lib/helper.js 8.62 KiB {0} [built] [7] external "url" 42 bytes {0} [built] [13] external "https" 42 bytes {0} [built] [109] ../node_modules/puppeteer-core/index.js 1.5 KiB {0} [built] [111] ../node_modules/puppeteer-core/lib/Puppeteer.js 2.7 KiB {0} [built] [112] ./scrapeMol.js 1.57 KiB {0} [built] [113] ../node_modules/chrome-aws-lambda/source/index.js 5.91 KiB {0} [built] [114] ../node_modules/lambdafs/build/index.js 3.72 KiB {0} [built] [136] ../node_modules/chrome-aws-lambda/source/puppeteer/lib sync ^\.\/.*$ 226 bytes {0} [built] [155] ../node_modules/puppeteer/index.js 1.5 KiB {0} [optional] [built] [191] ../node_modules/puppeteer-core/lib/api.js 1.75 KiB {0} [built] [197] ../node_modules/puppeteer-core/package.json 3.34 KiB {0} [built] + 183 hidden modules WARNING in ../node_modules/lambdafs/build/index.js 23:31-46 Critical dependency: the request of a dependency is an expression @ ../node_modules/chrome-aws-lambda/source/index.js @ ./scrapeMol.js WARNING in ../node_modules/ws/lib/buffer-util.js Module not found: Error: Can't resolve 'bufferutil' in 'C:\xampp\htdocs\mol-job-search-automation\node_modules\ws\lib' @ ../node_modules/ws/lib/buffer-util.js @ ../node_modules/ws/lib/receiver.js @ ../node_modules/ws/index.js @ ../node_modules/puppeteer-core/lib/WebSocketTransport.js @ ../node_modules/puppeteer-core/lib/Launcher.js @ ../node_modules/puppeteer-core/lib/Puppeteer.js @ ../node_modules/puppeteer-core/index.js @ ./scrapeMol.js WARNING in ../node_modules/ws/lib/validation.js Module not found: Error: Can't resolve 'utf-8-validate' in 'C:\xampp\htdocs\mol-job-search-automation\node_modules\ws\lib' @ ../node_modules/ws/lib/validation.js @ ../node_modules/ws/lib/receiver.js @ ../node_modules/ws/index.js @ ../node_modules/puppeteer-core/lib/WebSocketTransport.js @ ../node_modules/puppeteer-core/lib/Launcher.js @ ../node_modules/puppeteer-core/lib/Puppeteer.js @ ../node_modules/puppeteer-core/index.js @ ./scrapeMol.js Lambda server is listening on 9000 Request from ::1: GET /scrapeMol.js Catch error: Browser is not downloaded. Run "npm install" or "yarn install" Response with status 200 in 246 ms. I’m not sure if the warning about the Critical dependency is anything to do with this. I’ve googled it and haven’t been able to figure out a fix for that either. Other things to note, I’m working locally (with netlify-lambda serve functions) on Windows.If anyone has any advice, I would really appreciate it.Thanks.

Submitted February 26, 2020 at 06:46AM by hey__its__me__

No comments:

Post a Comment