Event listener for hw:// protocol links that communicates with parent frames via postMessage.
npm install @hyperware-ai/hw-protocol-watcherThe watcher automatically starts when the module is loaded:
import '@hyperware-ai/hw-protocol-watcher';
// Now any hw:// links will be handled automaticallyimport { startWatching, stopWatching, HWProtocolWatcher } from '@hyperware-ai/hw-protocol-watcher';
// Start watching
startWatching();
// Stop watching
stopWatching();
// Or use the class directly for more control
const watcher = new HWProtocolWatcher();
watcher.start();
watcher.stop();- Link Detection: Listens for clicks on anchor tags (
<a>) withhrefattributes starting withhw:// - Iframe Check: Only processes links when running inside an iframe (
window.parent !== window) - Message Format: Sends a postMessage to the parent window with:
{ type: 'HW_LINK_CLICKED', url: '/some-app-name:some-publisher.os/optional-path/etcetc' }
Given a link like:
<a href="hw://some-app-name:some-publisher.os/optional-path/etcetc">Open App</a>When clicked inside an iframe, it will send:
{
type: 'HW_LINK_CLICKED',
url: '/some-app-name:some-publisher.os/optional-path/etcetc'
}Full TypeScript support included with type definitions for the message format:
interface HWLinkMessage {
type: 'HW_LINK_CLICKED';
url: string;
}MIT