stage-browser 0.0.0-stage → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/README.md +136 -2
  2. package/build/icon.icns +0 -0
  3. package/build/icon.png +0 -0
  4. package/dist/bin/stage.js +111 -0
  5. package/dist/main/cli-args.js +28 -0
  6. package/dist/main/context-menu.js +68 -0
  7. package/dist/main/context.js +2 -0
  8. package/dist/main/extensions.js +78 -0
  9. package/dist/main/ipc.js +90 -0
  10. package/dist/main/main.js +279 -0
  11. package/dist/main/menu.js +140 -0
  12. package/dist/main/reveal.js +155 -0
  13. package/dist/main/selftest.js +490 -0
  14. package/dist/main/store.js +85 -0
  15. package/dist/main/suggest.js +43 -0
  16. package/dist/main/tabs.js +324 -0
  17. package/dist/main/url.js +38 -0
  18. package/dist/main/window.js +68 -0
  19. package/dist/preload/extension-compat.js +163 -0
  20. package/dist/preload/ui-preload.js +33 -0
  21. package/dist/shared/contract.js +6 -0
  22. package/dist/ui/app.js +653 -0
  23. package/dist/ui/index.html +41 -0
  24. package/dist/ui/mock.js +479 -0
  25. package/dist/ui/newtab.html +69 -0
  26. package/dist/ui/styles.css +410 -0
  27. package/node_modules/@types/chrome/LICENSE +21 -0
  28. package/node_modules/@types/chrome/README.md +15 -0
  29. package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
  30. package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
  31. package/node_modules/@types/chrome/index.d.ts +13786 -0
  32. package/node_modules/@types/chrome/package.json +99 -0
  33. package/node_modules/@types/filesystem/LICENSE +21 -0
  34. package/node_modules/@types/filesystem/README.md +15 -0
  35. package/node_modules/@types/filesystem/index.d.ts +564 -0
  36. package/node_modules/@types/filesystem/package.json +26 -0
  37. package/node_modules/@types/filewriter/LICENSE +21 -0
  38. package/node_modules/@types/filewriter/README.md +15 -0
  39. package/node_modules/@types/filewriter/index.d.ts +166 -0
  40. package/node_modules/@types/filewriter/package.json +25 -0
  41. package/node_modules/@types/har-format/LICENSE +21 -0
  42. package/node_modules/@types/har-format/README.md +15 -0
  43. package/node_modules/@types/har-format/index.d.ts +938 -0
  44. package/node_modules/@types/har-format/package.json +31 -0
  45. package/node_modules/adm-zip/LICENSE +21 -0
  46. package/node_modules/adm-zip/README.md +90 -0
  47. package/node_modules/adm-zip/adm-zip.js +1020 -0
  48. package/node_modules/adm-zip/headers/entryHeader.js +396 -0
  49. package/node_modules/adm-zip/headers/index.js +2 -0
  50. package/node_modules/adm-zip/headers/mainHeader.js +177 -0
  51. package/node_modules/adm-zip/methods/deflater.js +33 -0
  52. package/node_modules/adm-zip/methods/index.js +3 -0
  53. package/node_modules/adm-zip/methods/inflater.js +64 -0
  54. package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
  55. package/node_modules/adm-zip/package.json +56 -0
  56. package/node_modules/adm-zip/types.d.ts +223 -0
  57. package/node_modules/adm-zip/util/constants.js +142 -0
  58. package/node_modules/adm-zip/util/decoder.js +5 -0
  59. package/node_modules/adm-zip/util/errors.js +66 -0
  60. package/node_modules/adm-zip/util/fattr.js +76 -0
  61. package/node_modules/adm-zip/util/index.js +5 -0
  62. package/node_modules/adm-zip/util/utils.js +481 -0
  63. package/node_modules/adm-zip/zipEntry.js +415 -0
  64. package/node_modules/adm-zip/zipFile.js +466 -0
  65. package/node_modules/debug/LICENSE +20 -0
  66. package/node_modules/debug/README.md +481 -0
  67. package/node_modules/debug/package.json +64 -0
  68. package/node_modules/debug/src/browser.js +272 -0
  69. package/node_modules/debug/src/common.js +292 -0
  70. package/node_modules/debug/src/index.js +10 -0
  71. package/node_modules/debug/src/node.js +263 -0
  72. package/node_modules/electron-chrome-web-store/README.md +143 -0
  73. package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
  74. package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
  75. package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
  76. package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
  77. package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
  78. package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
  79. package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
  80. package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
  81. package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
  82. package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
  83. package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
  84. package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
  85. package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
  86. package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
  87. package/node_modules/electron-chrome-web-store/package.json +43 -0
  88. package/node_modules/ms/index.js +162 -0
  89. package/node_modules/ms/license.md +21 -0
  90. package/node_modules/ms/package.json +38 -0
  91. package/node_modules/ms/readme.md +59 -0
  92. package/node_modules/pbf/LICENSE +27 -0
  93. package/node_modules/pbf/README.md +293 -0
  94. package/node_modules/pbf/bin/pbf +17 -0
  95. package/node_modules/pbf/compile.js +441 -0
  96. package/node_modules/pbf/dist/pbf-dev.js +838 -0
  97. package/node_modules/pbf/dist/pbf.js +1 -0
  98. package/node_modules/pbf/index.d.ts +206 -0
  99. package/node_modules/pbf/index.js +830 -0
  100. package/node_modules/pbf/package.json +63 -0
  101. package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
  102. package/node_modules/protocol-buffers-schema/LICENSE +21 -0
  103. package/node_modules/protocol-buffers-schema/README.md +122 -0
  104. package/node_modules/protocol-buffers-schema/example.js +11 -0
  105. package/node_modules/protocol-buffers-schema/example.proto +13 -0
  106. package/node_modules/protocol-buffers-schema/index.js +6 -0
  107. package/node_modules/protocol-buffers-schema/package.json +31 -0
  108. package/node_modules/protocol-buffers-schema/parse.js +769 -0
  109. package/node_modules/protocol-buffers-schema/stringify.js +206 -0
  110. package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
  111. package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
  112. package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
  113. package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
  114. package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
  115. package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
  116. package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
  117. package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
  118. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
  119. package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
  120. package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
  121. package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
  122. package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
  123. package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
  124. package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
  125. package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
  126. package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
  127. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
  128. package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
  129. package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
  130. package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
  131. package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
  132. package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
  133. package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
  134. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
  135. package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
  136. package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
  137. package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
  138. package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
  139. package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
  140. package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
  141. package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
  142. package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
  143. package/node_modules/protocol-buffers-schema/test/index.js +157 -0
  144. package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
  145. package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
  146. package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
  147. package/node_modules/resolve-protobuf-schema/README.md +49 -0
  148. package/node_modules/resolve-protobuf-schema/index.js +50 -0
  149. package/node_modules/resolve-protobuf-schema/package.json +25 -0
  150. package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
  151. package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
  152. package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
  153. package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
  154. package/package.json +64 -4
