@open-matrix/hosting-browser (0.1.7)
Installation
@open-matrix:registry=npm install @open-matrix/hosting-browser@0.1.7"@open-matrix/hosting-browser": "0.1.7"About this package
@open-matrix/hosting-browser
Browser execution-environment adapters for @open-matrix/hosting.
Browser page lifetime
import { Host } from '@open-matrix/hosting';
import { AddBrowserPageLifetime } from '@open-matrix/hosting-browser';
const builder = Host.CreateApplicationBuilder({
ApplicationName: 'matrix-browser-runtime',
});
AddBrowserPageLifetime(builder.Services);
await using host = builder.Build();
await host.RunAsync();
BrowserPageLifetime observes pagehide and beforeunload, requests
IHostApplicationLifetime.StopApplication(), and removes its listeners during
host shutdown.
The event callback itself never waits for asynchronous cleanup. Browser termination is not process shutdown: the platform may terminate the page before transport drain, departure publication or telemetry flush completes.
Correct distributed behavior therefore requires:
- renewable presence/registry leases;
- server-side lease expiration;
- best-effort departure;
- idempotent reacquisition;
- a newly built host after BFCache restoration.
visibilitychange is intentionally not treated as shutdown. A hidden page is
not a stopped application.
Testing and embedding
Inject IBrowserLifecycleSource to test the lifetime without a real window or
to adapt an embedded browser shell. WindowBrowserLifecycleSource fails clearly
when constructed in a non-browser environment rather than silently pretending
that page events exist.
Dependencies
Dependencies
| ID | Version |
|---|---|
| @open-matrix/hosting | 0.1.7 |
Development Dependencies
| ID | Version |
|---|---|
| @types/node | ^25.0.10 |
| typescript | ^5.7.0 |