I try to run puppeteer in a firebase function. As I understand this .md#running-puppeteer-on-google-cloud-functions it should work adding
"engines": {
"node": "8"
},
in package.json. I get positive feedback it use firebase deploy
functions: updating Node.js 8 function helloWorld(us-central1)...
Sadly it cashes with
Error: Error: Failed to launch chrome!
[0408/080847.149912:ERROR:zygote_host_impl_linux(89)] Running as root without --no-sandbox is not supported. See .
TROUBLESHOOTING: .md
at startPuppeteer.then.then.then.catch.error (/srv/index.js:42:15)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
Tested the same code on local which worked.
That' the cloud functions code which fails.
const functions = require('firebase-functions');
const puppeteer = require('puppeteer');
let browser = ""
let page = ""
const startPuppeteer = async () => {
browser = await puppeteer.launch();
page = await browser.newPage()
}
const usePageInPuppeteer = async (url) => {
await page.goto(url);
return await page.title()
}
const closePuppeteer = async () => {
return await browser.close();
}
const runtimeOpts = {
timeoutSeconds: 500,
memory: '2GB'
}
exports.helloWorld = functions
.runWith(runtimeOpts)
.https.onRequest((request, response) => {
//response.send()
startPuppeteer()
.then(() => {
return usePageInPuppeteer('')
})
.then(returnUse => {
console.log(returnUse)
return response.send(returnUse)
})
.then(() => {
return closePuppeteer()
})
.catch(error => {
throw new Error(error)
});
});
That the local test, which works
const puppeteer = require('puppeteer');
let browser = ""
let page = ""
const startPuppeteer = async () => {
browser = await puppeteer.launch();
page = await browser.newPage()
}
const usePageInPuppeteer = async (url) => {
await page.goto(url);
return await page.title()
}
const closePuppeteer = async () => {
return await browser.close();
}
startPuppeteer()
.then(() => {
return usePageInPuppeteer('')
})
.then(returnUse => {
console.log(returnUse)
return closePuppeteer()
})
.catch(error => {
throw new Error(error)
});
I try to run puppeteer in a firebase function. As I understand this https://github./GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md#running-puppeteer-on-google-cloud-functions it should work adding
"engines": {
"node": "8"
},
in package.json. I get positive feedback it use firebase deploy
functions: updating Node.js 8 function helloWorld(us-central1)...
Sadly it cashes with
Error: Error: Failed to launch chrome!
[0408/080847.149912:ERROR:zygote_host_impl_linux(89)] Running as root without --no-sandbox is not supported. See https://crbug./638180.
TROUBLESHOOTING: https://github./GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at startPuppeteer.then.then.then.catch.error (/srv/index.js:42:15)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
Tested the same code on local which worked.
That' the cloud functions code which fails.
const functions = require('firebase-functions');
const puppeteer = require('puppeteer');
let browser = ""
let page = ""
const startPuppeteer = async () => {
browser = await puppeteer.launch();
page = await browser.newPage()
}
const usePageInPuppeteer = async (url) => {
await page.goto(url);
return await page.title()
}
const closePuppeteer = async () => {
return await browser.close();
}
const runtimeOpts = {
timeoutSeconds: 500,
memory: '2GB'
}
exports.helloWorld = functions
.runWith(runtimeOpts)
.https.onRequest((request, response) => {
//response.send()
startPuppeteer()
.then(() => {
return usePageInPuppeteer('https://www.google.')
})
.then(returnUse => {
console.log(returnUse)
return response.send(returnUse)
})
.then(() => {
return closePuppeteer()
})
.catch(error => {
throw new Error(error)
});
});
That the local test, which works
const puppeteer = require('puppeteer');
let browser = ""
let page = ""
const startPuppeteer = async () => {
browser = await puppeteer.launch();
page = await browser.newPage()
}
const usePageInPuppeteer = async (url) => {
await page.goto(url);
return await page.title()
}
const closePuppeteer = async () => {
return await browser.close();
}
startPuppeteer()
.then(() => {
return usePageInPuppeteer('https://www.google.')
})
.then(returnUse => {
console.log(returnUse)
return closePuppeteer()
})
.catch(error => {
throw new Error(error)
});
Share
Improve this question
asked Apr 8, 2019 at 8:26
TobiTobi
1,9022 gold badges30 silver badges44 bronze badges
1
-
1
Running as root without --no-sandbox is not supported.
From that message is looks like you are missing a flag--no-sandbox
for running your extension – Igor Ilic Commented Apr 8, 2019 at 8:29
2 Answers
Reset to default 7const startPuppeteer = async () => {
browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
page = await browser.newPage()
}
works great. Thanks to https://stackoverflow./users/2911633/igor-ilic for the hint
you need to launch the chrome in sandbox mode. Running chrome as root is not supported directly, you can pass the argument --no-sandbox
to launch it as a root user.
The final code will look like this
browser = await puppeteer.launch({args: ['--no-sandbox']});