Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

puppeteer.launch in Cloud Functions throwing error

I've been working on a gcloud function with React and Puppeteer. My team and I have come across this problem we can't seem to solve. We've looked almost everywhere.

Cloud function

index.js

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

exports.searchFor = functions.runWith({memory: "1GB"}).https.onCall(async (data, context) => {
    try {
        const browser = await puppeteer.launch({headless: true, args: [
            '--no-sandbox',
            '--disable-setuid-sandbox',
        ]})
    } catch (error) {
        return error
    }

})

Client

import firebase from 'firebase/app'
import "firebase/functions";
import {functions} from "../firebase";
import {parse} from "query-string";
import {RouteComponentProps} from "react-router";
import {searchQuery} from "../functions/tasks"
import {withRouter} from 'react-router-dom';
import React from "react";

// with proper values, of course
const firebaseConfig = {
    apiKey: "",
    authDomain: "",
    databaseURL: "",
    projectId: "",
    storageBucket: "",
    messagingSenderId: "",
    appId: "",
    measurementId: "",
}

const app = firebase.initializeApp(firebaseConfig);

const searchFor = firebase.functions(app).httpsCallable("searchFor")

export const Search = withRouter(props => <Searcher {...props}/>);

class Searcher extends React.Component<React.PropsWithChildren<RouteComponentProps<any>>> {

    private location = this.props.location;

    private searchQuery = parse(this.location.search)

    private testSearch = async (): void => {
        return await searchFor({data: "test"}).then((res) => {
            return res.data
        })
    }

    public componentDidMount = (): void => {
        this.testSearch().then((out) => {
            console.log(out)
        })
    }

    public render = (): JSX.Element => {
        return (
            <div id="search">
            </div>
        );
    }

}

Output

In the cloud function, await puppeteer.launch() throws an error. In the console, there is simply an empty object. And if we don't use a try catch block in the cloud function, the console outputs error INTERNAL and the status turns to 500. We're using Node JS 10 for our engine

tl;dr

const browser = await puppeteer.launch({headless: true, args: [
    '--no-sandbox',
    '--disable-setuid-sandbox',
]})

In a Google cloud function is throwing an unknown error and we don't know how to fix it.

like image 344
Luke-zhang-04 Avatar asked Oct 23 '25 17:10

Luke-zhang-04


1 Answers

Update

Our team found a Comprimise. We downgraded Puppeteer to v1.19.0, and we switched the engine to Node 8, and everything is working as expected

like image 88
Luke-zhang-04 Avatar answered Oct 26 '25 06:10

Luke-zhang-04