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
/** listened to by panels, emitted by the page script */
55
+
panel: { flash: (message:string) =>void }
48
56
}
49
57
sharedStates: {
50
58
state: { selections:string[] }
@@ -56,7 +64,9 @@ Channel names are namespaced with the devframe id, like RPC ids. Function names
56
64
57
65
## The page script endpoint
58
66
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.
67
+
The required `functions` option and optional `events` option declare every incoming name on the endpoint's protocol side; use `{}` for an empty direction. Functions require a `handler`. Events accept an optional `handler`, and `{}` registers an event for runtime subscriptions through `on()`. Handlers are contextually typed from the shared protocol and support Standard-Schema argument validation and `jsonSerializable` metadata. `defineChannelFunction` retains the named definition shape for lower-level authoring.
68
+
69
+
`call()` accepts names from `functions`, including actions returning `void` or `Promise<void>`: callers can await completion and catch errors or timeouts. `emit()`, its deprecated alias `callEvent()`, and `on()` use the names declared in `events`. Function and event names have separate namespaces.
`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', '…')`.
101
+
`emit` on the page-script endpoint fans out to every connected panel endpoint. Functions declared under `functions.panel` are called through a specific `pageChannel.panels[0].call()` peer handle.
90
102
91
103
## The panel endpoint
92
104
@@ -98,14 +110,17 @@ import { MY_CHANNEL } from '../shared/protocol'
serialize: value=>toRawDeep(value), // applied to every outgoing argument and result
180
+
functions: {},
181
+
events: { flash: {} },
165
182
})
166
183
```
167
184
@@ -174,7 +191,7 @@ Declaring a function `jsonSerializable: true` additionally enforces strict JSON
174
191
The same app open in two tabs means two page scripts on one origin. Each page script carries a per-tab instance id (persisted in `sessionStorage`), and handshakes are targeted `postMessage`, so a dock panel always pairs with its own tab's page script. A panel can also pin explicitly:
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.'
3
+
description: 'An in-page channel call names a function that is not registered on its endpoint.'
4
4
---
5
5
6
6
## Message
@@ -9,25 +9,39 @@ description: 'An in-page channel listener names a function that is not registere
9
9
10
10
## Cause
11
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`.
12
+
The two endpoints disagree about their channel contract. The calling endpoint names a function that the receiving endpoint did not register in its `functions` option. This usually means the page script and panel use different protocol declarations or incompatible devframe versions.
awaitpanel.call('inspect') // ✗ The page script did not register `inspect`.
25
39
```
26
40
27
41
## Fix
28
42
29
-
Declare the event in the endpoint's protocol side and `functions` option, then pass that declared name to `on()`.
43
+
Import one shared protocol declaration into both endpoints, then register every function from the receiving side of that protocol in its `functions` option.
30
44
31
45
## Source
32
46
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.
47
+
-[`packages/devframe/src/in-page-channel/internal.ts`](https://github.com/devframes/devframe/blob/main/packages/devframe/src/in-page-channel/internal.ts): `createLocalFunctionRegistry().resolve()` throws this when no local function definition matches the call name.
Copy file name to clipboardExpand all lines: docs/content/8.references/5.browser-api.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -50,6 +50,8 @@ The values of `rpc.status`: [Handling connection and auth errors](/guide/client#
50
50
51
51
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.
52
52
53
+
`InPageChannelProtocol` separates `functions` and `events`. Each section has optional `pageScript` and `panel` maps naming the receiving direction. Endpoint options require a complete `functions` map with handlers; `events` is optional, and when provided can include optional handlers (use `{}` to declare an event without a handler for `channel.on()`). `call()` uses function names regardless of return type, while `emit()`, `callEvent()` (deprecated), and `on()` use event names. A function returning `void` or `Promise<void>` remains an awaitable request/response call.
0 commit comments