I want to get the screenshots from PageSpeed Insights. Using the API, I used a code that i founded here : https://embed.plnkr.co/plunk/c7fAFx, but doesn't work. please help me! I am learning to code.
get screenshot from PageSpeed Insights, using javascript
796 Views Asked by Rodolfo Westhoff At
1
There are 1 best solutions below
Related Questions in JAVASCRIPT
- Using Puppeteer to scrape a public API only when the data changes
- inline SVG text (js)
- An array of images and a for loop display the buttons. How to assign each button to open its own block by name?
- Storing the preferred font-size in localStorage
- Simple movie API request not showing up in the console log
- Authenticate Flask rest API
- Deploying sveltekit app with gunjs on vercel throws cannot find module './lib/text-encoding'
- How to request administrator rights?
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- In Datatables, start value resets to 0, when column sorting
- How do I link two models in mongoose?
- parameter values only being sent to certain columns in google sheet?
- Run main several times of wasm in browser
- Variable inside a Variable, not updating
Related Questions in HTML
- How to store a date/time in sqlite (or something similar to a date)
- How to use custom font during html to pdf conversion?
- Storing the preferred font-size in localStorage
- mp4 embedded videos within github pages website not loading
- Scrimba tutorial was working, suddenly stopped even trying the default
- Is there any way to glow this bulb image like a real light bulb
- With non-graphical maps in Leaflet, zoomDelta doesn't work
- What can I do to improve my coding on both html and css
- Uncaught TypeError: google.maps.LatLng is not a constructor at init (script.js:7:13)
- Bootstrap modal not showing at the desired position on a web page when the screen size is smaller
- Displaying a Movie List on a Website Using Jinja2 and Bootstrap
- How to redirect to thank you page after submitting a Google form embedded into a Google Site?
- Storing selected language in localStorage
- Fences (parenthesis, braces) in HTML and MathML
- Understanding Scroll Anchoring Behavoir
Related Questions in SCREENSHOT
- How to refresh a webcam snapshot periodically in a webpage
- Difficulty using Steamworks SDK to receiev screenshot request callback in my cpp app
- How to block screenshot in flutter ios application?
- How to capture a small screenshot (cursor included) around mouse?, with AutoHotkey
- Screenshot function works only on first capture
- C# screenshot doesn't contain whole screen
- Cannot get screen captures faster than one per 17 ms
- Get a photo of the entire page with HTML
- Element Screenshot in Selenium (python, ChromeDriver) is cut off at bottom for vertically tall element
- macos python os screencapture : 'could not create image from window'
- How to screenshot a SCNScene or SceneView?
- Problem with using SetWindowDisplayAffinity in Delphi
- in a fullpage screenshot, I want to show all of the content, how can I get scrollable elements' content height together efficient?
- Compress format and quality of screencap?
- How to take screenshot on failure
Related Questions in PAGESPEED-INSIGHTS
- PageSpeed Insights wrongly reporting cache policy?
- Want to pass multiple enum values for PageSpeed Insights API
- Is it possible to set cookies to Page Speed Insights tests?
- Can I rely on Google Lighthouse reports (especially for mobile sites)?
- Why does PageSpeed Insights keeps returning a high TTI (Time to Interactive) for a simple game?
- Lighthouse & pagespeed insights performance score is inconsistent
- Java- How to store Parsing nested json data into Java list
- Google Webfonts destroys CLS score (FOUT)
- PageSpeed Insights: Server-side rendering or Client-side rendering?
- Page Speed shows high score only first time
- get screenshot from PageSpeed Insights, using javascript
- How to improve LCP score of website where h1 is the largest contentful element painted within the viewport
- What are causes of the differece between CoreWebVitals assessment and PageSpeen Insights performance grade?
- PageSpeed Insights / Lighthouse / Unlighthouse all gives differents results
- How to satisfy Accessibility in PageSpeed Insight with a link that contains both an image and text?
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Why doesn't the linked code work?
Well because it is ancient and attempting to use the version 1 Page Speed Insights API.
It is currently on version 5 so that is why it does not work, v1 no longer exists as a public API.
How to recreate the functionality of this App?
As you are learning to code I will lay out the steps for you and then you can research how to do each step and use that to learn.
I will warn you as a beginner there is a lot to learn here. However on the flip side if you manage to work out how to do the below you will have a good first project that has covered multiple areas of JS development.
As you have marked this "JavaScript" I have assumed you want to do this in the browser.
This is fine up until the point where you want to save the images as you will have to work out how to ZIP them which is probably the most difficult part.
I have highlighted the steps you need to learn / implement in bold
1. First call the API:
The current URL for Page Speed Insights API is:
https://www.googleapis.com/pagespeedonline/v5/runPagespeed?url=https://yoursite.comJust change
url=https://yoursite.comto any site you want to gather the images from.For a small amount of requests a day you do not need to worry about an API key.
However if you do already have an API key just add
&key=yourAPIKeyto the end of the URL (replacing theyourAPIKeypart obviously :-P).You want to make an AJAX call to the API URL first.
2. Parse the response
Then when you get a response you are going to get a large JSON response.
You need to parse the JSON response and turn it into a JavaScript Object or Array you can work with.
3. Find the relevant parts
So once you have a JavaScript Object you can work with you are looking for
"final-screenshot"and"screenshot-thumbnails".These are located under "audits".
So for example if you parsed to an array called
lighthouseResultsyou would be looking forlighthouseResults['audits']['final-screenshot']orlighthouseResults['audits']['screenshot-thumbnails']"final-screenshot"contains how the site looked after it was loaded, so if you just want that you want this element.This contains an image that is base64 encoded (
lighthouseResults['audits']['final-screenshot']['details']['data'])."screenshot-thumbnails"is the part you want if you want the "filmstrip" of how the site loads over time. This contains a list of the thumbnails base64 encoded.To access each of these you need to loop over each of the items located at
lighthouseResults['audits']['screenshot-thumbnails']['details']['items']and return the['data']part for each['item']Find the parts that you want and store them to a variable
4a. Decode the image(s)
Once you have the image(s) in a variable, you will have them as a base64 encoded string at the moment. You need to convert these into usable
jpgimages.To do this you need to base64 decode each image.
For now I would just display them in the browser once they are decoded.
learn how to decode a base64 encoded image
4b. Alternative to decoding the image
As the images are base64 encoded they can be displayed directly in a browser without decoding first.
You can just add an image where the
srcyour base64 image string you gathered in step 3.If you just want to display the images this is much easier.
Add images to the screen and set the
srcto the base64 image string you have from step 3Saving the images
Now you said in a comment you want to save the images. Although this can be done via JavaScript it is probably a little advanced for starting out.
If you want to save the images you really want to be doing that server side.
However if you do want to download the images (filmstrip) in the browser then you want to look into a zip utility such as jszip.js.
The beauty of this is they normally want you to convert the images to base64 first before zipping them, so it may not actually be that difficult!