How to screenshot a website/URL in Javascript
1 min readMar 8, 2020
Here is a super quick tutorial on how to use one of our APIs to screenshot a URL.
Add this script tag to your HTML file to import the API client that we will be using today.
<script src="https://cdn.cloudmersive.com/jsclient/cloudmersive-document-convert-client.js"></script>
Now call our URL screenshot function as shown here:
var CloudmersiveConvertApiClient = require('cloudmersive-convert-api-client');var defaultClient = CloudmersiveConvertApiClient.ApiClient.instance;// Configure API key authorization: Apikeyvar Apikey = defaultClient.authentications['Apikey'];Apikey.apiKey = 'YOUR API KEY';// Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)//Apikey.apiKeyPrefix = 'Token';var apiInstance = new CloudmersiveConvertApiClient.ConvertWebApi();var input = new CloudmersiveConvertApiClient.ScreenshotRequest(); // ScreenshotRequest | Screenshot request parametersvar callback = function(error, data, response) {if (error) {console.error(error);} else {console.log('API called successfully. Returned data: ' + data);}};apiInstance.convertWebUrlToScreenshot(input, callback);
That’s it! Seriously, how easy was that? If you want more useful functions like this that are just as easy to implement, we’ve got you covered. We have hundreds of other APIs that run the gamut from converting image formats to running optical character recognition on photos.