You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
panel: { // implemented by panels, called by the page script
45
+
/** implemented by panels, callable by the page script */
46
+
panel: {
45
47
flash: (message:string) =>void
46
48
}
47
49
sharedStates: {
@@ -54,15 +56,15 @@ Channel names are namespaced with the devframe id, like RPC ids. Function names
54
56
55
57
## The page script endpoint
56
58
57
-
Functions use the same authoring metadata as `defineRpcFunction` (`type`, Standard-Schema `args`/`returns`, `jsonSerializable`, `handler`), narrowed to the browser. The required `functions` object's keys are the function names, and it implements every function on that endpoint's protocol side. Each handler is contextually typed from its key and the corresponding function in the protocol. `defineChannelFunction` retains the named definition shape for lower-level authoring. Define each side's functions in that side's source files; the shared protocol file carries only types.
59
+
The required `functions` object declares every function on that endpoint's protocol side, preserving a compile-time completeness check. Request/response declarations require a `handler`; an event declaration uses `type: 'event'`, and the receiving endpoint may provide an optional `handler` or subscribe at runtime with `on()`. Functions use the same Standard-Schema `args`/`returns`and `jsonSerializable` metadata as `defineRpcFunction`, narrowed to the browser. Each handler is contextually typed from its key and the corresponding protocol function. `defineChannelFunction` retains the named definition shape for lower-level authoring. Define each side's functions in that side's source files; the shared protocol file carries only types.
`callEvent` on the pagescript is 1:N: it fans out to every connected panel, and panels that don't implement the function ignore it. Request/response *to* a panel goes through an explicit peer handle: `channel.panels[0].call('flash', '…')`.
89
+
`emit` on the page-script endpoint is 1:N: it fans out to every connected panel endpoint. Request/response *to* a panel goes through an explicit peer handle: `pageChannel.panels[0].call('flash', '…')`.
88
90
89
91
## The panel endpoint
90
92
@@ -94,19 +96,22 @@ import type { MyChannelProtocol } from '../shared/protocol'
The snippets form one channel pair: `pageChannel.emit('flash', …)` invokes `panelChannel.on('flash', …)`. In the other direction, `panelChannel.emit('highlight', …)` invokes the page-script endpoint's `highlight` handler and any matching `pageChannel.on()` listeners. An endpoint never receives its own emission.
114
+
110
115
## Shared state
111
116
112
117
The channel's shared-state layer mirrors [`rpc.sharedState`](/guide/shared-state) (same `SharedState<T>` handle, same accessor), with the page script playing the server's role as rendezvous and authority. Its first `get` of a key must provide the initial value; panels are seeded automatically on connect (including late joiners and re-connects) and converge through syncId-deduplicated patches.
@@ -133,7 +138,7 @@ Every failure mode is a coded `InPageChannelError` (`error.code`) with a message
133
138
The panel endpoint's connection lifecycle is explicit, so a panel renders a useful fallback instead of hanging:
134
139
135
140
-`channel.status` is `connecting` → `connected` → (`connecting` on port loss) → `closed`, with `events.on('status:updated', …)` for reactivity.
136
-
- While `connecting`, `call()` is queued (and still subject to its deadline) and `callEvent()` is buffered (up to `eventBufferLimit`, oldest dropped with a warning); both flush on connect.
141
+
- While `connecting`, `call()` is queued (and still subject to its deadline) and `emit()` is buffered (up to `eventBufferLimit`, oldest dropped with a warning); both flush on connect.
137
142
- A page script may legitimately never appear (the panel opened standalone, the user app not instrumented). Race `whenConnected(timeoutMs)` to show a "load the page script" empty state:
title: 'DF0077: In-Page Channel Function Not Registered'
3
+
description: 'An in-page channel listener names a function that is not registered on its endpoint.'
4
+
---
5
+
6
+
## Message
7
+
8
+
> In-page channel function "{name}" is not registered on this endpoint.
9
+
10
+
## Cause
11
+
12
+
`channel.on(name, listener)` received a name absent from that endpoint's required `functions` option. A page-script endpoint subscribes to functions declared under `pageScript`; a panel endpoint subscribes to functions declared under `panel`.
Declare the event in the endpoint's protocol side and `functions` option, then pass that declared name to `on()`.
30
+
31
+
## Source
32
+
33
+
-[`packages/devframe/src/in-page-channel/internal.ts`](https://github.com/devframes/devframe/blob/main/packages/devframe/src/in-page-channel/internal.ts): `createLocalFunctionRegistry().on()` throws this when no local definition matches the listener name.
Copy file name to clipboardExpand all lines: docs/content/8.references/5.browser-api.md
+13-1Lines changed: 13 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
title: 'Browser-Side API'
3
3
navigation:
4
4
icon: i-lucide-globe
5
-
description: 'Lookup tables for the browser side: connectDevframe options, RPC client events, connection statuses, and in-page channel error codes.'
5
+
description: 'Lookup tables for the browser side: connectDevframe options, RPC client events, connection statuses, and in-page channels error codes.'
6
6
---
7
7
8
8
Lookup tables for a devframe's browser side. Each section links the guide page that teaches the concept.
@@ -45,6 +45,18 @@ The values of `rpc.status`: [Handling connection and auth errors](/guide/client#
45
45
|`disconnected`| Socket closed (dropped mid-session or never opened). |
46
46
|`error`| Fatal: the socket errored or connection meta couldn't load. |
47
47
48
+
## In-page channel endpoints
49
+
50
+
The browser-only endpoint methods of the [in-page channel](/guide/in-page-channel). `emit()` sends to the opposite endpoint; `on()` handles events arriving from that endpoint.
|`emit(name, ...args)`| Fans an event out to every connected panel. | Sends an event to the page script, buffering while connecting. |
55
+
|`on(name, listener)`| Subscribes to events emitted by a panel. Returns an unsubscribe function. | Subscribes to events emitted by the page script. Returns an unsubscribe function. |
56
+
|`call(name, ...args)`| Available through a specific `PanelPeer`. | Calls a page-script function and awaits its result. |
57
+
|`events`| Local `panel:connected` / `panel:disconnected` lifecycle events. | Local `status:updated` lifecycle event. |
58
+
|`sharedState`| Owns the authoritative state. | Mirrors the page-script state. |
59
+
48
60
## In-page channel error codes
49
61
50
62
The `error.code` values of `InPageChannelError`: [Errors and fallbacks](/guide/in-page-channel#errors-and-fallbacks).
0 commit comments