@@ -0,0 +1,490 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.run = run;
4
+ // Scripted self-test: `npm run selftest`. No human input. Writes results.json and PNGs, exits 0 or 1.
5
+ const electron_1 = require("electron");
6
+ const node_fs_1 = require("node:fs");
7
+ const node_os_1 = require("node:os");
8
+ const node_path_1 = require("node:path");
9
+ const cli_args_1 = require("./cli-args");
10
+ const extensions_1 = require("./extensions");
11
+ const store_1 = require("./store");
12
+ const suggest_1 = require("./suggest");
13
+ const tabs_1 = require("./tabs");
14
+ const url_1 = require("./url");
15
+ const OUT = (0, node_path_1.resolve)(process.env.STAGE_SELFTEST_OUT || './selftest-out');
16
+ const OKTA_ID = 'glnpjglilkicbckjpbgcfkogebgllemb';
17
+ const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
18
+ async function waitFor(fn, timeout = 25_000, step = 100) {
19
+ const t0 = Date.now();
20
+ for (;;) {
21
+ const v = await fn();
22
+ if (v)
23
+ return v;
24
+ if (Date.now() - t0 > timeout)
25
+ throw new Error('timeout waiting for condition');
26
+ await sleep(step);
27
+ }
28
+ }
29
+ // Draws PNG layers over each other in a hidden window's canvas; returns base64 PNG.
30
+ async function composite(layers) {
31
+ const win = new electron_1.BrowserWindow({ show: false, webPreferences: { sandbox: true } });
32
+ try {
33
+ await win.loadURL('about:blank');
34
+ const urls = layers.map((img) => img.toDataURL());
35
+ const dataUrl = await win.webContents.executeJavaScript(`(async () => {
36
+ const urls = ${JSON.stringify(urls)};
37
+ const imgs = await Promise.all(urls.map(u => new Promise((res, rej) => { const i = new Image(); i.onload = () => res(i); i.onerror = rej; i.src = u })));
38
+ const c = document.createElement('canvas'); c.width = imgs[0].width; c.height = imgs[0].height;
39
+ const g = c.getContext('2d');
40
+ imgs.forEach(i => g.drawImage(i, 0, 0));
41
+ return c.toDataURL('image/png');
42
+ })()`);
43
+ return dataUrl.replace(/^data:image\/png;base64,/, '');
44
+ }
45
+ finally {
46
+ win.destroy();
47
+ }
48
+ }
49
+ function writeExtension(prefix, manifest, files = {}) {
50
+ const dir = (0, node_fs_1.mkdtempSync)((0, node_path_1.join)((0, node_os_1.tmpdir)(), prefix));
51
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, 'manifest.json'), JSON.stringify(manifest));
52
+ for (const [name, body] of Object.entries(files))
53
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(dir, name), body);
54
+ return dir;
55
+ }
56
+ const loaded = (t) => !t.loading && !!t.url && !!t.title;
57
+ async function run(ctx) {
58
+ (0, node_fs_1.mkdirSync)(OUT, { recursive: true });
59
+ const results = [];
60
+ const uncaught = [];
61
+ ctx.holdQuit = true; // keep the app alive after the close-window check so results get written
62
+ process.on('uncaughtException', (e) => {
63
+ uncaught.push(String(e.stack ?? e));
64
+ console.error('[selftest] uncaughtException', e);
65
+ });
66
+ const check = async (name, fn) => {
67
+ let outcome;
68
+ try {
69
+ outcome = await fn();
70
+ }
71
+ catch (e) {
72
+ outcome = { pass: false, detail: 'threw: ' + (e instanceof Error ? e.message : String(e)) };
73
+ }
74
+ const result = { name, pass: outcome.pass, detail: outcome.detail ?? '' };
75
+ results.push(result);
76
+ console.log(`[selftest] ${result.pass ? 'PASS' : 'FAIL'} ${name} ${result.detail}`);
77
+ };
78
+ const save = (name, data) => (0, node_fs_1.writeFileSync)((0, node_path_1.join)(OUT, name), data);
79
+ const { tabs, reveal, uiView, win } = ctx;
80
+ const ui = uiView.webContents;
81
+ const activeTab = () => {
82
+ const t = tabs.active;
83
+ if (!t)
84
+ throw new Error('no active tab');
85
+ return t;
86
+ };
87
+ const only = (keep) => {
88
+ for (const t of tabs.list.filter((x) => !keep.includes(x)))
89
+ tabs.close(t.id);
90
+ };
91
+ await check('window and UI view exist; new tab page present when empty', async () => {
92
+ tabs.create();
93
+ return { pass: tabs.list.length === 1 && !!tabs.list[0]?.newTab, detail: `newtab.html exists=${(0, node_fs_1.existsSync)(tabs_1.NEWTAB_FILE)}` };
94
+ });
95
+ only([]);
96
+ let t1;
97
+ let t2;
98
+ const openWorkingSet = () => {
99
+ t1 = tabs.create({ url: 'https://example.com', activate: true });
100
+ t2 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Web_browser', activate: false });
101
+ };
102
+ await check('launch with two URLs: both load with title', async () => {
103
+ openWorkingSet();
104
+ await waitFor(() => loaded(t1) && loaded(t2));
105
+ return { pass: /Example Domain/.test(t1.title) && /Web browser/i.test(t2.title), detail: `${t1.title} | ${t2.title}` };
106
+ });
107
+ only([t1, t2]); // drop the fresh tab that replaced the one closed above
108
+ await check('favicon and state pushed (wikipedia)', async () => {
109
+ await waitFor(() => t2.favicon, 15_000).catch(() => { });
110
+ const w = ctx.getState().tabs.find((t) => t.id === t2.id);
111
+ return { pass: !!(w?.favicon && w.title && w.url), detail: `favicon=${w?.favicon}` };
112
+ });
113
+ await check('user agent has no Electron/Stage token', async () => {
114
+ const ua = await t1.wc.executeJavaScript('navigator.userAgent');
115
+ const bad = /Electron|stage-browser|Stage\//i;
116
+ return { pass: !bad.test(ua) && !bad.test(ctx.session.getUserAgent()), detail: ua };
117
+ });
118
+ await check('url resolution cases', async () => {
119
+ const cases = [
120
+ ['https://a.com/x', 'https://a.com/x'],
121
+ ['example.com', 'https://example.com'],
122
+ ['example.com/path?q=1', 'https://example.com/path?q=1'],
123
+ ['localhost:3000', 'http://localhost:3000'],
124
+ ['127.0.0.1:8080/a', 'http://127.0.0.1:8080/a'],
125
+ ['localhost', 'http://localhost'],
126
+ ['about:blank', 'about:blank'],
127
+ ['hello world', 'https://www.google.com/search?q=hello%20world'],
128
+ ['stage', 'https://www.google.com/search?q=stage'],
129
+ ['what is 3.5', 'https://www.google.com/search?q=what%20is%203.5'],
130
+ ['zoommtg://x', 'zoommtg://x'],
131
+ ];
132
+ const bad = cases.filter(([i, o]) => (0, url_1.resolveInput)(i) !== o).map(([i, o]) => `${i} -> ${(0, url_1.resolveInput)(i)} (want ${o})`);
133
+ return { pass: bad.length === 0, detail: bad.join('; ') };
134
+ });
135
+ await check('cli-args parsing', async () => {
136
+ const a = (0, cli_args_1.parseArgs)(['electron', '.', '--inspect=1', '--size', '1280x720', 'a.com', '--pin', '--fresh', 'hello world']);
137
+ return { pass: a.pin && a.fresh && a.size?.width === 1280 && a.size.height === 720 && a.urls.join('|') === 'a.com|hello world', detail: JSON.stringify(a) };
138
+ });
139
+ await check('activate / close / reopen closed tab', async () => {
140
+ tabs.activate(t1.id);
141
+ const ok1 = ctx.getState().activeTabId === t1.id && t1.view.getVisible() && !t2.view.getVisible();
142
+ const url2 = t2.url;
143
+ tabs.close(t2.id);
144
+ const ok2 = tabs.list.length === 1;
145
+ tabs.reopenClosed();
146
+ await sleep(200);
147
+ const reopened = tabs.list.find((x) => x.id !== t1.id);
148
+ if (!reopened)
149
+ return { pass: false, detail: 'nothing reopened' };
150
+ t2 = reopened;
151
+ const ok3 = tabs.list.length === 2 && tabs.activeId === t2.id;
152
+ await waitFor(() => loaded(t2));
153
+ return { pass: ok1 && ok2 && ok3 && t2.url === url2, detail: `visibleOnlyActive=${ok1} closed=${ok2} reopened=${ok3} url=${t2.url}` };
154
+ });
155
+ await check('closing the last tab leaves a new-tab page', async () => {
156
+ const t = tabs.create({ url: 'about:blank' });
157
+ only([t]);
158
+ await sleep(100);
159
+ const single = tabs.list.length === 1;
160
+ tabs.close(t.id);
161
+ await sleep(300);
162
+ const newTab = tabs.list.length === 1 && !!tabs.list[0]?.newTab;
163
+ const placeholder = tabs.list[0];
164
+ openWorkingSet();
165
+ if (placeholder)
166
+ tabs.close(placeholder.id);
167
+ await waitFor(() => loaded(t1) && loaded(t2));
168
+ tabs.activate(t1.id);
169
+ return { pass: single && newTab, detail: `single=${single} newtab=${newTab}` };
170
+ });
171
+ await check("suggest('wiki') returns open tab + history", async () => {
172
+ const t3 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Google_Chrome', activate: false });
173
+ await waitFor(() => loaded(t3));
174
+ tabs.close(t3.id);
175
+ const s = (0, suggest_1.suggest)(tabs.list, 'wiki');
176
+ const okTab = s.some((x) => x.kind === 'tab' && x.tabId === t2.id);
177
+ const okHist = s.some((x) => x.kind === 'history' && /Google_Chrome/.test(x.url));
178
+ return { pass: s[0]?.kind === 'search' && okTab && okHist && s.length <= 8, detail: JSON.stringify(s.map((x) => [x.kind, x.url])) };
179
+ });
180
+ await check('suggest: url and search first items', async () => {
181
+ const a = (0, suggest_1.suggest)(tabs.list, 'example.org')[0];
182
+ const b = (0, suggest_1.suggest)(tabs.list, 'two words')[0];
183
+ return { pass: a?.kind === 'url' && a.url === 'https://example.org' && b?.kind === 'search', detail: `${a?.kind} ${b?.kind}` };
184
+ });
185
+ const shot = async (name) => {
186
+ const page = await activeTab().wc.capturePage();
187
+ const bar = await ui.capturePage();
188
+ save(`${name.replace('composite', 'page')}.png`, page.toPNG());
189
+ save(`${name.replace('composite', 'ui')}.png`, bar.toPNG());
190
+ save(`${name}.png`, Buffer.from(await composite([page, bar]), 'base64'));
191
+ return { page: page.getSize(), ui: bar.getSize() };
192
+ };
193
+ await check('reveal bar: state pushed visible, view shown, composite captured', async () => {
194
+ reveal.setHover(true); // the real cursor is elsewhere; keep the poller from hiding the bar
195
+ reveal.show();
196
+ await sleep(1200);
197
+ const sizes = await shot('bar-composite');
198
+ reveal.setHover(false);
199
+ return { pass: ctx.bar.visible && uiView.getVisible() && sizes.ui.height > 0, detail: JSON.stringify(sizes) };
200
+ });
201
+ await check('omnibox overlay: full-size UI view, composite captured', async () => {
202
+ reveal.openOverlay('new', '');
203
+ await sleep(800);
204
+ await ui
205
+ .executeJavaScript(`(() => { const i = document.querySelector('input'); if (i) { i.focus(); i.value = 'wiki'; i.dispatchEvent(new Event('input', { bubbles: true })) } return !!i })()`)
206
+ .catch(() => { });
207
+ await sleep(900);
208
+ const [w, h] = win.getContentSize();
209
+ const b = uiView.getBounds();
210
+ const sizes = await shot('omnibox-composite');
211
+ reveal.closeOverlay();
212
+ return { pass: b.width === w && b.height === h && !ctx.overlay, detail: JSON.stringify({ b, sizes }) };
213
+ });
214
+ await check('pin: tab view bounds start at y=52; unpin: y=0', async () => {
215
+ reveal.setPinned(true);
216
+ const pinned = activeTab().view.getBounds();
217
+ const [, ch = 0] = win.getContentSize();
218
+ reveal.setPinned(false);
219
+ const y2 = activeTab().view.getBounds().y;
220
+ return { pass: pinned.y === 52 && pinned.height === ch - 52 && y2 === 0, detail: `pinned y=${pinned.y} h=${pinned.height}/${ch}, unpinned y=${y2}` };
221
+ });
222
+ await check('hide: state false, UI view invisible after timeout', async () => {
223
+ reveal.hide();
224
+ const stateFalse = !ctx.bar.visible;
225
+ await sleep(500);
226
+ return { pass: stateFalse && !uiView.getVisible(), detail: `uiVisible=${uiView.getVisible()}` };
227
+ });
228
+ await check('floating bar has room for its shadow; clicks under the strip reach the page', async () => {
229
+ const page = 'data:text/html,' +
230
+ encodeURIComponent('<body style="margin:0"><button style="position:absolute;left:300px;top:55px;width:240px;height:14px" onclick="window.clicked=(window.clicked||0)+1">x</button></body>');
231
+ reveal.closeOverlay();
232
+ reveal.setPinned(false);
233
+ const tab = tabs.create({ url: page, activate: true });
234
+ await waitFor(() => !tab.loading && tab.url.startsWith('data:'));
235
+ reveal.show();
236
+ await sleep(400);
237
+ const floatH = uiView.getBounds().height;
238
+ for (const type of ['mouseDown', 'mouseUp'])
239
+ ui.sendInputEvent({ type, x: 420, y: 62, button: 'left', clickCount: 1 });
240
+ const clicked = await waitFor(() => tab.wc.executeJavaScript('window.clicked || 0'), 3000).catch(() => 0);
241
+ const hidden = !ctx.bar.visible && !uiView.getVisible();
242
+ reveal.setPinned(true);
243
+ await sleep(100);
244
+ const pinnedH = uiView.getBounds().height;
245
+ reveal.setPinned(false);
246
+ reveal.hide();
247
+ tabs.close(tab.id);
248
+ return { pass: floatH === 72 && clicked === 1 && hidden && pinnedH === 52, detail: JSON.stringify({ floatH, clicked, hidden, pinnedH }) };
249
+ });
250
+ await check('extension icons: shown with a button extension, hidden by the menu option, gone with none installed', async () => {
251
+ const dir = writeExtension('stage-action-ext-', { manifest_version: 3, name: 'Stage action probe', version: '1.0', action: { default_title: 'Probe' } });
252
+ const probe = await ctx.session.extensions.loadExtension(dir);
253
+ const controlsShown = () => ui.executeJavaScript("document.getElementById('controls').checkVisibility()");
254
+ reveal.show();
255
+ await sleep(400);
256
+ const withExt = await controlsShown();
257
+ ctx.setHideExtensionIcons(true);
258
+ await sleep(250);
259
+ const hiddenByOption = !(await controlsShown());
260
+ const item = electron_1.Menu.getApplicationMenu()
261
+ ?.items.find((i) => i.label === 'Extensions')
262
+ ?.submenu?.items.find((i) => i.label === 'Hide Icons in Tab Bar');
263
+ const checked = !!item?.checked;
264
+ const saved = (0, store_1.readPrefs)().hideExtensionIcons;
265
+ ctx.setHideExtensionIcons(false);
266
+ await sleep(250);
267
+ const back = await controlsShown();
268
+ ctx.session.extensions.removeExtension(probe.id);
269
+ await sleep(400);
270
+ const goneWithNone = !(await controlsShown());
271
+ const noPinButton = await ui.executeJavaScript("!document.getElementById('pin')");
272
+ reveal.hide();
273
+ const r = { withExt, hiddenByOption, checked, saved, back, goneWithNone, noPinButton };
274
+ return { pass: Object.values(r).every(Boolean), detail: JSON.stringify(r) };
275
+ });
276
+ await check('UI view stays topmost after adding tabs', async () => {
277
+ tabs.create({ url: 'about:blank', activate: false });
278
+ const kids = win.contentView.children;
279
+ return { pass: kids.at(-1) === uiView, detail: `children=${kids.length}` };
280
+ });
281
+ await check('content size 1280x720 sets and centers', async () => {
282
+ win.setContentSize(1280, 720);
283
+ win.center();
284
+ const [w, h] = win.getContentSize();
285
+ return { pass: w === 1280 && h === 720, detail: `${w}x${h}` };
286
+ });
287
+ await check('external scheme from page opens via shell, not in tab', async () => {
288
+ const original = electron_1.shell.openExternal;
289
+ let called = '';
290
+ electron_1.shell.openExternal = async (url) => {
291
+ called = url;
292
+ };
293
+ try {
294
+ const r = tabs.openHandler({
295
+ url: 'zoommtg://zoom.us/join?x=1',
296
+ frameName: '',
297
+ features: '',
298
+ disposition: 'foreground-tab',
299
+ referrer: { url: '', policy: 'default' },
300
+ });
301
+ return { pass: r.action === 'deny' && called.startsWith('zoommtg:'), detail: called };
302
+ }
303
+ finally {
304
+ electron_1.shell.openExternal = original;
305
+ }
306
+ });
307
+ // Real clicks, so Electron's own window-open path runs (not just openHandler's return value).
308
+ const LINKS_PAGE = 'data:text/html,' +
309
+ encodeURIComponent('<a id="blank" target="_blank" href="https://example.com/?from=blank">blank</a>' +
310
+ '<script>window.openWithOpener = () => { const w = window.open("about:blank"); return !!w && !w.closed && w.opener === window }</script>');
311
+ const openLinksPage = async () => {
312
+ const src = tabs.create({ url: LINKS_PAGE, activate: true });
313
+ await waitFor(() => !src.loading && src.url.startsWith('data:'));
314
+ return src;
315
+ };
316
+ await check('target=_blank link opens the URL in a new active tab', async () => {
317
+ const errorsBefore = uncaught.length;
318
+ const src = await openLinksPage();
319
+ const before = tabs.list.length;
320
+ await src.wc.executeJavaScript('document.getElementById("blank").click()', true);
321
+ const t = await waitFor(() => tabs.list.length === before + 1 && tabs.list.find((x) => x.url.includes('from=blank')), 15_000);
322
+ const ok = tabs.activeId === t.id && uncaught.length === errorsBefore;
323
+ tabs.close(t.id);
324
+ tabs.close(src.id);
325
+ return { pass: ok, detail: t.url };
326
+ });
327
+ await check('window.open() opens a tab that keeps window.opener', async () => {
328
+ const errorsBefore = uncaught.length;
329
+ const src = await openLinksPage();
330
+ const before = tabs.list.length;
331
+ const hasOpener = await src.wc.executeJavaScript('window.openWithOpener()', true);
332
+ await waitFor(() => tabs.list.length === before + 1, 5000);
333
+ const t = tabs.list.find((x) => x.id !== src.id && x.id === tabs.activeId);
334
+ if (t)
335
+ tabs.close(t.id);
336
+ tabs.close(src.id);
337
+ const clean = uncaught.length === errorsBefore;
338
+ return { pass: hasOpener && !!t && clean, detail: `opener=${hasOpener} tabs=${tabs.list.length} uncaught=${!clean}` };
339
+ });
340
+ // Opt-in compatibility suite against a real extension from the Web Store. The app itself
341
+ // installs nothing. STAGE_SELFTEST_EXT_ID=<web store id> targets any other extension.
342
+ if (process.env.STAGE_SELFTEST_OKTA || process.env.STAGE_SELFTEST_EXT_ID) {
343
+ const extId = process.env.STAGE_SELFTEST_EXT_ID || OKTA_ID;
344
+ // Console output from every extension page and service worker, recorded from before the
345
+ // install so startup errors are caught.
346
+ const diag = { pageConsole: [], swConsole: [], swRunning: null, popupDom: null };
347
+ electron_1.app.on('web-contents-created', (_e, wc) => {
348
+ wc.on('console-message', (ev) => {
349
+ const url = wc.isDestroyed() ? '' : wc.getURL();
350
+ if (url.startsWith('chrome-extension://'))
351
+ diag.pageConsole.push(`[${ev.level}] ${url.split('/').slice(3).join('/')}: ${ev.message} (${ev.sourceId}:${ev.lineNumber})`);
352
+ });
353
+ });
354
+ ctx.session.serviceWorkers.on('console-message', (_e, d) => {
355
+ diag.swConsole.push(`[${d.level}] ${d.message} (${d.sourceUrl}:${d.lineNumber})`);
356
+ });
357
+ const heard = (marker) => diag.swConsole.filter((l) => l.includes(marker)).length;
358
+ await check(`extension ${extId} installs from the Web Store`, async () => {
359
+ await (0, extensions_1.install)(ctx.session, extId);
360
+ const list = (0, extensions_1.installed)(ctx.session);
361
+ return { pass: list.some((e) => e.id === extId), detail: JSON.stringify(list) };
362
+ });
363
+ await check('extension responds to its toolbar button (popup or page)', async () => {
364
+ tabs.activate(t1.id);
365
+ reveal.setHover(true);
366
+ reveal.show();
367
+ await sleep(2500);
368
+ const desc = await ui.executeJavaScript(`(() => {
369
+ const l = document.querySelector('browser-action-list'); if (!l) return 'no element';
370
+ const r = l.shadowRoot; const btns = r ? r.querySelectorAll('button, .action, [part]') : [];
371
+ return 'buttons=' + btns.length + ' html=' + (r ? r.innerHTML.slice(0, 300) : 'no shadow')
372
+ })()`);
373
+ await shot('ext-bar-composite').catch(() => { }); // screenshots need an awake display; the check doesn't
374
+ let popupInfo = 'not attempted';
375
+ const tabsBefore = new Set(tabs.list.map((t) => t.id));
376
+ const popupCreated = new Promise((res) => ctx.ext.once('browser-action-popup-created', (p) => res(p)));
377
+ await ui.executeJavaScript(`(() => {
378
+ const l = document.querySelector('browser-action-list'); const b = l && l.shadowRoot && l.shadowRoot.querySelector('button, .action');
379
+ if (b) b.click(); return !!b })()`);
380
+ const popup = await Promise.race([popupCreated, sleep(6000).then(() => null)]);
381
+ let opened = false;
382
+ const bw = popup && (await popup.whenReady().catch(() => { }), await sleep(4000), popup.browserWindow);
383
+ if (popup && bw && !bw.isDestroyed()) {
384
+ opened = true;
385
+ diag.popupDom = await bw.webContents
386
+ .executeJavaScript(`(() => {
387
+ const t = (o) => typeof o
388
+ const c = window.chrome || {}
389
+ return {
390
+ readyState: document.readyState,
391
+ contentHtmlLength: (document.getElementById('content') || {}).innerHTML?.length,
392
+ bodyText: document.body.innerText.slice(0, 300),
393
+ apis: {
394
+ 'runtime.sendMessage': t(c.runtime && c.runtime.sendMessage), 'storage.local': t(c.storage && c.storage.local),
395
+ 'storage.session': t(c.storage && c.storage.session), 'tabs.query': t(c.tabs && c.tabs.query),
396
+ scripting: t(c.scripting), declarativeNetRequest: t(c.declarativeNetRequest), webRequest: t(c.webRequest),
397
+ cookies: t(c.cookies), i18n: t(c.i18n), permissions: t(c.permissions), privacy: t(c.privacy),
398
+ windows: t(c.windows), action: t(c.action), alarms: t(c.alarms), idle: t(c.idle), management: t(c.management),
399
+ downloads: t(c.downloads), offscreen: t(c.offscreen), contextMenus: t(c.contextMenus), notifications: t(c.notifications),
400
+ 'runtime.connectNative': t(c.runtime && c.runtime.connectNative), 'runtime.sendNativeMessage': t(c.runtime && c.runtime.sendNativeMessage),
401
+ identity: t(c.identity), commands: t(c.commands), sidePanel: t(c.sidePanel), 'privacy.services': t(c.privacy && c.privacy.services),
402
+ },
403
+ }
404
+ })()`)
405
+ .catch((e) => 'executeJavaScript failed: ' + e.message);
406
+ diag.swRunning = Object.values(ctx.session.serviceWorkers.getAllRunning()).map((w) => w.scriptUrl);
407
+ await bw.webContents
408
+ .capturePage()
409
+ .then((img) => save('ext-popup.png', img.toPNG()))
410
+ .catch(() => { });
411
+ popupInfo = 'popup url=' + bw.webContents.getURL() + ' revealHeld=' + ctx.popupOpen;
412
+ popup.destroy();
413
+ }
414
+ // An extension may answer a click by opening a page instead (1Password does on first run).
415
+ if (!popup)
416
+ await sleep(3000);
417
+ const newTabs = tabs.list.filter((t) => !tabsBefore.has(t.id));
418
+ diag.newTabsAfterClick = newTabs.map((t) => (t.wc.isDestroyed() ? '' : t.wc.getURL()));
419
+ for (const t of newTabs) {
420
+ await waitFor(() => !t.loading, 10_000).catch(() => { });
421
+ await t.wc
422
+ .capturePage()
423
+ .then((img) => save('ext-click-tab.png', img.toPNG()))
424
+ .catch(() => { });
425
+ diag.newTabText = await t.wc.executeJavaScript('document.body ? document.body.innerText.slice(0, 300) : ""').catch(() => '');
426
+ }
427
+ save('ext-diag.json', JSON.stringify(diag, null, 2));
428
+ const dom = diag.popupDom;
429
+ const popupText = dom && typeof dom === 'object' && 'bodyText' in dom ? String(dom.bodyText) : '';
430
+ const respondedWithPage = newTabs.length > 0 && !!diag.newTabText;
431
+ return {
432
+ pass: (opened && !!popupText) || respondedWithPage,
433
+ detail: [desc.slice(0, 40), popupInfo, 'popup text: ' + JSON.stringify(popupText), 'new tabs: ' + JSON.stringify(diag.newTabsAfterClick) + ' ' + JSON.stringify((diag.newTabText ?? '').slice(0, 80))].join(' | '),
434
+ };
435
+ });
436
+ // Okta injects its autofill scripts with chrome.scripting.executeScript from its service worker.
437
+ await check('extension service worker can inject a script into the active tab', async () => {
438
+ const dir = writeExtension('stage-probe-ext-', { manifest_version: 3, name: 'Stage probe', version: '1.0', permissions: ['scripting', 'tabs'], host_permissions: ['<all_urls>'], background: { service_worker: 'sw.js' } }, {
439
+ 'sw.js': `
440
+ chrome.tabs.query({ active: true }).then(([tab]) =>
441
+ chrome.scripting.executeScript({ target: { tabId: tab.id }, func: () => 'PROBE:' + document.title })
442
+ ).then((r) => console.log(r[0].result)).catch((e) => console.log('PROBE-ERR:' + e.message))`,
443
+ });
444
+ tabs.activate(t1.id);
445
+ await ctx.session.extensions.loadExtension(dir);
446
+ const line = await waitFor(() => diag.swConsole.find((l) => l.includes('PROBE')), 10_000).catch(() => null);
447
+ return { pass: !!line?.includes('PROBE:Example Domain'), detail: line ?? 'no probe output' };
448
+ });
449
+ // Regression: a tracker iframe whose URL contains a UUID made Okta take over the tab, because
450
+ // webNavigation URL filters were ignored.
451
+ const UUID_IFRAME_PAGE = 'data:text/html,' + encodeURIComponent('<h1>host</h1><iframe src="https://example.com/?id=11111111-2222-4333-8444-555555555555"></iframe>');
452
+ await check('webNavigation URL filters: listeners hear only matching URLs', async () => {
453
+ const dir = writeExtension('stage-navfilter-ext-', { manifest_version: 3, name: 'Stage nav filter probe', version: '1.0', permissions: ['webNavigation'], host_permissions: ['<all_urls>'], background: { service_worker: 'sw.js' } }, {
454
+ 'sw.js': `
455
+ const oktaLike = '^https://personal\\\\.okta\\\\.com/okta-personal-app/([0-9a-f-]{36})/launch'
456
+ chrome.webNavigation.onBeforeNavigate.addListener((d) => console.log('NAVOKTA:' + d.url), { url: [{ urlMatches: oktaLike }] })
457
+ chrome.webNavigation.onBeforeNavigate.addListener((d) => console.log('NAVORG:' + d.url), { url: [{ hostEquals: 'example.org' }] })
458
+ chrome.webNavigation.onBeforeNavigate.addListener((d) => { if (d.url.includes('11111111-2222')) console.log('NAVALL:' + d.url) })`,
459
+ });
460
+ await ctx.session.extensions.loadExtension(dir);
461
+ await sleep(1000);
462
+ const tab = tabs.create({ url: UUID_IFRAME_PAGE, activate: true });
463
+ await waitFor(() => heard('NAVALL:') > 0, 10_000).catch(() => { });
464
+ tab.wc.loadURL('https://example.org/').catch(() => { });
465
+ await waitFor(() => heard('NAVORG:') > 0, 10_000).catch(() => { });
466
+ tabs.close(tab.id);
467
+ const ok = heard('NAVALL:') > 0 && heard('NAVOKTA:') === 0 && heard('NAVORG:') > 0 && heard('NAVORG:https://example.com') === 0;
468
+ return { pass: ok, detail: `unfiltered=${heard('NAVALL:')} oktaPattern=${heard('NAVOKTA:')} example.org=${heard('NAVORG:')}` };
469
+ });
470
+ await check('Okta does not take over a tab when an iframe URL contains a UUID', async () => {
471
+ const tab = tabs.create({ url: UUID_IFRAME_PAGE, activate: true });
472
+ await waitFor(() => !tab.loading && tab.url.startsWith('data:'), 10_000).catch(() => { });
473
+ await sleep(4000); // the takeover ran within about a second of the iframe navigating
474
+ const url = tab.wc.isDestroyed() ? '(destroyed)' : tab.wc.getURL();
475
+ tabs.close(tab.id);
476
+ return { pass: !url.startsWith('chrome-extension://'), detail: url.slice(0, 120) };
477
+ });
478
+ }
479
+ await check('closing the window with a push pending does not throw', async () => {
480
+ ctx.push();
481
+ win.close();
482
+ await sleep(800); // give the push, poll, save and hide timers a chance to fire
483
+ return { pass: uncaught.length === 0 && ctx.quitting && win.isDestroyed(), detail: uncaught.join(' | ').slice(0, 400) };
484
+ });
485
+ const failed = results.filter((r) => !r.pass).length;
486
+ (0, node_fs_1.writeFileSync)((0, node_path_1.join)(OUT, 'results.json'), JSON.stringify({ passed: results.length - failed, failed, results }, null, 2));
487
+ console.log(`[selftest] ${results.length - failed}/${results.length} passed -> ${OUT}`);
488
+ ctx.quitting = true;
489
+ electron_1.app.exit(failed ? 1 : 0);
490
+ }
@@ -0,0 +1,85 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.writeSession = exports.readSession = exports.writePrefs = exports.readPrefs = void 0;
4
+ exports.addVisit = addVisit;
5
+ exports.setHistoryTitle = setHistoryTitle;
6
+ exports.flushHistory = flushHistory;
7
+ exports.historyEntries = historyEntries;
8
+ const electron_1 = require("electron");
9
+ const node_fs_1 = require("node:fs");
10
+ const node_path_1 = require("node:path");
11
+ const file = (name) => (0, node_path_1.join)(electron_1.app.getPath('userData'), name);
12
+ function readJson(name, fallback) {
13
+ try {
14
+ return JSON.parse((0, node_fs_1.readFileSync)(file(name), 'utf8'));
15
+ }
16
+ catch {
17
+ return fallback;
18
+ }
19
+ }
20
+ function writeJson(name, data) {
21
+ try {
22
+ (0, node_fs_1.mkdirSync)(electron_1.app.getPath('userData'), { recursive: true });
23
+ const tmp = file(name) + '.tmp';
24
+ (0, node_fs_1.writeFileSync)(tmp, JSON.stringify(data));
25
+ (0, node_fs_1.renameSync)(tmp, file(name));
26
+ }
27
+ catch (e) {
28
+ console.error('[stage] write failed', name, e);
29
+ }
30
+ }
31
+ const readPrefs = () => ({ hideExtensionIcons: false, ...readJson('prefs.json', {}) });
32
+ exports.readPrefs = readPrefs;
33
+ const writePrefs = (prefs) => writeJson('prefs.json', prefs);
34
+ exports.writePrefs = writePrefs;
35
+ const readSession = () => readJson('session.json', {});
36
+ exports.readSession = readSession;
37
+ const writeSession = (session) => writeJson('session.json', session);
38
+ exports.writeSession = writeSession;
39
+ const HISTORY_CAP = 2000;
40
+ let history = null;
41
+ let historyTimer;
42
+ function loadHistory() {
43
+ if (history)
44
+ return history;
45
+ history = new Map();
46
+ for (const h of readJson('history.json', []))
47
+ if (h?.url)
48
+ history.set(h.url, h);
49
+ return history;
50
+ }
51
+ function addVisit(url, title) {
52
+ const h = loadHistory();
53
+ const e = h.get(url) ?? { url, title: '', visits: 0, last: 0 };
54
+ e.visits++;
55
+ e.last = Date.now();
56
+ if (title)
57
+ e.title = title;
58
+ h.delete(url);
59
+ h.set(url, e);
60
+ if (h.size > HISTORY_CAP) {
61
+ const recent = [...h.values()].sort((a, b) => b.last - a.last).slice(0, HISTORY_CAP);
62
+ history = new Map(recent.map((x) => [x.url, x]));
63
+ }
64
+ scheduleHistorySave();
65
+ }
66
+ function setHistoryTitle(url, title) {
67
+ const e = loadHistory().get(url);
68
+ if (e && title && e.title !== title) {
69
+ e.title = title;
70
+ scheduleHistorySave();
71
+ }
72
+ }
73
+ function scheduleHistorySave() {
74
+ clearTimeout(historyTimer);
75
+ historyTimer = setTimeout(flushHistory, 2000);
76
+ }
77
+ function flushHistory() {
78
+ clearTimeout(historyTimer);
79
+ historyTimer = undefined;
80
+ if (history)
81
+ writeJson('history.json', [...history.values()]);
82
+ }
83
+ function historyEntries() {
84
+ return [...loadHistory().values()];
85
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.suggest = suggest;
4
+ const store_1 = require("./store");
5
+ const url_1 = require("./url");
6
+ const MAX = 8;
7
+ const DAY_MS = 86_400_000;
8
+ function suggest(tabs, query) {
9
+ const q = query.trim();
10
+ const words = q.toLowerCase().split(/\s+/).filter(Boolean);
11
+ const matches = (s) => {
12
+ const l = s.toLowerCase();
13
+ return words.every((w) => l.includes(w));
14
+ };
15
+ const out = [];
16
+ const seen = new Set();
17
+ const first = (0, url_1.classify)(q);
18
+ if (first) {
19
+ out.push({ kind: first.kind, title: first.kind === 'search' ? `Search Google for “${q}”` : first.url, url: first.url, favicon: null });
20
+ seen.add(first.url);
21
+ }
22
+ for (const t of tabs) {
23
+ if (out.length >= MAX)
24
+ break;
25
+ if (!t.url || (words.length && !matches(`${t.title} ${t.url}`)))
26
+ continue;
27
+ out.push({ kind: 'tab', title: t.title || t.url, url: t.url, tabId: t.id, favicon: t.favicon });
28
+ seen.add(t.url);
29
+ }
30
+ if (words.length) {
31
+ const now = Date.now();
32
+ const scored = (0, store_1.historyEntries)()
33
+ .filter((h) => !seen.has(h.url) && matches(`${h.title} ${h.url}`))
34
+ .map((h) => ({ h, score: h.visits + Math.max(0, 7 - (now - h.last) / DAY_MS) }))
35
+ .sort((a, b) => b.score - a.score);
36
+ for (const { h } of scored) {
37
+ if (out.length >= MAX)
38
+ break;
39
+ out.push({ kind: 'history', title: h.title || h.url, url: h.url, favicon: null });
40
+ }
41
+ }
42
+ return out.slice(0, MAX);
43
+ }