Knowing all the bog standard metadata for a screenshot isn't enough information for everyone.
Saving the HTML and parsing it server side is one option. But that takes time and can be a memory intensive pain to do at scale.
What if you could get any data you want from a page at the same moment your screenshot is being taken?
Urlbox runs your own JavaScript in the page with the js option. That JavaScript can return data to you by assigning a value to a special variable, window.customUrlboxData.
Here's an example of a simple request you could make including some JavaScript you'd like us to execute:
curl -X POST \
https://api.urlbox.com/v1/render/sync \
-H 'Authorization: Bearer YOUR_URLBOX_API_SECRET' \
-H 'Content-Type: application/json' \
-d '{"url":"https://www.bbc.co.uk/news/technology-63635380", "save_metadata": true, "js": "window.customUrlboxData = { h1: document.querySelector(\"h1\")?.textContent ?? null }"}'It results in a response like the following, with your data under metadata.custom:
{
"renderUrl": "https://renders.urlbox.com/ub-temp-renders/renders/.../<render-id>.png",
"size": 608845,
"renderTime": 6609,
"queueTime": 127,
"metadataUrl": "https://renders.urlbox.com/ub-temp-renders/renders/.../<render-id>.json",
"metadata": {
"author": "BBC News",
"title": "Google to pay record $391m privacy settlement",
"custom": {
"h1": "Google to pay record $391m privacy settlement"
}
}
}The same metadata object, including custom, also comes back in the async status response, in the render.succeeded webhook and in the JSON file at metadataUrl, so it works however you integrate. Your JavaScript can await anything it needs before assigning, and if customUrlboxData clashes with something on the page you can pick a different name with custom_data_variable.
The js option is available on the Ultra plan and above. For the full details, including how values are converted and how to confirm a metadata file belongs to a render, see Returning data from your JavaScript in the docs.
