Advertisement
jz-nr

BrowserScreen.js

Dec 1st, 2021
1,172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // install:
  2. //     npm i puppeteer
  3.  
  4. // run (assuming this script is save as BrowserScreen.js):
  5. //     node BrowserScreen.js
  6.  
  7. // the script is saving a screenshot of the website every second to fresh-screenshot.png  
  8.  
  9. const puppeteer = require('puppeteer');
  10.  
  11.  
  12. (async () => {
  13.  
  14.     takeScreenshot = async function () {
  15.         await page.screenshot({ path: "fresh-screenshot.png" , omitBackground: true}); // use your own file name
  16.         console.log("Screenshot image is now fresh");
  17.         setTimeout(takeScreenshot, 1000);
  18.     }
  19.    
  20.  
  21.     const browser = await puppeteer.launch();
  22.     const page = await browser.newPage();
  23.     await page.goto('https://www.unixtimestamp.com/'); // use your own URL
  24.    
  25.     // // use this if your web page doesn't have transparent background by CSS:
  26.     // await page.evaluate(() => document.body.style.background = 'transparent');
  27.  
  28.     takeScreenshot();
  29.    
  30.     // await browser.close(); // this should be called once the script is finished
  31.    
  32. }) ();
  33.  
  34.  
  35.  
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement