Skip to content

Instantly share code, notes, and snippets.

@mokoshalb
Created April 21, 2020 20:57
Show Gist options
  • Save mokoshalb/3b4d5c40c98790598a0adc83bc8e5af3 to your computer and use it in GitHub Desktop.
Save mokoshalb/3b4d5c40c98790598a0adc83bc8e5af3 to your computer and use it in GitHub Desktop.
Simple, lightweight jQuery Program to get website screenshots using Google Page Insights API
//Import jQuery
var url = "https://nodetent.com/";
$.ajax({
url: 'https://www.googleapis.com/pagespeedonline/v1/runPagespeed?url=' + url + '&screenshot=true',
context: this,
type: 'GET',
dataType: 'json',
timeout: 60000,
success: function(result) {
var imgData = result.screenshot.data.replace(/_/g, '/').replace(/-/g, '+');
var imgSrc = 'data:image/jpeg;base64,' + imgData;
},
error:function(e) {
alert("ERROR");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment