overmux 0.0.9 → 0.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/dist/bin.js +1 -1
  3. package/dist/bin.js.map +1 -1
  4. package/dist/docs/400-reference/200-configuration.md +35 -0
  5. package/dist/docs/400-reference/500-server/400-notifications.md +4 -0
  6. package/dist/docs/400-reference/600-client/030-native-web-view.md +166 -0
  7. package/dist/docs/400-reference/600-client/300-tech-stack-recommendations.md +1 -0
  8. package/dist/docs/400-reference/700-cli/600-docs.md +1 -1
  9. package/dist/exports/client.d.ts +43 -7
  10. package/dist/exports/client.d.ts.map +1 -1
  11. package/dist/exports/client.js +172 -22
  12. package/dist/exports/client.js.map +1 -1
  13. package/dist/exports/index.js +1 -1
  14. package/dist/exports/index.js.map +1 -1
  15. package/dist/internal/server/coordinator/server-child.js +25 -1
  16. package/dist/internal/server/coordinator/server-child.js.map +1 -1
  17. package/dist/push/THIRD_PARTY_NOTICES.md +30 -0
  18. package/dist/push/badge.png +0 -0
  19. package/dist/push/icon.png +0 -0
  20. package/dist/push/sw.js +88 -0
  21. package/dist/push/sw.js.map +1 -0
  22. package/docs/400-reference/200-configuration.md +35 -0
  23. package/docs/400-reference/500-server/400-notifications.md +4 -0
  24. package/docs/400-reference/600-client/030-native-web-view.md +166 -0
  25. package/docs/400-reference/600-client/300-tech-stack-recommendations.md +1 -0
  26. package/docs/400-reference/700-cli/600-docs.md +1 -1
  27. package/package.json +3 -3
  28. package/src/internal/client/background-notifications.ts +3 -1
  29. package/src/internal/client/client-definition.ts +9 -13
  30. package/src/internal/client/host/desktop-host.ts +28 -2
  31. package/src/internal/client/host/hosted-pages/browser-notification-settings.tsx +8 -3
  32. package/src/internal/client/native-web-view.tsx +158 -0
  33. package/src/internal/client/push-assets/badge.png +0 -0
  34. package/src/internal/client/push-assets/icon.png +0 -0
  35. package/src/internal/client/push-service-worker.ts +118 -0
  36. package/src/internal/client/register-push-worker.ts +63 -0
  37. package/src/internal/client/shortcuts.tsx +17 -31
  38. package/src/internal/server/http/routes.ts +47 -2
  39. package/src/internal/shared/routes.ts +2 -0
  40. package/src/public/client.ts +5 -0
@@ -255,3 +255,38 @@ export default defineOvermuxDesktopConfig({
255
255
  macosTrafficLights: "hidden",
256
256
  });
257
257
  ```
258
+
259
+ ### `onBeforeInputEvent`
260
+
261
+ The optional `onBeforeInputEvent` callback exposes Electron's [`before-input-event`](https://www.electronjs.org/docs/latest/api/web-contents#event-before-input-event), receiving the actual Electron `Event`, `Input`, and receiving [`WebContents`](https://www.electronjs.org/docs/latest/api/web-contents).
262
+
263
+ You can use this callback to intercept Electron key presses.
264
+
265
+
266
+ ```ts
267
+ import { defineOvermuxDesktopConfig } from "@overmux/desktop";
268
+
269
+ export default defineOvermuxDesktopConfig({
270
+ onBeforeInputEvent: ({ event, input, webContents }) => {
271
+ const key = input.key.toLowerCase();
272
+ if (
273
+ process.platform !== "linux" ||
274
+ input.type !== "keyDown" ||
275
+ !input.meta ||
276
+ input.control ||
277
+ input.alt ||
278
+ input.shift ||
279
+ (key !== "c" && key !== "v")
280
+ ) {
281
+ return;
282
+ }
283
+
284
+ event.preventDefault();
285
+ if (key === "c") {
286
+ webContents.copy();
287
+ } else {
288
+ webContents.paste();
289
+ }
290
+ },
291
+ });
292
+ ```
@@ -30,3 +30,7 @@ export const serverConfig = defineOvermuxServer({
30
30
  - `open.link`: optional destination to open when the notification is activated. Use an app-relative path starting with `/` or an HTTP(S) URL without credentials.
31
31
 
32
32
  Each text field and link has a maximum length of 4,096 characters. `send()` returns `Promise<void>`.
33
+
34
+ ## PWA background notifications
35
+
36
+ Open `/_overmux/settings` on your Overmux server, and enable browser notifications. This requires HTTPS, or localhost for development. See [Hosted pages](../../500-hosted-pages.md) for adding a settings link to your application.
@@ -0,0 +1,166 @@
1
+ ---
2
+ title: Native web views
3
+ ---
4
+
5
+ `NativeWebView` embeds a website in Overmux Desktop using a chrome native webview.
6
+
7
+ ```tsx
8
+ import { NativeWebView } from "overmux/client";
9
+
10
+ export const Website = () => (
11
+ <NativeWebView
12
+ url="https://example.com"
13
+ style={{ width: "100%", height: 600 }}
14
+ fallback={
15
+ <a href="https://example.com" target="_blank" rel="noopener noreferrer">
16
+ Open website in browser
17
+ </a>
18
+ }
19
+ />
20
+ );
21
+ ```
22
+
23
+ ## Props
24
+
25
+ `NativeWebViewProps` and `NativeWebViewLoadError` are exported from `overmux/client`.
26
+
27
+ ### `url`
28
+
29
+ **Required.** Type: `string`. The initial website URL.
30
+
31
+ ```tsx
32
+ import { NativeWebView } from "overmux/client";
33
+
34
+ <NativeWebView url="https://example.com" style={{ height: 600 }} />;
35
+ ```
36
+
37
+ Changing this string navigates; rerendering the same URL preserves in-page navigation. A remount starts again at `url`, retaining cookies and site storage.
38
+
39
+ A blocked `url` prop clears the native page, including when an HTTP allowance is revoked. Blocked in-page links leave the current page in place. See [`allowedHttpOrigins`](#allowedhttporigins) for permitted destinations.
40
+
41
+ New-window links open in the system browser, not another embedded surface. The system browser has its own login state. Popup-based authentication flows may therefore not complete inside the embedded view; use in-page sign-in where supported.
42
+
43
+ ### `className`
44
+
45
+ **Optional.** Type: `string`. No default. Applies a CSS class to the desktop placeholder `div`, not the embedded website.
46
+
47
+ ```tsx
48
+ import { NativeWebView } from "overmux/client";
49
+
50
+ <NativeWebView
51
+ url="https://example.com"
52
+ className="website-pane"
53
+ style={{ height: 600 }}
54
+ />;
55
+ ```
56
+
57
+ Define the class in your application's stylesheet. See [Theming and CSS](./theming) for loading styles.
58
+
59
+ ### `style`
60
+
61
+ **Optional.** Type: `React.CSSProperties`. No default. Applies inline styles to the desktop placeholder `div`.
62
+
63
+ ```tsx
64
+ import { NativeWebView } from "overmux/client";
65
+
66
+ <NativeWebView
67
+ url="https://example.com"
68
+ style={{ width: "100%", height: 600 }}
69
+ />;
70
+ ```
71
+
72
+ Give the placeholder a **nonzero width and height**. The component has no default height. Desktop follows its rectangular position and size as the layout moves, scrolls or resizes. Hidden and zero-size placeholders hide the native surface without clearing its site data. See [Layout limitations](#layout-limitations) before using overlapping panes or CSS effects.
73
+
74
+ ### `fallback`
75
+
76
+ **Optional.** Type: `React.ReactNode`. Content shown in browsers, PWAs and desktop versions without native web view support.
77
+
78
+ ```tsx
79
+ import { NativeWebView } from "overmux/client";
80
+
81
+ <NativeWebView
82
+ url="https://example.com"
83
+ style={{ height: 600 }}
84
+ fallback={
85
+ <a href="https://example.com" target="_blank" rel="noopener noreferrer">
86
+ Open website in browser
87
+ </a>
88
+ }
89
+ />;
90
+ ```
91
+
92
+
93
+ ### `onLoadError`
94
+
95
+ **Optional.** Type: `(error: NativeWebViewLoadError) => void`. No default handler. Receives `{ url, code, message }` for main-page load failures, blocked destinations, invalid configuration or bridge errors.
96
+
97
+ ```tsx
98
+ import { NativeWebView, type NativeWebViewLoadError } from "overmux/client";
99
+
100
+ const reportLoadError = (error: NativeWebViewLoadError) => console.error(error);
101
+
102
+ <NativeWebView
103
+ url="https://example.com"
104
+ style={{ height: 600 }}
105
+ onLoadError={reportLoadError}
106
+ />;
107
+ ```
108
+
109
+ Main-page failures exclude subresource failures and aborted navigation superseded by a newer request.
110
+
111
+ | Code | Meaning |
112
+ | --- | --- |
113
+ | Numeric string, such as `"-105"` | Chromium load error |
114
+ | `ERR_URL_BLOCKED` | Destination rejected by navigation policy |
115
+ | `ERR_DESKTOP_BRIDGE` | Bridge or configuration failure |
116
+ | `ERR_OPEN_EXTERNAL` | Failed to open the system browser |
117
+ | `ERR_RENDER_PROCESS_GONE` | Native renderer crashed; the surface is destroyed |
118
+
119
+ Remount to retry after a native renderer crash.
120
+
121
+ ### `allowedHttpOrigins`
122
+
123
+ **Optional.** Type: `string[]`. Defaults to `[]`. Additional plain-HTTP origins to permit. An origin is the scheme, hostname and port, without a path.
124
+
125
+ ```tsx
126
+ import { NativeWebView } from "overmux/client";
127
+
128
+ <NativeWebView
129
+ url="http://devbox.local:3000"
130
+ style={{ height: 600 }}
131
+ allowedHttpOrigins={["http://devbox.local:3000"]}
132
+ />;
133
+ ```
134
+
135
+ HTTPS is allowed. HTTP is allowed for `localhost`, `127.0.0.1` and `[::1]`, plus exact origins in this list. Entries must be HTTP origins, optionally with a trailing slash. Wildcards, credentials, paths, queries and fragments are rejected. Matching includes the port. Other schemes are denied. Policy is enforced in Electron main for requested URLs, page navigation, redirects and new-window links.
136
+
137
+ ### `passthroughBindings`
138
+
139
+ **Optional.** Type: `readonly ShortcutBinding[]`. Defaults to `[]`. Keyboard bindings to forward to the owning Overmux UI while the embedded page has focus. `ShortcutBinding` is exported from `overmux/client`.
140
+
141
+ ```tsx
142
+ import { NativeWebView } from "overmux/client";
143
+
144
+ <NativeWebView
145
+ url="https://example.com"
146
+ style={{ height: 600 }}
147
+ passthroughBindings={["Escape", "Control+Shift+X", ["F12", "P", "R"]]}
148
+ />;
149
+ ```
150
+
151
+ Uses the same binding and chord syntax as [command shortcuts](./shortcuts), but does not require a matching command registration. A chord is a sequence of key presses, such as F12, then P, then R.
152
+
153
+ Overmux desktop intercepts a completed configured binding before the embedded page receives it and forwards its keyboard input, including modifiers and releases, to the owning Overmux UI. That UI then handles it through its ordinary DOM listeners - for example, a dialog's Escape handler, a local `onKeyDown`, or the normal shortcut host. The embedded page remains sandboxed and receives no Overmux bridge or command capability.
154
+
155
+
156
+ ## Security and shared sessions
157
+
158
+ Embedded pages have no Overmux bridge, preload script or Node access. Sandbox, context isolation and web security stay enabled. Permissions and downloads are denied.
159
+
160
+ All native views across connected Overmux instances share **one persistent desktop browser session**, `persist:overmux-native-web`. Cookies and login state survive unmounting, switching instances and restarting Desktop. This session is separate from Overmux authentication and from the system browser. Unmounting destroys the surface, not site data. Clearing an Overmux instance does not clear native website logins. There is no per-view profile or partition option.
161
+
162
+ ## Layout limitations
163
+
164
+ Native surfaces paint **above the DOM**, including React modals, menus and dropdowns. Use ordinary, non-overlapping rectangular panes. DOM stacking order, rounded corners, CSS transforms, ancestor clipping and arbitrary CSS effects are not faithfully reproduced. Bounds are clipped to the host window, not arbitrary DOM containers. Avoid layouts that depend on those effects; unmount the view when its native surface must not cover other content.
165
+
166
+ There is no `visible` prop, toolbar, zoom or history API, overlap coordination, or pane/session restoration. Host document reloads, crashes, instance changes and window destruction also destroy its native surfaces.
@@ -8,5 +8,6 @@ We recommend:
8
8
  - [TanStack Router](https://tanstack.com/router) for routing.
9
9
  - [shadcn/ui](https://ui.shadcn.com/) for UI components.
10
10
  - [Zod](https://zod.dev/) for schemas and runtime validation.
11
+ - [@pierre/diffs](https://diffs.com/) for building custom Git diff views.
11
12
 
12
13
  If your app already uses a different stack, follow its existing conventions.
@@ -122,7 +122,7 @@ Inspect these files so guidance matches the versions used by the application.
122
122
  #### `tech-stack-recommendations`
123
123
 
124
124
  ```text
