fetch
hc.fetch(input, init?)
Available since v2.0.0
Signature:(input: string | URL | { url: string }, init?: object) => Promise<object>
| Parameter | Type | Description |
|---|---|---|
input | | Required. URL string, URL, or Request-like { url } object. |
init.method | | HTTP method (default GET). |
init.headers | | Plain { "Header-Name": "value" } map, [key, value][] list, or Headers-like object. |
init.body | | Request body as a string or URLSearchParams. FormData, Blob, and AbortSignal are not supported. |
Sends an outbound HTTP request from the script sandbox using the same signature as the browser fetch() API. Disabled by default. Enable Allow script network requests in Settings → General before calling this API.
Use await — scripts are evaluated as async functions, so top-level await hc.fetch(...) is supported.
Query parameters belong on the URL (for example "https://api.example.com/items?limit=10"). Script-initiated sends use the same HTTP stack as the Requester — general settings for timeout, SSL verification, proxy, and redirects apply. Cookies from the jar are attached when the target host matches; Set-Cookie responses update the jar.
The returned promise resolves to a Response-like object:
| Property / method | Description |
|---|---|
ok |
true when status is in the 200–299 range |
status |
HTTP status code |
statusText |
Status text |
headers |
Headers-like object with .get(name) / .has(name) |
text() |
Async — response body as string |
json() |
Async — parses JSON; throws on invalid JSON |
arrayBuffer() |
Async — response body as an ArrayBuffer (UTF-8 of text) |
When the setting is disabled or the API is unavailable in the current context, hc.fetch throws.
var login = await hc.fetch("https://api.example.com/login", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ user: "ada", pass: "secret" }),
});
var data = await login.json();
hc.request.variables.set("token", data.token);