Last active
June 5, 2018 19:30
-
-
Save xDimGG/9813e36bbcb79fdb3737a2ab7fdd4c35 to your computer and use it in GitHub Desktop.
Freely grab screenshots of web pages via Google's hidden PageSpeed API.
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 { get } = require('snekfetch'); | |
/** | |
* @typedef {Object} Query | |
* @prop {'mobile'|'desktop'} strategy The strategy to use when taking the screenshot | |
*/ | |
/** | |
* Screenshot a web page using its URL | |
* @param {string} url Web page URL to screenshot | |
* @param {?Query} query Extra querystring parameters | |
* @returns {Promise<String>} Base64 encoded image | |
*/ | |
module.exports = (url, query = {}) => | |
get('https://www.googleapis.com/pagespeedonline/v1/runPagespeed') | |
.query({ | |
screenshot: true, | |
strategy: 'desktop', | |
...query, | |
url, | |
}) | |
.then(res => res.body.screenshot.data.replace(/_/g, '/').replace(/-/g, '+')); |
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
{ | |
"author": "lloti <[email protected]> (https://dim.codes)", | |
"name": "page-screenshotter", | |
"version": "1.0.0", | |
"description": "Freely grab screenshots of web pages via Google's hidden PageSpeed API.", | |
"private": true, | |
"dependencies": { | |
"snekfetch": "^4.0.0" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment