2022-06-16 04:13:44 -05:00
|
|
|
const puppeteer = require("puppeteer");
|
|
|
|
const { PuppeteerBlocker } = require("@cliqz/adblocker-puppeteer");
|
|
|
|
const fetch = require("cross-fetch");
|
2022-06-17 20:18:48 -05:00
|
|
|
const { screenshotDirectory, pdfDirectory } = require("../config.js");
|
2022-05-26 11:15:07 -05:00
|
|
|
|
|
|
|
module.exports = async (link, id) => {
|
2022-06-17 20:18:48 -05:00
|
|
|
const browser = await puppeteer.launch({
|
|
|
|
args: ['--no-sandbox'],
|
|
|
|
timeout: 10000,
|
|
|
|
});
|
2022-05-26 11:15:07 -05:00
|
|
|
const page = await browser.newPage();
|
|
|
|
|
|
|
|
await PuppeteerBlocker.fromPrebuiltAdsAndTracking(fetch).then((blocker) => {
|
|
|
|
blocker.enableBlockingInPage(page);
|
|
|
|
});
|
|
|
|
|
2022-06-16 04:13:44 -05:00
|
|
|
await page.goto(link, { waitUntil: "load", timeout: 0 });
|
|
|
|
|
|
|
|
await page.screenshot({
|
2022-06-17 20:18:48 -05:00
|
|
|
path: screenshotDirectory + "/" + id + ".png",
|
2022-06-16 04:13:44 -05:00
|
|
|
fullPage: true,
|
|
|
|
});
|
2022-06-17 20:18:48 -05:00
|
|
|
await page.pdf({ path: pdfDirectory + "/" + id + ".pdf", format: "a4" });
|
2022-05-26 11:15:07 -05:00
|
|
|
|
|
|
|
await browser.close();
|
2022-06-16 04:13:44 -05:00
|
|
|
};
|