For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /guide/concepts/javascript-environment.md.

The JavaScript environment

Your app's JavaScript runs in Lynx's engine, not in a browser. Standard JavaScript works, but browser APIs mostly don't. This page lists what's there, what's missing, and what to use instead.

What AngularLynx adds for you

Lynx doesn't provide some APIs that Angular relies on. AngularLynx adds them before your app starts:

  • setTimeout, setInterval, clearTimeout, clearInterval
  • requestAnimationFrame, requestIdleCallback
  • queueMicrotask, AbortController
  • URL, URLSearchParams
  • performance.now()
  • crypto.randomUUID(), which isn't cryptographically secure, so not for secrets
  • fetch, XMLHttpRequest, EventSource, Headers, Request, Response, WebSocket: see Network requests
  • ReadableStream, TextEncoder, TextDecoder (UTF-8 only), atob(), btoa(), DOMException
  • Blob, URL.createObjectURL(), ProgressEvent
  • IntersectionObserver, from Lynx's own visibility checks: see Detect when elements are visible
  • structuredClone() and EventTarget: see Copies and events
  • crypto.getRandomValues(), from the phone's secure random generator: see Random numbers
  • For drawing in a <canvas>:
    • document.createElement('canvas') and OffscreenCanvas: canvases off the page, with a 2D or WebGL2 context
    • Path2D, ImageData, createImageBitmap(), ImageBitmap
    • Image, for loading textures, not for showing images: use <image>
    • ResizeObserver, devicePixelRatio, self
  • Newer built-in methods, up to ES2026, such as array.at(), toSorted() and Object.groupBy(): see JavaScript language level

Added only when used

fetch, XMLHttpRequest, EventSource, WebSocket, IntersectionObserver, ReadableStream, TextEncoder, TextDecoder, Blob, structuredClone(), EventTarget and crypto.getRandomValues() come only into apps that use them. Lynx loads all of an app's code into memory, whether it runs or not.

The build adds each where a file of your app or its libraries names it, or names an API that uses it:

  • fetch with provideHttpClient()
  • XMLHttpRequest with withXhr()
  • IntersectionObserver with @defer (on viewport)
  • TextEncoder with $localize
  • Blob with a canvas's toBlob() or convertToBlob()
  • fetch brings ReadableStream, TextEncoder, TextDecoder and Blob too, for reading a response
  • XMLHttpRequest and EventSource bring fetch
  • LynxImagePicker brings Blob
  • WebSocket with RxJS's webSocket(), and it brings Blob

A name built at runtime isn't seen. Code that reaches one as globalThis['fe' + 'tch'] finds it missing, unless another file names it. Write the name out, or call its enable function from @blotch/angular-lynx first: ɵenableFetch(), ɵenableXMLHttpRequest(), ɵenableEventSource(), ɵenableWebSocket(), ɵenableIntersectionObserver(), ɵenableReadableStream(), ɵenableTextEncoder(), ɵenableTextDecoder(), ɵenableBlob(), ɵenableStructuredClone(), ɵenableEventTarget() or ɵenableGetRandomValues().

The drawing APIs come the same way. See <canvas>.

  • document.createElement('canvas'), OffscreenCanvas, ImageData, Image, ImageBitmap and createImageBitmap() come with the canvas. That's where a file names 'canvas' (as a template's <canvas> does) or one of them.
  • Path2D comes with the 2D context.

document, window and navigator

The build also adds small document, window and navigator objects. They are not a DOM: document.querySelector() always returns null.

  • document and window can be listened on. They hear touches anywhere on screen. See document:, window: and body: listeners.
  • window hears resize. window.innerWidth and window.innerHeight are the screen's size.
  • Event and CustomEvent are there, for code that dispatches events of its own.

Copies and events

These work as they do in a browser, on the main thread, where your Angular code runs:

  • structuredClone(value) copies a value deeply, as the browser does: objects and arrays, Map, Set, Date, RegExp, ArrayBuffer and typed arrays, errors, and cycles. A class instance comes back as a plain object. A function or a symbol throws a DataCloneError.
  • EventTarget can be made with new EventTarget() or extended, to give an object of your own events. once, signal and handleEvent work as in the browser.
export class CartStore extends EventTarget {
  #items: Item[] = [];

