Created
July 30, 2020 13:50
-
-
Save ilicfilip/9f09da25ae7711bd38ca075000f376b8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const puppeteer = require( 'puppeteer' ); | |
const argv = require( 'minimist' )( process.argv.slice(2) ); | |
var utils = require( './includes/utils.js' ); | |
const url = argv.url || 'https://www.google.com'; | |
// const format = argv.format === 'jpeg' ? 'jpeg' : 'png'; | |
const viewportWidth = argv.viewportWidth || 1440; | |
const viewportHeight = argv.viewportHeight || 900; | |
const delay = argv.delay || 0; | |
const nameSuffix = argv.nameSuffix || ''; | |
const screenshotPath = argv.screenshotPath || './'; | |
( async () => { | |
var screenshotName = ''; | |
const browser = await puppeteer.launch(); | |
const page = await browser.newPage(); | |
await page.setViewport( { 'width': viewportWidth, 'height': viewportHeight } ); | |
await page.goto( url, { 'waitUntil' : 'networkidle0' } ); | |
await page.evaluate( () => { | |
var styleSelector = document.getElementById( 'style-selector' ), | |
testimonials = document.getElementsByClassName( 'fusion-testimonials' ); | |
// Hide SS. | |
if ( null !== styleSelector ) { | |
styleSelector.style.display = 'none'; | |
} | |
// Hide Testimonials. | |
if ( 'undefined' !== typeof testimonials ) { | |
for ( var i = 0; i < testimonials.length; i++ ) { | |
testimonials[ i ].style.visibility = 'hidden'; | |
} | |
} | |
// Show hidden elements. | |
document.getElementsByTagName( 'body' )[0].classList.add( 'dont-animate' ); | |
// Scroll to bottom of the page. | |
return Promise.resolve( window.scrollTo( 0, document.body.scrollHeight ) ); | |
} ); | |
// remove protocol | |
screenshotName = utils.urlToName( url ); | |
/* | |
page.on( 'console', msg => { | |
for ( let i = 0; i < msg.args().length; ++i ) | |
console.log( `${i}: ${msg.args()[i]}` ); | |
}); | |
// page.evaluate(() => console.log('hello', 5, {foo: 'bar'})); | |
*/ | |
await page.waitFor( delay ); | |
await page.screenshot( { path: screenshotPath + '/' + screenshotName + nameSuffix + '.png', fullPage: true } ); | |
await browser.close(); | |
} ) (); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment