Overview
You can show GetScreenshot screenshots in Google Sheets with a small Apps Script custom function and the built-in IMAGE() function. No third-party add-on is needed.
The GetScreenshot API returns JSON that contains the URL of the screenshot. It does not return the image itself. That is why a formula such as =IMAGE("https://api.rasterwise.com/v1/get-screenshot?...") cannot work: IMAGE() needs a URL that points straight at an image file. The custom function below calls the API, reads the JSON and returns the image URL, which IMAGE() can then display.
Requirements
- GetScreenshot API Key - Get one here. Any plan works, because this integration calls the API directly
- Google account with access to Google Sheets
Setup
1. Add the script
- Open your spreadsheet
- Go to Extensions > Apps Script
- Delete any code in the editor and paste the following
- Click Save
/**
* Captures a screenshot with GetScreenshot and returns the image URL.
*
* @param {string} url The page to capture, starting with http:// or https://.
* @param {string} options Optional. Extra API parameters as a query string, for example "fullpage=true".
* @return {string} The URL of the screenshot image.
* @customfunction
*/
function GETSCREENSHOT(url, options) {
if (!url) return "";
var apiKey = PropertiesService.getScriptProperties().getProperty("GETSCREENSHOT_API_KEY");
if (!apiKey) throw new Error("Set the GETSCREENSHOT_API_KEY script property first.");
// Reuse a recent result so recalculations do not use more quota.
var cache = CacheService.getScriptCache();
var digest = Utilities.computeDigest(Utilities.DigestAlgorithm.MD5, url + " " + (options || ""));
var cacheKey = "getscreenshot-" + Utilities.base64Encode(digest);
var cached = cache.get(cacheKey);
if (cached) return cached;
var endpoint = "https://api.rasterwise.com/v1/get-screenshot" +
"?apikey=" + encodeURIComponent(apiKey) +
"&url=" + encodeURIComponent(url) +
(options ? "&" + options : "");
var response = UrlFetchApp.fetch(endpoint, { muteHttpExceptions: true });
var code = response.getResponseCode();
var body = response.getContentText();
var data = {};
try {
data = JSON.parse(body) || {};
} catch (e) {
// Some errors are plain text, not JSON.
}
if (code !== 200 || data.status !== "success" || !data.screenshotImage) {
throw new Error("Screenshot failed (HTTP " + code + "): " + (data.message || body.slice(0, 100)));
}
cache.put(cacheKey, data.screenshotImage, 21600); // 6 hours
return data.screenshotImage;
}
2. Store your API key
Keep the key out of the sheet and out of the code by saving it as a script property:
- In the Apps Script editor, open Project Settings (the gear icon)
- Under Script Properties, click Add script property
- Set the property name to
GETSCREENSHOT_API_KEYand the value to your API key - Click Save script properties
3. Use the function
Put a URL in cell A2, then enter this formula in B2:
=IMAGE(GETSCREENSHOT(A2))
The cell shows “Loading…” while the capture runs, which typically takes 8 to 15 seconds, and then displays the screenshot. To see the image URL instead of the image, use =GETSCREENSHOT(A2).
Screenshot Parameters
Pass extra API parameters as a second argument, written as a query string:
=IMAGE(GETSCREENSHOT(A2, "fullpage=true"))
| Parameter | Description | Example |
|---|---|---|
width |
Viewport width in pixels | width=1280 |
height |
Viewport height in pixels | height=800 |
fullpage |
Capture entire scrollable page | fullpage=true |
format |
Output format, png (default) or jpeg |
format=jpeg |
devicefactor |
Retina scaling (1, 2, or 3) | devicefactor=2 |
hidemsg |
Hide chat widgets | hidemsg=true |
hidecookie |
Cookie banners are hidden by default. Pass false to keep them |
hidecookie=false |
waituntil |
Page load condition. domcontentloaded is the fastest |
waituntil=domcontentloaded |
Join several parameters with &. The full list is in the API Reference.
Example Formulas
Mobile Screenshot (iPhone 12 size)
=IMAGE(GETSCREENSHOT(A2, "width=390&height=844"))
Full Page Screenshot
=IMAGE(GETSCREENSHOT(A2, "fullpage=true"))
Clean Screenshot (No Chat Widgets)
=IMAGE(GETSCREENSHOT(A2, "hidemsg=true"))
High-Resolution Retina Screenshot
=IMAGE(GETSCREENSHOT(A2, "devicefactor=2"))
Only for Non-Empty Rows
=IF(A2<>"", IMAGE(GETSCREENSHOT(A2)), "")
Error Handling
Wrap in IFERROR() to handle failed screenshots gracefully:
=IFERROR(IMAGE(GETSCREENSHOT(A2)), "Screenshot failed")
IMAGE Function Modes
The IMAGE() function accepts an optional second parameter for sizing:
| Mode | Description |
|---|---|
1 (default) |
Resize image to fit cell, maintain aspect ratio |
2 |
Stretch image to fill cell |
3 |
Use original image size |
4 |
Custom size with width and height parameters |
Example with fit-to-cell mode:
=IMAGE(GETSCREENSHOT(A2), 1)
Quota and Recalculation
Every time the function calls the API it uses one screenshot of your monthly quota, including calls that fail.
- Sheets runs a custom function again when its arguments change. Editing the URL in A2 triggers a new capture.
- The script caches each result for six hours. A recalculation with the same URL and options inside that window returns the cached image URL and does not call the API.
- After six hours a recalculation takes a fresh capture and uses quota again.
- A column of 200 formulas means 200 captures. Fill the formula down in small batches.
- Screenshots are stored for 30 days. After that the image URL stops working and the cell needs a new capture.
If you want screenshots that never recalculate, use the batch script below. It writes the image URLs into the sheet as plain values.
Batch Processing
Custom functions must finish within 30 seconds, so a slow page fails with an “Exceeded maximum execution time” error. For slow pages or long lists, add this menu-driven script below the function in the same Apps Script project:
function onOpen() {
SpreadsheetApp.getUi()
.createMenu("GetScreenshot")
.addItem("Capture selected URLs", "captureSelected")
.addToUi();
}
/**
* For every URL in the selected cells, writes the screenshot URL
* into the cell to the right.
*/
function captureSelected() {
var range = SpreadsheetApp.getActiveRange();
var values = range.getValues();
for (var row = 0; row < values.length; row++) {
var url = values[row][0];
if (!url) continue;
var target = range.getCell(row + 1, 1).offset(0, 1);
try {
target.setValue(GETSCREENSHOT(url));
} catch (e) {
target.setValue("Error: " + e.message);
}
SpreadsheetApp.flush();
}
}
To use it:
- Reload the spreadsheet. A GetScreenshot menu appears
- Select the cells in column A that hold your URLs
- Click GetScreenshot > Capture selected URLs. The first run asks you to authorize the script
- The image URLs are written to column B. Show them with
=IMAGE(B2)in column C
Example structure:
| A (URL) | B (Screenshot URL) | C (Screenshot) |
|---|---|---|
| https://example.com | written by the script | =IMAGE(B2) |
| https://google.com | written by the script | =IMAGE(B3) |
Apps Script stops a run after six minutes. At 8 to 15 seconds per capture that is enough for about 20 pages, so select about 20 rows at a time.
Troubleshooting
“Set the GETSCREENSHOT_API_KEY script property first”
- Add the script property as described in step 2 of the setup
“Screenshot failed (HTTP 500): error”
- The API key is not recognised. Check the value of the script property for typos or spaces
“Screenshot failed (HTTP 429)”
Limit Exceededmeans your monthly quota is used upToo Many Requestsmeans too many captures ran at once. Fill the formula down in smaller batches
“Exceeded maximum execution time”
- The capture took longer than the 30 seconds a custom function may run
- Add
waituntil=domcontentloadedas an option, or use the batch script
Image appears broken
- The screenshot is older than 30 days and was deleted. Capture it again
- Use
=GETSCREENSHOT(A2)withoutIMAGE()to see the URL or the error message
Screenshot is outdated
- The script returns the cached result for six hours
- To force a new capture, change the options slightly, for example add
timewait=2100
Quota running out quickly
- Each capture uses one screenshot of your quota
- Reduce the number of live formulas, or switch to the batch script so results are stored as plain values
Support
- API Reference: API Docs
- Support Email: support@rasterwise.com