On google Cloud Functions when I try to use puppeteer I get the following error for all sites that I try, an example for google.com:
Error: net::ERR_NAME_RESOLUTION_FAILED at http://www.google.com
at navigate (/srv/node_modules/puppeteer/lib/FrameManager.js:101:37)
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
-- ASYNC --
at Frame.<anonymous> (/srv/node_modules/puppeteer/lib/helper.js:110:27)
at Page.goto (/srv/node_modules/puppeteer/lib/Page.js:656:49)
at Page.<anonymous> (/srv/node_modules/puppeteer/lib/helper.js:111:23)
at /srv/index.js:35:20
at <anonymous>
at process._tickDomainCallback (internal/process/next_tick.js:229:7)
the Cloud Functions code:
const functions = require("firebase-functions");
const cors = require("cors")({origin: true});
const Firestore = require("@google-cloud/firestore");
const puppeteer = require("puppeteer");
const cheerio = require("cheerio");
exports.getSiteOne = functions
.runWith({ memory: "2GB" })
.https.onRequest((req, res) => {
cors(req, res, async function() {
try {
const browser = await puppeteer.launch({
headless: true,
args: ["--no-sandbox", "--disable-setuid-sandbox"]
});
const page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3419.0 Safari/537.36');
await page.goto("http://www.google.com", {
waitUntil: "networkidle0"
});
var html = await page.content();
res.status(200).json({
message: "cron added",
html
});
}
catch (err) {
console.log(err);
res.status(500).json({
error: err
});
}
});
});
puppeteer version "^1.14.0"
NB: when I serve it locally it works fine
The error is saying that the DNS lookup fails. I'm assuming you are on the free "Spark Plan". That one is not allowing any outgoing traffic:
Outbound networking: Google services only
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments