Globals
Azot extensions run with a set of familiar Web APIs.
If you already know these APIs from the browser, most of the behavior and usage is the same. When in doubt, follow the MDN docs.
| Category | APIs |
|---|---|
| Debugging | console |
| Network | fetch, Request, Response, Headers, AbortController, AbortSignal |
| URLs | URL, URLSearchParams, URLPattern, open, window.open |
| Storage and cookies | localStorage, cookieStore, document.cookie |
| Crypto | crypto |
| Encoding and data | TextEncoder, TextDecoder, btoa, atob, Uint8Array |
| Data formats | Blob, JSON |
| Structured clone | structuredClone |
| Environment and events | navigator, Event, EventTarget |
| Eval | eval |
Azot
The Azot global holds the host API of the current extension.
| Property | Description |
|---|---|
Azot.signal | AbortSignal of the operation running your code. Throws outside an operation. See Cancellation. |
Console and debugging
Use the standard console helpers while developing.
console.log("hello");
console.warn("be careful");
console.error("something went wrong");Network
Use fetch with the same Request / Response model as in the browser.
Under the hood, Azot already adds headers like
User-Agentand similar to impersonate Chrome, so you only need to override them if you have a specific requirement.
const controller = new AbortController();
const response = await fetch("https://example.com/api", {
headers: new Headers({ accept: "application/json" }),
signal: controller.signal,
});
const data = await response.json();URLs
Parse URLs or match them with patterns.
const url = "https://example.com/movie/123456/watch";
const pattern = new URLPattern({ pathname: "/:mediaType/:id/watch" });
const match = pattern.exec(url);
const mediaType = match?.pathname.groups.mediaType;
const id = match?.pathname.groups.id;Open external links
Use window.open() or global open() to open a URL in the default browser.
window.open("https://example.com/pricing", "_blank");
open("https://example.com/help", "_blank");Storage and cookies
Use localStorage for simple key-value storage, and cookieStore for HTTP cookies. cookieStore is automatically populated from requests, so you can read cookies without setting them manually.
const token = localStorage.getItem("token");
if (!token) {
throw new Error("User is not authorized");
}
const sessionId = await cookieStore.get("sessionId");
if (!sessionId) {
throw new Error("Missing auth cookie");
}You can also read cookies from document.cookie:
const cookies = document.cookie;Crypto
Use Web Crypto APIs for hashing and random bytes.
const data = new TextEncoder().encode("hello");
const hash = await crypto.subtle.digest("SHA-256", data);
const bytes = new Uint8Array(hash);Encoding and data
Encoding helpers work the same as in the browser.
const raw = new TextEncoder().encode("hello");
const text = new TextDecoder().decode(raw);
const base64 = btoa(text);
const original = atob(base64);There's also Base64 and HEX helpers in Uint8Array.
const bytes = Uint8Array.fromHex("48656c6c6f");
const hex = bytes.toHex();
const base64 = bytes.toBase64();
const decoded = Uint8Array.fromBase64(base64);Structured clone
Clone complex data safely.
const copy = structuredClone({ items: [1, 2, 3] });Environment and events
Read environment info and use EventTarget utilities.
const platform = navigator.platform;
const target = new EventTarget();
const event = new Event("ready");
target.dispatchEvent(event);Eval
Evaluate code dynamically when needed.
const add = eval("(a, b) => a + b");
const result = add(2, 3);