125
- Prefer pnpm as the package manager, TanStack Router for routing, shadcn/ui for UI components, and Zod for schemas and runtime validation. Follow the application's established stack when it already differs.
125
+ Prefer pnpm as the package manager, TanStack Router for routing, shadcn/ui for UI components, and Zod for schemas and runtime validation. For custom Git diff views, prefer @pierre/diffs (https://diffs.com/). Follow the application's established stack when it already differs.
126
126
  ```
127
127
 
128
128
  [//]: # (END GENERATED AI CONTEXT)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "overmux",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "license": "MIT",
5
5
  "homepage": "https://github.com/richardgill/overmux",
6
6
  "repository": {
@@ -53,7 +53,7 @@
53
53
  "typescript": "5.9.3",
54
54
  "web-push": "3.6.7",
55
55
  "ws": "8.21.3",
56
- "@overmux/keybindings": "0.0.6"
56
+ "@overmux/keybindings": "0.0.7"
57
57
  },
58
58
  "devDependencies": {
59
59
  "@playwright/test": "1.58.0",
@@ -82,7 +82,7 @@
82
82
  "access": "public"
83
83
  },
84
84
  "scripts": {
85
- "build": "node ../../../scripts/generate-ai-context-docs.ts && rm -rf dist && vite build && vite build --config vite.auth.config.ts && vp pack && node scripts/clean-declarations.ts && node scripts/add-client-styles.mjs && cp -R docs dist/docs",
85
+ "build": "node ../../../scripts/generate-ai-context-docs.ts && rm -rf dist && vite build && vite build --config vite.auth.config.ts && vite build --config vite.push.config.ts && vp pack && node scripts/clean-declarations.ts && node scripts/add-client-styles.mjs && cp -R docs dist/docs",
86
86
  "dev": "pnpm run dev:cli",
87
87
  "dev:cli": "node --import jiti/register src/internal/cli/bin.ts serve",
88
88
  "serve": "node dist/bin.js serve",
@@ -5,6 +5,8 @@ import {
5
5
  backgroundNotificationSubscriptionSchema,
6
6
  } from "../shared/index";
7
7
 
8
+ import { registerPushWorker } from "./register-push-worker";
9
+
8
10
  const enabledStorageKey = "overmux.backgroundNotificationsEnabled";
9
11
 
10
12
  export type BackgroundNotificationStatus =
@@ -132,7 +134,7 @@ const removeCurrentSubscription = async () => {
132
134
  };
133
135
 
134
136
  const reconcileBackgroundNotifications = async () => {
135
- const registration = await navigator.serviceWorker.ready;
137
+ const registration = await registerPushWorker();
136
138
  const publicKey = await getPublicKey();
137
139
  let subscription = await registration.pushManager.getSubscription();
138
140
  const subscriptionKey = subscription
@@ -1,18 +1,23 @@
1
1
  import type { OvermuxContrast, OvermuxScheme } from "./theme-scope";
2
2
  import type { ComponentType } from "react";
3
3
  import {
4
- formatKeyBinding,
5
4
  keyBindingSchema,
6
5
  matchesKeyBinding,
6
+ shortcutBindingSchema,
7
7
  type KeyBinding,
8
+ type KeySequence,
9
+ type ShortcutBinding,
10
+ } from "@overmux/keybindings";
11
+ export { formatShortcutBinding } from "@overmux/keybindings";
12
+ export type {
13
+ KeyBinding,
14
+ KeySequence,
15
+ ShortcutBinding,
8
16
  } from "@overmux/keybindings";
9
- export type { KeyBinding } from "@overmux/keybindings";
10
17
  import { z } from "zod";
11
18
 
12
19
  import type { OvermuxServerApi } from "./browser-api";
13
20
 
14
- export type KeySequence = readonly [KeyBinding, KeyBinding, ...KeyBinding[]];
15
- export type ShortcutBinding = KeyBinding | KeySequence;
16
21
  export type ConditionalShortcutBinding = {
17
22
  binding: ShortcutBinding;
18
23
  when: { media: string };
@@ -23,10 +28,6 @@ export type ChordPrefix = {
23
28
  unmatched: "replay-to-focused-input";
24
29
  };
25
30
 
26
- const shortcutBindingSchema = z.union([
27
- keyBindingSchema,
28
- z.array(keyBindingSchema).min(2),
29
- ]);
30
31
  const commandBindingSchema = z.union([
31
32
  shortcutBindingSchema,
32
33
  z.object({
@@ -39,11 +40,6 @@ const chordPrefixSchema = z.object({
39
40
  unmatched: z.literal("replay-to-focused-input"),
40
41
  });
41
42
 
42
- export const formatShortcutBinding = (binding: ShortcutBinding) =>
43
- typeof binding === "string"
44
- ? formatKeyBinding(binding)
45
- : binding.map(formatKeyBinding).join(" ");
46
-
47
43
  type CommandRunResult = Promise<unknown> | unknown;
48
44
  type CommandRun<TServerConfig, TParams> = (input: {
49
45
  overmuxServerApi: OvermuxServerApi<TServerConfig>;
@@ -1,6 +1,34 @@
1
+ import type { ShortcutBinding } from "@overmux/keybindings";
2
+
3
+ import type { NativeWebViewLoadError } from "../native-web-view";
4
+
5
+ // This capability is independently versioned from the host envelope.
6
+ export type NativeWebViewBridge = {
7
+ version: 1;
8
+ command: (
9
+ input:
10
+ | { type: "create" | "destroy"; id: string }
11
+ | {
12
+ type: "configure";
13
+ id: string;
14
+ url: string;
15
+ allowedHttpOrigins: string[];
16
+ passthroughBindings: readonly ShortcutBinding[];
17
+ },
18
+ ) => Promise<void>;
19
+ setBounds: (
20
+ id: string,
21
+ bounds: { x: number; y: number; width: number; height: number },
22
+ ) => void;
23
+ onLoadError: (
24
+ callback: (input: { id: string; error: NativeWebViewLoadError }) => void,
25
+ ) => () => void;
26
+ };
27
+
1
28
  type DesktopHost = {
2
29
  version: 1;
3
30
  platform: string;
31
+ nativeWebView?: NativeWebViewBridge;
4
32
  instance?: { report: (identity: { instanceId: string }) => void; version: 1 };
5
33
  clipboard?: { writeText: (text: string) => void; version: 1 };
6
34
  notifications?: { show: (notification: unknown) => void; version: 1 };
@@ -11,5 +39,3 @@ declare global {
11
39
  overmuxHost?: DesktopHost;
12
40
  }
13
41
  }
14
-
15
- export {};
@@ -25,6 +25,7 @@ const statusMessage = (status: BackgroundNotificationStatus) => {
25
25
  export const BrowserNotificationSettings = () => {
26
26
  const [status, setStatus] =
27
27
  useState<BackgroundNotificationStatus>("checking");
28
+ const [error, setError] = useState<string>();
28
29
 
29
30
  useEffect(() => {
30
31
  let active = true;
@@ -35,8 +36,9 @@ export const BrowserNotificationSettings = () => {
35
36
  setStatus(next);
36
37
  }
37
38
  })
38
- .catch(() => {
39
+ .catch((cause: unknown) => {
39
40
  if (active) {
41
+ setError(cause instanceof Error ? cause.message : undefined);
40
42
  setStatus("error");
41
43
  }
42
44
  });
@@ -70,7 +72,8 @@ export const BrowserNotificationSettings = () => {
70
72
  ? "denied"
71
73
  : "disabled",
72
74
  );
73
- } catch {
75
+ } catch (cause) {
76
+ setError(cause instanceof Error ? cause.message : undefined);
74
77
  setStatus("error");
75
78
  }
76
79
  }, []);
@@ -80,7 +83,8 @@ export const BrowserNotificationSettings = () => {
80
83
  setStatus("checking");
81
84
  await disableBackgroundNotifications();
82
85
  setStatus("disabled");
83
- } catch {
86
+ } catch (cause) {
87
+ setError(cause instanceof Error ? cause.message : undefined);
84
88
  setStatus("error");
85
89
  }
86
90
  }, []);
@@ -92,6 +96,7 @@ export const BrowserNotificationSettings = () => {
92
96
  <h3>Browser notifications</h3>
93
97
  <p aria-live="polite" data-om-background-notifications-status="">
94
98
  {statusMessage(status)}
99
+ {status === "error" && error ? ` ${error}` : null}
95
100
  </p>
96
101
  <div data-om-hosted-actions="">
97
102
  {canEnable ? (
@@ -0,0 +1,158 @@
1
+ import { useEffect, useRef, type CSSProperties, type ReactNode } from "react";
2
+
3
+ import type { ShortcutBinding } from "@overmux/keybindings";
4
+
5
+ import type { NativeWebViewBridge } from "./host/desktop-host";
6
+
7
+ export type NativeWebViewLoadError = {
8
+ url: string;
9
+ code: string;
10
+ message: string;
11
+ };
12
+ export type NativeWebViewProps = {
13
+ url: string;
14
+ className?: string;
15
+ style?: CSSProperties;
16
+ fallback?: ReactNode;
17
+ onLoadError?: (error: NativeWebViewLoadError) => void;
18
+ allowedHttpOrigins?: string[];
19
+ passthroughBindings?: readonly ShortcutBinding[];
20
+ };
21
+
22
+ type MountedView = {
23
+ id: string;
24
+ active: boolean;
25
+ bridge: NativeWebViewBridge;
26
+ report: (error: NativeWebViewLoadError) => void;
27
+ };
28
+
29
+ const command = async (
30
+ view: MountedView,
31
+ input: Parameters<NativeWebViewBridge["command"]>[0],
32
+ url: string,
33
+ ) => {
34
+ try {
35
+ await view.bridge.command(input);
36
+ } catch (error) {
37
+ view.report({ url, code: "ERR_DESKTOP_BRIDGE", message: String(error) });
38
+ }
39
+ };
40
+
41
+ const trackBounds = (element: HTMLDivElement, view: MountedView) => {
42
+ let previous = "";
43
+ let frame = 0;
44
+ const measure = () => {
45
+ const rect = element.getBoundingClientRect();
46
+ const visible =
47
+ !document.hidden &&
48
+ element.checkVisibility({
49
+ opacityProperty: true,
50
+ visibilityProperty: true,
51
+ });
52
+ const bounds = {
53
+ x: Math.round(rect.x),
54
+ y: Math.round(rect.y),
55
+ width: visible ? Math.max(0, Math.round(rect.width)) : 0,
56
+ height: visible ? Math.max(0, Math.round(rect.height)) : 0,
57
+ };
58
+ const key = JSON.stringify(bounds);
59
+ if (key !== previous) {
60
+ previous = key;
61
+ view.bridge.setBounds(view.id, bounds);
62
+ }
63
+ };
64
+ const tick = () => {
65
+ measure();
66
+ frame = requestAnimationFrame(tick);
67
+ };
68
+ // ResizeObserver alone misses position-only changes (siblings, scrolling and
69
+ // animation). Sample once per frame, but send IPC only for changed pixel bounds.
70
+ tick();
71
+ document.addEventListener("visibilitychange", measure);
72
+ return () => {
73
+ cancelAnimationFrame(frame);
74
+ document.removeEventListener("visibilitychange", measure);
75
+ };
76
+ };
77
+
78
+ export const NativeWebView = ({
79
+ url,
80
+ className,
81
+ style,
82
+ fallback,
83
+ onLoadError,
84
+ allowedHttpOrigins = [],
85
+ passthroughBindings = [],
86
+ }: NativeWebViewProps) => {
87
+ const bridge =
88
+ typeof window === "undefined" ||
89
+ window.overmuxHost?.version !== 1 ||
90
+ window.overmuxHost.nativeWebView?.version !== 1
91
+ ? undefined
92
+ : window.overmuxHost.nativeWebView;
93
+ const element = useRef<HTMLDivElement>(null);
94
+ const mounted = useRef<MountedView | undefined>(undefined);
95
+ const latest = useRef({ url, onLoadError });
96
+ latest.current = { url, onLoadError };
97
+ // Equal array contents are not a navigation or a policy change.
98
+ const origins = JSON.stringify(allowedHttpOrigins);
99
+ const bindings = JSON.stringify(passthroughBindings);
100
+
101
+ useEffect(() => {
102
+ if (!bridge || !element.current) {
103
+ return;
104
+ }
105
+ const view: MountedView = {
106
+ id: crypto.randomUUID(),
107
+ active: true,
108
+ bridge,
109
+ report: (error) => {
110
+ // Keep caller exceptions out of IPC promise chains.
111
+ queueMicrotask(() => {
112
+ if (view.active) {
113
+ latest.current.onLoadError?.(error);
114
+ }
115
+ });
116
+ },
117
+ };
118
+ mounted.current = view;
119
+ const unsubscribe = bridge.onLoadError(({ id, error }) => {
120
+ if (id === view.id) {
121
+ view.report(error);
122
+ }
123
+ });
124
+ void command(view, { type: "create", id: view.id }, latest.current.url);
125
+ const stopTracking = trackBounds(element.current, view);
126
+ return () => {
127
+ view.active = false;
128
+ mounted.current = undefined;
129
+ stopTracking();
130
+ unsubscribe();
131
+ // Creation and destruction are ordered commands, not asynchronous load waits.
132
+ void command(view, { type: "destroy", id: view.id }, latest.current.url);
133
+ };
134
+ }, [bridge]);
135
+
136
+ useEffect(() => {
137
+ const view = mounted.current;
138
+ if (view) {
139
+ void command(
140
+ view,
141
+ {
142
+ type: "configure",
143
+ id: view.id,
144
+ url,
145
+ allowedHttpOrigins: JSON.parse(origins) as string[],
146
+ passthroughBindings: JSON.parse(bindings) as ShortcutBinding[],
147
+ },
148
+ url,
149
+ );
150
+ }
151
+ }, [bindings, bridge, url, origins]);
152
+
153
+ return bridge ? (
154
+ <div ref={element} className={className} style={style} />
155
+ ) : (
156
+ <>{fallback}</>
157
+ );
158
+ };