'How to run latest chromium/puppeteer on firebase

I do have a working application on firebase, that renders code and delivers a png image as output using puppeteer. However I would like to have a newer chromium version running (new features). There are newer puppeteer versions, but no newer version of chrome-aws-lambda then 10.1.0 and that uses chromium 92.0.4512.0.

Is this project dead (last update 9 month ago), or is there a other package that I can use?

For reference, this is the code that runs on firebase.

const functions = require("firebase-functions");
const chromium = require("chrome-aws-lambda");
const puppeteer = chromium.puppeteer;
const admin = require("firebase-admin");
admin.initializeApp();
exports.preview = functions
  .runWith({ memory: "512MB", timeoutSeconds: 10 })
  .https.onRequest(async (req, res) => {
    const browser = await puppeteer.launch({
      args: chromium.args,
      defaultViewport: { width: 400, height: 300 },
      executablePath: await chromium.executablePath,
      headless: true,
    });
    const {
      query: { q = "" },
    } = req;

    const page = await browser.newPage();

    await page.setContent(q);
    const screenshot = await page.screenshot();
    await browser.close();

    res.header({ "Content-Type": "image/png" });
    res.end(screenshot, "binary");
  });


Solution 1:[1]

I have worked around that by using puppeteer directly without -core. So there is no chrome-aws-lambda dependency needed anymore and I can use the latest puppeteer version.

So this is how it works now if anyone else needs that:

const functions = require("firebase-functions");
const puppeteer = require('puppeteer');

// admin seems to be necessary in order
// to run the function via `firebase emulators`
const admin = require("firebase-admin");
admin.initializeApp();

exports.preview = functions
  .runWith({ memory: "512MB", timeoutSeconds: 10 })
  .https.onRequest(async (req, res) => {
    const browser = await puppeteer.launch({
      defaultViewport: { width: 400, height: 300 },
      headless: true
    });

    const {
      query: { q = "" },
    } = req;

    const page = await browser.newPage();

    await page.setContent(q);
    const screenshot = await page.screenshot();
    await browser.close();

    res.header({ "Content-Type": "image/png" });
    res.end(screenshot, "binary");
  });

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Beowolve