From 3341e8d8ddf35fef99350344d2f0030590d62a13 Mon Sep 17 00:00:00 2001 From: Vishal <321vishalds@gmail.com> Date: Thu, 1 Aug 2024 14:02:07 +0530 Subject: [PATCH] abort requests to api.zitefy.com (#9) this is a temporary fix. doesn't close the issue. --- scripts/screenshot.js | 44 +++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/scripts/screenshot.js b/scripts/screenshot.js index d7a0fd6..e8ffa83 100644 --- a/scripts/screenshot.js +++ b/scripts/screenshot.js @@ -3,19 +3,43 @@ During initial setup, run bun run puppeteer browsers install chrome, and copy the executable path to line 8 */ const puppeteer = require('puppeteer'); +const fs = require('fs'); (async () => { - const browser = await puppeteer.launch({executablePath: '/home/vishalds/.cache/puppeteer/chrome/linux-126.0.6478.182/chrome-linux64/chrome'}); - const page = await browser.newPage(); - await page.goto('file://' + process.argv[2]); + try { + const browser = await puppeteer.launch({ + executablePath: '/home/vishalds/.cache/puppeteer/chrome/linux-126.0.6478.182/chrome-linux64/chrome', + args: ['--no-sandbox', '--disable-setuid-sandbox'] + }); - // Mobile screenshot - await page.setViewport({ width: 412, height: 915 }); - await page.screenshot({ path: process.argv[3] }); + const page = await browser.newPage(); + await page.setRequestInterception(true); - // Desktop screenshot - await page.setViewport({ width: 1280, height: 800 }); - await page.screenshot({ path: process.argv[4] }); + // Intercept requests to our own API & block them + // this is a temporary fix, has to be mitigated completely asap + page.on('request', (request) => { + if (request.url().includes('api.zitefy.com')) { + request.abort(); + } else { + request.continue(); + } + }); - await browser.close(); + await page.goto('file://' + process.argv[2], { + waitUntil: 'networkidle0', + timeout: 60000 + }); + + await page.setViewport({ width: 412, height: 915 }); + await page.screenshot({ path: process.argv[3] }); + + await page.setViewport({ width: 1280, height: 800 }); + await page.screenshot({ path: process.argv[4] }); + + await browser.close(); + + } catch (error) { + fs.writeFileSync('screenshot_error.log', error.toString()); + process.exit(1); + } })(); \ No newline at end of file