  add(item: Item): void {
    this.#items.push(item);
    this.dispatchEvent(
      new CustomEvent('change', { detail: structuredClone(this.#items) }),
    );
  }
}

On a device, structuredClone(value, { transfer: [buffer] }) copies the buffer and leaves the original as it is: Lynx's engine can't empty one, as a browser does.

The background thread has neither.

Random numbers

crypto.getRandomValues() fills an array from the phone's secure random generator, as in a browser, so uuid, nanoid and sign-in code that makes a PKCE verifier work:

const bytes = crypto.getRandomValues(new Uint8Array(32));

Lynx itself has no secure random source, so the bytes come from a native module of the apps ng build --platform makes, and ng serve --platform's. Lynx Explorer has no such module, so there it's missing, and the console says so. An app whose code never calls it is built without the module.

crypto.randomUUID() isn't secure, so use getRandomValues() for anything secret. The background thread has no crypto.

What's missing, and what to use instead

Browser APIOn Lynx
The DOM: querySelector, createElement, innerHTMLUse templates, viewChild() and signals. createElement('canvas') and createElement('img') work, for drawing
getComputedStyle()Call element methods, or a main-thread script
matchMediaLynxSystemInfo for screen size
navigator.userAgent, navigator.languageLynxSystemInfo, LynxLocale
localStorage, sessionStorageSee Storage
IntlSee Intl
navigator.bluetoothLynxBluetooth
navigator.geolocationLynxGeolocation
navigator.clipboardLynxClipboard
Web Audio, Web Workers, drag and dropNot available

An element's getBoundingClientRect(), clientWidth and clientHeight answer from its last layout, so they're empty until the element has been laid out. Use ResizeObserver to hear when it has, or element methods to ask native for the box.

Code that calls a missing API throws when it runs. That includes code inside libraries. Before adding an npm package, check that it doesn't use the DOM.

Network requests

HttpClient, httpResource, fetch, XMLHttpRequest and EventSource work, and a response can stream as it arrives. So does WebSocket. Load data from a server shows how, and what's different on a device.

Lynx itself can make requests only from the background thread. The fetch and XMLHttpRequest AngularLynx adds pass each request there and bring the response back.

Lynx itself has no WebSocket. The one AngularLynx adds opens its sockets through a native module of the apps ng build --platform makes, which an app that never names WebSocket is built without. See Real-time with WebSockets.

Timers

setTimeout and the other timer functions work. When the user switches to another app, Lynx pauses JavaScript, so a timer can fire late after the app comes back. Don't use timers to measure elapsed time; compare Date.now() values instead.

Storage

There's no localStorage. To keep data after the app closes, use LynxLocalStorage, or LynxSecureStorage for tokens and other secrets. To share values between the pages of your app while it runs, use LynxSessionStorage.

Intl

Lynx has no Intl object where your app runs, so Intl.NumberFormat, Intl.DateTimeFormat and the rest throw. The methods that would use it ignore the locale:

  • toLocaleString() formats numbers the en-US way, and dates as 01/15/2026, 01:05:09 PM.
  • localeCompare() compares character codes, so 'é' sorts after 'z'.

There's no String.prototype.normalize() either.

List the Intl APIs your code uses in the build's intl option, and the build adds them, with your locales' data. Use Intl shows how.

Angular's own pipes, such as DatePipe and CurrencyPipe, use Angular's locale data instead of Intl, so they work without it.

URL

URL and URLSearchParams work, because AngularLynx provides them. There's no window.location and no address bar: the router keeps its URL in memory. See Routing.

JavaScript language level

Write modern TypeScript as usual. The build compiles new syntax, such as ?. and ??, down to what Lynx supports.

Lynx's engine has fewer built-in methods than a browser: the main thread supports ES2019 and some later additions. AngularLynx adds the rest, up to ES2026.

The build adds each one to the files that call it, your libraries' included. So it's there before their code runs, and your app carries only the ones its code calls. Your code and libraries written for current browsers can call them:

const last = items.at(-1);
const cheapest = items.toSorted((a, b) => a.price - b.price);
const byStatus = Object.groupBy(orders, (order) => order.status);
const shared = new Set(mine).intersection(new Set(theirs));
const firstTen = users
  .values()
  .filter((user) => user.active)
  .take(10)
  .toArray();

The build looks for the method's name in each file: called as a method, or in a string that could be the name you call it by.

It can't see a name your code puts together as it runs, or keeps as data: in a list, or as an object's value ({ decode: 'fromHex' }). Write the name out in the file that calls it:

// Seen: the names are in the code.
const sorted = items.toSorted();
const method = descending ? 'toReversed' : 'toSorted';
// Not seen: nothing in the file names toSorted.
const name = ['to', 'Sorted'].join('');

These are still missing, because they need the engine itself, or they're browser APIs rather than JavaScript:

MissingUse instead
The d and v regular expression flagsPatterns without them
new Error(message, { cause })Set error.cause after creating the error
JSON.rawJSON(), and context.source in a JSON.parse reviverNot available
Resizable ArrayBuffers, transfer(), Float16ArrayNot available
A missing method can blank the whole screen

If a template or a computed() calls something that's missing, the render fails, and nothing on screen updates. The error is "not a function" or "is not defined". It's not about signals.

Warning

for await over an array of promises On the main thread, for await (const value of promises) gives you each promise, not its value. Await each one yourself, or use await Promise.all(promises). Async generators work as usual.

Share code with a web app

A library of stores and services that your web app also imports can be type-checked against what's listed here instead of the DOM. Then a browser-only API is a type error, not a crash on a phone. See Share code with an Angular web app.