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,clearIntervalrequestAnimationFrame,requestIdleCallbackqueueMicrotask,AbortControllerURL,URLSearchParamsperformance.now()crypto.randomUUID(), which isn't cryptographically secure, so not for secretsfetch,XMLHttpRequest,EventSource,Headers,Request,Response,WebSocket: see Network requestsReadableStream,TextEncoder,TextDecoder(UTF-8 only),atob(),btoa(),DOMExceptionBlob,URL.createObjectURL(),ProgressEventIntersectionObserver, from Lynx's own visibility checks: see Detect when elements are visiblestructuredClone()andEventTarget: see Copies and eventscrypto.getRandomValues(), from the phone's secure random generator: see Random numbers- For drawing in a
<canvas>:document.createElement('canvas')andOffscreenCanvas: canvases off the page, with a 2D or WebGL2 contextPath2D,ImageData,createImageBitmap(),ImageBitmapImage, for loading textures, not for showing images: use<image>ResizeObserver,devicePixelRatio,self
- Newer built-in methods, up to ES2026, such as
array.at(),toSorted()andObject.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:
fetchwithprovideHttpClient()XMLHttpRequestwithwithXhr()IntersectionObserverwith@defer (on viewport)TextEncoderwith$localizeBlobwith a canvas'stoBlob()orconvertToBlob()fetchbringsReadableStream,TextEncoder,TextDecoderandBlobtoo, for reading a responseXMLHttpRequestandEventSourcebringfetchLynxImagePickerbringsBlobWebSocketwith RxJS'swebSocket(), and it bringsBlob
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,ImageBitmapandcreateImageBitmap()come with the canvas. That's where a file names'canvas'(as a template's<canvas>does) or one of them.Path2Dcomes 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.
documentandwindowcan be listened on. They hear touches anywhere on screen. Seedocument:,window:andbody:listeners.windowhearsresize.window.innerWidthandwindow.innerHeightare the screen's size.EventandCustomEventare 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,ArrayBufferand typed arrays, errors, and cycles. A class instance comes back as a plain object. A function or a symbol throws aDataCloneError.EventTargetcan be made withnew EventTarget()or extended, to give an object of your own events.once,signalandhandleEventwork as in the browser.
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:
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
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 theen-USway, and dates as01/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:
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:
These are still missing, because they need the engine itself, or they're browser APIs rather than JavaScript:
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.
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.
Related
- Coming from web Angular
- Share code with an Angular web app
- Threads: where your code runs
- Debugging: how to see errors like these.
