Appearance
How-to: Debug postMessage Traffic
Use this when a napplet appears loaded but no NAP request or response is visible.
Checklist
- Confirm the iframe uses
sandbox="allow-scripts"withoutallow-same-origin. - Confirm the shell registered the iframe's
contentWindowbefore the napplet's bootstrap runs. The bootstrap sends a single window-levelnapplet.hellocarrying oneMessagePort(NIP-5D port-bound identity). - Confirm the hello bound a port:
originRegistry.getPort(windowId)is defined. Every NAP request and response travels over that port, not as window-levelmessageevents. - Confirm the napplet was not revoked.
ShellAdapter.onNappletRevokedreports a second hello, any other window-level message, a second load, or a closed port. A napplet that also imports@napplet/shimon a Kehto host sends a second hello. - Confirm messages are plain objects with a string
type. - Confirm ACL grants exist for the requested capability.
- Confirm the target service is registered.
Temporary trace
Observe port traffic through the host adapter in a local debug branch:
ts
const hooks: ShellAdapter = {
...adapter,
onNappletMessage: (windowId, message) => console.debug('[napplet->shell]', windowId, message.type),
onNappletRevoked: ({ windowId, reason, detail }) => console.debug('[revoked]', windowId, reason, detail),
};Window-level message listeners only ever see the napplet.hello handoff.
Remove debug traces before shipping. Source validation and ACL denial behavior should be tested, not bypassed.