Skip to content

Commit

Permalink
fixed js screenshot mody
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanarlan committed Dec 10, 2023
1 parent 25762fc commit 124a9d6
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 36 deletions.
43 changes: 43 additions & 0 deletions screenshot.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const puppeteer = require('puppeteer-extra');
const StealthPlugin = require('puppeteer-extra-plugin-stealth');
puppeteer.use(StealthPlugin());

const url = process.argv[2];
const pageLoadTimeout = 30000; // 30 seconds for page load
const extraWaitTime = 5000; // 5 seconds extra wait after page load

(async () => {
try {
const browser = await puppeteer.launch({
headless: true, // Set to false to see the browser
args: ['--no-sandbox', '--disable-setuid-sandbox'], // Added for better stability in different environments
});

const page = await browser.newPage();

await page.setViewport({
width: 1200,
height: 1200,
deviceScaleFactor: 1,
});

await page.goto(url, {
waitUntil: "networkidle0",
timeout: pageLoadTimeout,
});

// Wait for additional time if needed, then take the screenshot
await page.waitForTimeout(extraWaitTime);

await page.screenshot({
path: "screenshot.jpg",
fullPage: true,
});

console.log("Screenshot saved as 'screenshot.jpg'");
} catch (error) {
console.error("An error occurred:", error);
} finally {
await browser.close();
}
})();
35 changes: 0 additions & 35 deletions screenshot.js

This file was deleted.

2 changes: 1 addition & 1 deletion vision_crawl.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def image_b64(image):
os.remove("screenshot.jpg")

result = subprocess.run(
["node", "screenshot.js", url],
["node", "screenshot.cjs", url],
capture_output=True,
text=True
)
Expand Down

0 comments on commit 124a9d6

Please sign in to comment.