Reputation: 578
Recently we have updated our Ubuntu server hard Disk, after updating I am getting errors when I try to scrape data using puppeteer as mentioned below:
Could not create a browser instance => : Error: Failed to launch the browser process!
1|app | /usr/bin/chromium-browser: 12: xdg-settings: not found
1|app | cannot perform operation: umount --no-follow /var/lib/snapd/hostfs//tmp/snap.rootfs_grFzK6: Invalid argument
1|app | TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
1|app | at onClose (/home/secfusionread/scrape/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:193:20)
1|app | at ChildProcess.<anonymous> (/home/secfusionread/scrape/node_modules/puppeteer/lib/cjs/puppeteer/node/BrowserRunner.js:184:79)
My Puppeteer connection code below, I was able to scrape data before the updating.
const puppeteer = require("puppeteer");
async function startBrowser() {
let browser;
//console.log(process.env.NODE_ENV);
try {
console.log("----------- Open the browser ------------");
browser = await puppeteer.launch({
// userDataDir: "../cache",
executablePath:
process.env.NODE_ENV === "production"
? "/usr/bin/chromium-browser"
: "",
args: [
"--no-sandbox",
"--disable-setuid-sandbox",
"--disable-dev-shm-usage",
"--disable-accelerated-2d-canvas",
"--no-first-run",
"--no-zygote",
"--single-process",
"--disable-gpu",
],
headless: true,
timeout: 6000,
});
} catch (err) {
console.log("Could not create a browser instance => : ", err);
}
return browser;
}
async function startPage(browser) {
let page;
try {
console.log("----------- Open a new page ------------");
page = await browser.newPage();
await page.setViewport({ width: 1200, height: 800 });
await page.setExtraHTTPHeaders({
"Accept-Language": "en-US,en;q=0.9",
});
await page.setUserAgent(
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
// "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36"
);
// await page.setRequestInterception(true);
// page.on("request", (req) => {
// if (req.resourceType() === "font" || req.resourceType() === "image") {
// req.abort();
// } else {
// req.continue();
// }
// });
} catch (err) {
console.log("Could not create a new page => : ", err);
}
return page;
}
module.exports = {
startBrowser,
startPage,
};
chromium-browser exists in /usr/bin/chromium-browser
, I tried a lot of code from google but nothing works.
Upvotes: 2
Views: 4609
Reputation: 8861
It is a missing dependency-related issue, which needs to be re-installed after Ubuntu was changed (hardware update under the server).
Even the error msg states this: xdg-settings
for example is included in xdg-utils
which is a direct dependency to puppeteer over Debian.
The exact missing libraries can be retrieved with: ldd /usr/bin/chromium-browser/<EXECUTABLE> | grep not
. (you need to retrieve the <EXECUTABLE>
's value for yourself, you can use the command whereis
)
The usual Debian (Ubuntu) dependencies are the following that need to be installed:
sudo apt-get install ca-certificates fonts-liberation libappindicator3-1 libasound2 libatk-bridge2.0-0 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgbm1 libgcc1 libglib2.0-0 libgtk-3-0 libnspr4 libnss3 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 lsb-release wget xdg-utils
Note: even if installing all the dependencies can solve your issue, I highly recommend finding out the exact missing ones and install only them to avoid updating unnecessary dependencies!
Upvotes: 1