Skip to content

Screenshot functions#

Functions that take JPEG screenshots and return a base64 string (without the data: prefix) that you can save, send, or pass to a captcha-solving function or an AI.

If you need a data URL, add data:image/jpeg;base64, in front of the returned string yourself.

CapturePage#

Captures the part of the page currently visible on screen, not the whole long page. To get the part below, scroll down and capture again.

Syntax
await CapturePage(quality=80);
Parameters
Name Description
quality JPEG quality from 1 to 100. Default 80; lower it to make the string much smaller.
Returns

The base64 string of the JPEG image, or null if the capture failed.

Examples
1
2
3
4
5
const img = await CapturePage();        // quality 80
const smallImg = await CapturePage(50); // smaller string, enough to see the layout

// build a data URL from the screenshot
const dataUrl = "data:image/jpeg;base64," + img;

CaptureArea#

Captures a rectangular area of the visible part of the page. x1, y1 is the top-left corner and x2, y2 is the bottom-right corner (not the width and height).

Syntax
await CaptureArea(x1, y1, x2, y2, quality=80);
Parameters
Name Description
x1 x coordinate of the top-left corner, in pixels.
y1 y coordinate of the top-left corner, in pixels.
x2 x coordinate of the bottom-right corner; must be greater than x1. The width of the captured area is x2 - x1.
y2 y coordinate of the bottom-right corner; must be greater than y1. The height of the captured area is y2 - y1.
quality JPEG quality from 1 to 100. Default 80.
Returns

The base64 string of the JPEG image, or null if the capture failed (for example when x2 is smaller than x1).

Examples
1
2
3
4
5
// capture a 300 x 500 pixel area in the top-left corner
const img = await CaptureArea(0, 0, 300, 500);

// the same area, at the highest quality
const betterImg = await CaptureArea(0, 0, 300, 500, 100);

Note

To capture exactly one element, use CaptureElement: it finds the element's position and scrolls to it for you.

CaptureElement#

Captures a single element by CSS selector, for example a captcha image. Any element works, not only img tags. The function scrolls to the element before capturing. If several elements match, it captures the first visible one.

Syntax
await CaptureElement(selector, quality=80, frameSearch="", frameSearchType="");
Parameters
Name Description
selector A CSS selector, for example "#image_captcha".
quality JPEG quality from 1 to 100. Default 80.
frameSearch Condition for finding the iframe that contains the element; leave it empty for the main frame. See Iframes, selectors and waiting.
frameSearchType How to match frameSearch: "src-starts", "src-ends", "src-equals", "src-contains", "src-regex" or "frame-path". Required when you use frameSearch: if you leave it empty, the function works on the main frame.
Returns

The base64 string of the JPEG image, or null when no visible element matches or the capture failed. With an empty or non-string selector it returns undefined. Check the result before you use it.

Examples
1
2
3
4
5
6
7
8
9
// capture the captcha image
const captcha = await CaptureElement("#image_captcha");
if (!captcha) Log("Could not capture the captcha image");

// capture the avatar at quality 60
const avatar = await CaptureElement("#profile img.avatar", 60);

// capture a captcha image inside an iframe whose URL contains "captcha"
const img = await CaptureElement("img.challenge", 80, "captcha", "src-contains");