experiments in a post-browser web
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <meta http-equiv="Content-Security-Policy" content="script-src 'self' 'unsafe-inline';">
6 <title>Groups Extension</title>
7</head>
8<body>
9<script type="module">
10 import extension from './background.js';
11
12 const api = window.app;
13 const extId = extension.id;
14
15 console.log(`[ext:${extId}] background.html loaded`);
16
17 // Initialize extension BEFORE publishing ext:ready
18 // (commands must be registered before lazy stub re-publishes)
19 if (extension.init) {
20 console.log(`[ext:${extId}] calling init()`);
21 await extension.init();
22 }
23
24 // Collect registered command topics for assertion verification
25 const registeredTopics = Object.keys(window._cmdHandlers || {})
26 .map(name => `cmd:execute:${name}`);
27
28 // Signal ready to main process
29 api.publish('ext:ready', {
30 id: extId,
31 registeredTopics,
32 manifest: {
33 id: extension.id,
34 labels: extension.labels,
35 version: '1.0.0'
36 }
37 }, api.scopes.SYSTEM);
38
39 // Handle shutdown request from main process
40 api.subscribe('app:shutdown', () => {
41 console.log(`[ext:${extId}] received shutdown`);
42 if (extension.uninit) {
43 extension.uninit();
44 }
45 }, api.scopes.SYSTEM);
46
47 // Handle extension-specific shutdown
48 api.subscribe(`ext:${extId}:shutdown`, () => {
49 console.log(`[ext:${extId}] received extension shutdown`);
50 if (extension.uninit) {
51 extension.uninit();
52 }
53 }, api.scopes.SYSTEM);
54</script>
55</body>
56</html>