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,324 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Tabs = exports.NEWTAB_FILE = void 0;
4
+ const electron_1 = require("electron");
5
+ const node_path_1 = require("node:path");
6
+ const context_menu_1 = require("./context-menu");
7
+ const store_1 = require("./store");
8
+ const url_1 = require("./url");
9
+ const window_1 = require("./window");
10
+ exports.NEWTAB_FILE = (0, node_path_1.join)(__dirname, '..', 'ui', 'newtab.html');
11
+ const CLOSED_CAP = 25;
12
+ const WEB_SCHEMES = new Set(['http:', 'https:', 'file:', 'about:', 'data:', 'blob:', 'chrome-extension:', 'view-source:', 'devtools:', 'chrome:', 'javascript:']);
13
+ function isExternal(url) {
14
+ const scheme = /^([a-z][a-z0-9+.-]*:)/i.exec(url)?.[1]?.toLowerCase();
15
+ return !!scheme && !WEB_SCHEMES.has(scheme);
16
+ }
17
+ function openExternal(url) {
18
+ electron_1.shell.openExternal(url).catch(() => { });
19
+ }
20
+ class Tabs {
21
+ list = [];
22
+ activeId = null;
23
+ ctx;
24
+ closed = [];
25
+ constructor(ctx) {
26
+ this.ctx = ctx;
27
+ }
28
+ get(id) {
29
+ return this.list.find((t) => t.id === id);
30
+ }
31
+ get active() {
32
+ return this.list.find((t) => t.id === this.activeId);
33
+ }
34
+ create(opts = {}) {
35
+ const { ctx } = this;
36
+ const view = opts.webContents
37
+ ? new electron_1.WebContentsView({ webContents: opts.webContents })
38
+ : new electron_1.WebContentsView({ webPreferences: { session: ctx.session, sandbox: true, contextIsolation: true, nodeIntegration: false } });
39
+ view.setBackgroundColor((0, window_1.bgColor)());
40
+ const wc = view.webContents;
41
+ const tab = { id: wc.id, view, wc, title: '', url: '', favicon: null, loading: false, audible: false, muted: false, newTab: false };
42
+ this.list.splice(opts.index ?? this.list.length, 0, tab);
43
+ ctx.win.contentView.addChildView(view, 0); // the UI view stays on top
44
+ view.setBounds(ctx.tabBounds());
45
+ view.setVisible(false);
46
+ this.wire(tab);
47
+ ctx.ext.addTab(wc, ctx.win);
48
+ if (!opts.webContents) {
49
+ if (opts.url)
50
+ this.load(tab, opts.url);
51
+ else
52
+ this.loadNewTab(tab);
53
+ }
54
+ if (opts.activate !== false)
55
+ this.activate(tab.id);
56
+ else
57
+ ctx.push();
58
+ return tab;
59
+ }
60
+ loadNewTab(tab) {
61
+ tab.newTab = true;
62
+ tab.wc.loadFile(exports.NEWTAB_FILE).catch(() => { });
63
+ }
64
+ load(tab, url) {
65
+ tab.newTab = false;
66
+ tab.wc.loadURL(url).catch(() => { }); // failures arrive through did-fail-load
67
+ }
68
+ wire(tab) {
69
+ const { wc } = tab;
70
+ const push = () => this.ctx.push();
71
+ const syncUrl = () => {
72
+ const u = wc.getURL();
73
+ tab.newTab = u.startsWith('file://') && decodeURI(u).endsWith('/ui/newtab.html');
74
+ tab.url = tab.newTab ? '' : u;
75
+ };
76
+ const guardExternal = (e, url) => {
77
+ if (!isExternal(url))
78
+ return;
79
+ e.preventDefault();
80
+ openExternal(url);
81
+ };
82
+ wc.on('page-title-updated', (_e, title) => {
83
+ tab.title = title;
84
+ if ((0, url_1.isWebUrl)(tab.url))
85
+ (0, store_1.setHistoryTitle)(tab.url, title);
86
+ push();
87
+ });
88
+ wc.on('page-favicon-updated', (_e, favicons) => {
89
+ tab.favicon = favicons[0] ?? null;
90
+ push();
91
+ });
92
+ wc.on('did-start-navigation', (e) => {
93
+ if (e.isMainFrame && !e.isSameDocument)
94
+ tab.favicon = null;
95
+ });
96
+ wc.on('did-start-loading', () => {
97
+ tab.loading = true;
98
+ push();
99
+ });
100
+ wc.on('did-stop-loading', () => {
101
+ tab.loading = false;
102
+ syncUrl();
103
+ if (!tab.title && tab.url)
104
+ tab.title = tab.url;
105
+ push();
106
+ });
107
+ wc.on('did-navigate', (_e, url) => {
108
+ syncUrl();
109
+ if ((0, url_1.isWebUrl)(url))
110
+ (0, store_1.addVisit)(url, wc.getTitle());
111
+ this.ctx.saveSession();
112
+ push();
113
+ });
114
+ wc.on('did-navigate-in-page', (_e, _url, isMainFrame) => {
115
+ if (!isMainFrame)
116
+ return;
117
+ syncUrl();
118
+ this.ctx.saveSession();
119
+ push();
120
+ });
121
+ wc.on('audio-state-changed', (e) => {
122
+ tab.audible = e.audible;
123
+ push();
124
+ });
125
+ wc.on('zoom-changed', push);
126
+ wc.on('did-fail-load', (_e, code, _desc, _url, isMainFrame) => {
127
+ if (!isMainFrame || code === -3)
128
+ return;
129
+ syncUrl();
130
+ push();
131
+ });
132
+ wc.on('destroyed', () => this.removeDead(tab));
133
+ wc.on('context-menu', (_e, params) => (0, context_menu_1.showPageMenu)(this.ctx, tab, params));
134
+ wc.on('will-navigate', guardExternal);
135
+ wc.on('will-redirect', guardExternal);
136
+ wc.setWindowOpenHandler((d) => this.openHandler(d));
137
+ }
138
+ openHandler({ url, disposition }) {
139
+ if (isExternal(url)) {
140
+ openExternal(url);
141
+ return { action: 'deny' };
142
+ }
143
+ if (disposition === 'new-window') {
144
+ return {
145
+ action: 'allow',
146
+ overrideBrowserWindowOptions: { autoHideMenuBar: true, backgroundColor: (0, window_1.bgColor)(), webPreferences: { sandbox: true, contextIsolation: true } },
147
+ };
148
+ }
149
+ return {
150
+ action: 'allow',
151
+ createWindow: ({ webContents }) => this.create({
152
+ webContents,
153
+ url: webContents ? undefined : url,
154
+ activate: disposition !== 'background-tab',
155
+ index: this.insertIndexAfterActive(),
156
+ }).wc,
157
+ };
158
+ }
159
+ insertIndexAfterActive() {
160
+ const i = this.list.findIndex((t) => t.id === this.activeId);
161
+ return i < 0 ? this.list.length : i + 1;
162
+ }
163
+ activate(id) {
164
+ const tab = this.get(id);
165
+ if (!tab)
166
+ return;
167
+ this.activeId = id;
168
+ for (const t of this.list)
169
+ t.view.setVisible(t === tab);
170
+ tab.view.setBounds(this.ctx.tabBounds());
171
+ this.ctx.ext.selectTab(tab.wc);
172
+ if (!this.ctx.overlay)
173
+ tab.wc.focus();
174
+ this.ctx.saveSession();
175
+ this.ctx.push();
176
+ }
177
+ focusActive() {
178
+ const t = this.active;
179
+ if (t && !t.wc.isDestroyed())
180
+ t.wc.focus();
181
+ }
182
+ close(id) {
183
+ const tab = this.get(id);
184
+ if (!tab)
185
+ return;
186
+ if ((0, url_1.isWebUrl)(tab.url))
187
+ this.closed.push(tab.url);
188
+ if (this.closed.length > CLOSED_CAP)
189
+ this.closed.shift();
190
+ this.removeFromList(tab);
191
+ this.detach(tab);
192
+ try {
193
+ this.ctx.ext.removeTab(tab.wc);
194
+ }
195
+ catch { }
196
+ if (!tab.wc.isDestroyed())
197
+ tab.wc.close();
198
+ }
199
+ // The webContents went away on its own: window.close() or crash cleanup.
200
+ removeDead(tab) {
201
+ if (!this.get(tab.id))
202
+ return;
203
+ this.removeFromList(tab);
204
+ this.detach(tab);
205
+ }
206
+ detach(tab) {
207
+ try {
208
+ this.ctx.win.contentView.removeChildView(tab.view);
209
+ }
210
+ catch { }
211
+ }
212
+ removeFromList(tab) {
213
+ const i = this.list.indexOf(tab);
214
+ if (i < 0)
215
+ return;
216
+ this.list.splice(i, 1);
217
+ if (this.ctx.quitting)
218
+ return;
219
+ const next = this.list[Math.min(i, this.list.length - 1)];
220
+ if (!next)
221
+ this.create();
222
+ else if (this.activeId === tab.id)
223
+ this.activate(next.id);
224
+ else {
225
+ this.ctx.saveSession();
226
+ this.ctx.push();
227
+ }
228
+ }
229
+ closeOthers(id) {
230
+ for (const t of this.list.filter((x) => x.id !== id))
231
+ this.close(t.id);
232
+ }
233
+ closeRight(id) {
234
+ const i = this.list.findIndex((t) => t.id === id);
235
+ for (const t of this.list.slice(i + 1))
236
+ this.close(t.id);
237
+ }
238
+ reopenClosed() {
239
+ const url = this.closed.pop();
240
+ if (url)
241
+ this.create({ url });
242
+ }
243
+ duplicate(id) {
244
+ const t = this.get(id);
245
+ if (!t)
246
+ return;
247
+ this.create({ url: t.url || undefined, index: this.list.indexOf(t) + 1 });
248
+ }
249
+ move(id, toIndex) {
250
+ const from = this.list.findIndex((t) => t.id === id);
251
+ if (from < 0)
252
+ return;
253
+ const [t] = this.list.splice(from, 1);
254
+ if (!t)
255
+ return;
256
+ this.list.splice(Math.max(0, Math.min(toIndex, this.list.length)), 0, t);
257
+ this.ctx.saveSession();
258
+ this.ctx.push();
259
+ }
260
+ step(delta) {
261
+ const n = this.list.length;
262
+ if (n < 2)
263
+ return;
264
+ const i = this.list.findIndex((t) => t.id === this.activeId);
265
+ const t = this.list[(i + delta + n) % n];
266
+ if (t)
267
+ this.activate(t.id);
268
+ }
269
+ // 1-based; 9 means the last tab.
270
+ goTo(n) {
271
+ const t = n === 9 ? this.list.at(-1) : this.list[n - 1];
272
+ if (t)
273
+ this.activate(t.id);
274
+ }
275
+ toggleMute(id) {
276
+ const t = this.get(id);
277
+ if (!t)
278
+ return;
279
+ t.muted = !t.muted;
280
+ t.wc.setAudioMuted(t.muted);
281
+ this.ctx.push();
282
+ }
283
+ open(url, { newTab }) {
284
+ const t = this.active;
285
+ if (newTab || !t)
286
+ return this.create({ url, index: this.insertIndexAfterActive() });
287
+ this.load(t, url);
288
+ this.activate(t.id);
289
+ return t;
290
+ }
291
+ layout() {
292
+ const b = this.ctx.tabBounds();
293
+ for (const t of this.list)
294
+ t.view.setBounds(b);
295
+ }
296
+ zoom(delta) {
297
+ const t = this.active;
298
+ if (!t)
299
+ return;
300
+ const f = delta === 0 ? 1 : Math.min(5, Math.max(0.25, Math.round((t.wc.getZoomFactor() + delta) * 100) / 100));
301
+ t.wc.setZoomFactor(f);
302
+ this.ctx.push();
303
+ }
304
+ snapshot() {
305
+ const a = this.active;
306
+ const live = a && !a.wc.isDestroyed() ? a.wc : null;
307
+ return {
308
+ tabs: this.list.map((t) => ({
309
+ id: t.id,
310
+ title: t.newTab ? 'New Tab' : t.title || t.url || 'Untitled',
311
+ url: t.url,
312
+ favicon: t.favicon,
313
+ loading: t.loading,
314
+ audible: t.audible,
315
+ muted: t.muted,
316
+ })),
317
+ activeTabId: this.activeId,
318
+ canGoBack: !!live && live.navigationHistory.canGoBack(),
319
+ canGoForward: !!live && live.navigationHistory.canGoForward(),
320
+ zoomFactor: live ? live.getZoomFactor() : 1,
321
+ };
322
+ }
323
+ }
324
+ exports.Tabs = Tabs;
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.searchUrl = searchUrl;
4
+ exports.resolveInput = resolveInput;
5
+ exports.classify = classify;
6
+ exports.isWebUrl = isWebUrl;
7
+ const SCHEME_SLASHES = /^[a-z][a-z0-9+.-]*:\/\//i;
8
+ const SCHEME_BARE = /^(about|data|mailto|view-source|blob|chrome-extension|file):/i;
9
+ const LOCAL = /^(localhost|\[[0-9a-f:]+\]|\d{1,3}(\.\d{1,3}){3})(:\d+)?([/?#].*)?$/i;
10
+ const DOTTED = /^[^\s/?#:]+\.[a-z][a-z0-9-]*(:\d+)?([/?#]\S*)?$/i;
11
+ const SEARCH_PREFIX = 'https://www.google.com/search?q=';
12
+ function searchUrl(query) {
13
+ return SEARCH_PREFIX + encodeURIComponent(query);
14
+ }
15
+ function resolveInput(input) {
16
+ const s = input.trim();
17
+ if (!s)
18
+ return null;
19
+ if (SCHEME_SLASHES.test(s) || SCHEME_BARE.test(s))
20
+ return s;
21
+ if (!/\s/.test(s)) {
22
+ if (LOCAL.test(s))
23
+ return 'http://' + s;
24
+ if (DOTTED.test(s))
25
+ return 'https://' + s;
26
+ }
27
+ return searchUrl(s);
28
+ }
29
+ function classify(input) {
30
+ const s = input.trim();
31
+ const url = resolveInput(s);
32
+ if (url === null)
33
+ return null;
34
+ return { url, kind: url.startsWith(SEARCH_PREFIX) && !s.startsWith('http') ? 'search' : 'url' };
35
+ }
36
+ function isWebUrl(url) {
37
+ return /^https?:\/\//i.test(url);
38
+ }
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BAR_HEIGHT = void 0;
4
+ exports.bgColor = bgColor;
5
+ exports.createWindow = createWindow;
6
+ exports.tabBounds = tabBounds;
7
+ exports.uiBounds = uiBounds;
8
+ const electron_1 = require("electron");
9
+ const node_path_1 = require("node:path");
10
+ exports.BAR_HEIGHT = 52;
11
+ // Transparent room under the floating bar so the capsule's shadow isn't clipped. Clicks in it are
12
+ // passed to the page. Not used when pinned: the page then starts right under the strip.
13
+ const SHADOW_ROOM = 20;
14
+ const TRAFFIC_LIGHTS = { x: 20, y: 19 };
15
+ const EMPTY = { x: 0, y: 0, width: 0, height: 0 };
16
+ function bgColor() {
17
+ return electron_1.nativeTheme.shouldUseDarkColors ? '#1c1c1e' : '#ffffff';
18
+ }
19
+ function initialBounds(saved) {
20
+ if (!saved?.width || !saved.height)
21
+ return { width: 1280, height: 800 };
22
+ const onScreen = electron_1.screen.getAllDisplays().some(({ workArea: a }) => {
23
+ return saved.x < a.x + a.width - 40 && saved.x + saved.width > a.x + 40 && saved.y >= a.y - 10 && saved.y < a.y + a.height - 40;
24
+ });
25
+ return onScreen ? saved : { width: saved.width, height: saved.height };
26
+ }
27
+ function createWindow(saved, size) {
28
+ const win = new electron_1.BaseWindow({
29
+ ...initialBounds(saved),
30
+ useContentSize: size !== null,
31
+ minWidth: 480,
32
+ minHeight: 320,
33
+ show: false,
34
+ titleBarStyle: 'hidden',
35
+ trafficLightPosition: TRAFFIC_LIGHTS,
36
+ backgroundColor: bgColor(),
37
+ });
38
+ if (size) {
39
+ win.setContentSize(size.width, size.height);
40
+ win.center();
41
+ }
42
+ win.setWindowButtonVisibility(false);
43
+ const uiView = new electron_1.WebContentsView({
44
+ webPreferences: {
45
+ // Non-persistent: it only serves the local UI. Extension icons load over crx://.
46
+ session: electron_1.session.fromPartition('stage-ui'),
47
+ preload: (0, node_path_1.join)(__dirname, '..', 'preload', 'ui-preload.js'),
48
+ contextIsolation: true,
49
+ sandbox: false,
50
+ nodeIntegration: false,
51
+ },
52
+ });
53
+ uiView.setBackgroundColor('#00000000');
54
+ uiView.setVisible(false);
55
+ win.contentView.addChildView(uiView);
56
+ return { win, uiView };
57
+ }
58
+ function tabBounds(win, pinned) {
59
+ if (win.isDestroyed())
60
+ return EMPTY;
61
+ const [w = 0, h = 0] = win.getContentSize();
62
+ const top = pinned ? exports.BAR_HEIGHT : 0;
63
+ return { x: 0, y: top, width: w, height: Math.max(0, h - top) };
64
+ }
65
+ function uiBounds(win, pinned, overlay) {
66
+ const [w = 0, h = 0] = win.getContentSize();
67
+ return { x: 0, y: 0, width: w, height: overlay ? h : pinned ? exports.BAR_HEIGHT : exports.BAR_HEIGHT + SHADOW_ROOM };
68
+ }
@@ -0,0 +1,163 @@
1
+ "use strict";
2
+ // Fills gaps between electron-chrome-extensions and real Chrome. Runs after the library's own
3
+ // preload, in extension pages and service workers only.
4
+ //
5
+ // 1. Constants the library leaves undefined (chrome.tabs.TAB_ID_NONE and friends). The Okta
6
+ // Browser Plugin builds a declarativeNetRequest rule with `tabIds: [chrome.tabs.TAB_ID_NONE]`;
7
+ // left undefined, its service worker throws at startup and its popup renders blank.
8
+ //
9
+ // 2. URL filters on chrome.webNavigation events. The library ignores the second argument of
10
+ // addListener, so a listener meant for one URL pattern hears every navigation, iframes
11
+ // included. Okta listens for Okta Personal app-launch URLs this way; without the filter, any
12
+ // tracker iframe whose URL contains a UUID made it take over the tab and show "Sign in Error".
13
+ //
14
+ // A script, not a module: sandboxed and service-worker preloads have no `exports`.
15
+ {
16
+ const { contextBridge } = require('electron');
17
+ // Serialized into the extension's main world, so everything it uses must live inside it.
18
+ const patchExtensionApis = () => {
19
+ const g = globalThis;
20
+ const c = g.chrome;
21
+ if (!c)
22
+ return;
23
+ const define = (target, key, value) => {
24
+ if (!target || typeof target !== 'object' || target[key] !== undefined)
25
+ return;
26
+ try {
27
+ Object.defineProperty(target, key, { value, enumerable: true });
28
+ }
29
+ catch { }
30
+ };
31
+ define(c.tabs, 'TAB_ID_NONE', -1);
32
+ define(c.tabs, 'TAB_INDEX_NONE', -1);
33
+ define(c.tabs, 'MAX_CAPTURE_VISIBLE_TAB_CALLS_PER_SECOND', 2);
34
+ define(c.windows, 'WINDOW_ID_NONE', -1);
35
+ define(c.windows, 'WINDOW_ID_CURRENT', -2);
36
+ // Chrome exposes `browser` as the same object as `chrome`. Electron has its own, smaller
37
+ // `browser` without the APIs the library adds. 1Password reads `browser.windows.WINDOW_ID_NONE`
38
+ // at startup, so its service worker crashed and its popup spun forever.
39
+ if (g.browser !== c) {
40
+ try {
41
+ Object.defineProperty(globalThis, 'browser', { value: c, configurable: true, writable: true });
42
+ }
43
+ catch {
44
+ const b = g.browser;
45
+ if (b) {
46
+ for (const key of Object.keys(c)) {
47
+ if (b[key] === c[key])
48
+ continue;
49
+ try {
50
+ Object.defineProperty(b, key, { value: c[key], configurable: true, writable: true, enumerable: true });
51
+ }
52
+ catch { }
53
+ }
54
+ }
55
+ }
56
+ }
57
+ // chrome.events.UrlFilter: every condition in one filter must hold; any filter in the list may match.
58
+ const DEFAULT_PORTS = { 'http:': 80, 'https:': 443, 'ws:': 80, 'wss:': 443, 'ftp:': 21 };
59
+ const regexCache = new Map();
60
+ const regex = (source) => {
61
+ if (!regexCache.has(source)) {
62
+ let re = null;
63
+ try {
64
+ re = new RegExp(source);
65
+ }
66
+ catch { }
67
+ regexCache.set(source, re);
68
+ }
69
+ return regexCache.get(source) ?? null;
70
+ };
71
+ const matchesFilter = (rawUrl, filter) => {
72
+ let u;
73
+ try {
74
+ u = new URL(rawUrl);
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ u.hash = '';
80
+ const url = u.href; // the URL parser already drops default ports
81
+ const host = u.hostname;
82
+ const path = u.pathname;
83
+ const query = u.search.replace(/^\?/, '');
84
+ const port = u.port ? Number(u.port) : DEFAULT_PORTS[u.protocol];
85
+ const checks = {
86
+ hostContains: (v) => ('.' + host).includes(v),
87
+ hostEquals: (v) => host === v,
88
+ hostPrefix: (v) => host.startsWith(v),
89
+ hostSuffix: (v) => host.endsWith(v),
90
+ pathContains: (v) => path.includes(v),
91
+ pathEquals: (v) => path === v,
92
+ pathPrefix: (v) => path.startsWith(v),
93
+ pathSuffix: (v) => path.endsWith(v),
94
+ queryContains: (v) => query.includes(v),
95
+ queryEquals: (v) => query === v,
96
+ queryPrefix: (v) => query.startsWith(v),
97
+ querySuffix: (v) => query.endsWith(v),
98
+ urlContains: (v) => url.includes(v),
99
+ urlEquals: (v) => url === v,
100
+ urlPrefix: (v) => url.startsWith(v),
101
+ urlSuffix: (v) => url.endsWith(v),
102
+ urlMatches: (v) => !!regex(v)?.test(url),
103
+ originAndPathMatches: (v) => !!regex(v)?.test(u.origin + path),
104
+ schemes: (v) => Array.isArray(v) && v.includes(u.protocol.replace(/:$/, '')),
105
+ ports: (v) => Array.isArray(v) && port !== undefined && v.some((p) => (Array.isArray(p) ? port >= p[0] && port <= p[1] : port === p)),
106
+ };
107
+ const lookup = checks;
108
+ return Object.entries(filter).every(([key, value]) => lookup[key]?.(value) ?? true);
109
+ };
110
+ const passes = (details, filter) => {
111
+ const list = Array.isArray(filter?.url) ? filter.url : null;
112
+ if (!list?.length)
113
+ return true;
114
+ const url = details && typeof details === 'object' ? details.url : undefined;
115
+ return typeof url === 'string' && list.some((f) => matchesFilter(url, f));
116
+ };
117
+ const nav = c.webNavigation;
118
+ if (!nav)
119
+ return;
120
+ for (const ev of Object.values(nav)) {
121
+ if (!ev || typeof ev.addListener !== 'function' || ev.__stageFiltered)
122
+ continue;
123
+ const add = ev.addListener.bind(ev);
124
+ const remove = ev.removeListener.bind(ev);
125
+ const wrappers = new Map();
126
+ try {
127
+ Object.defineProperties(ev, {
128
+ __stageFiltered: { value: true },
129
+ addListener: {
130
+ value(callback, filter) {
131
+ if (typeof callback !== 'function' || wrappers.has(callback))
132
+ return;
133
+ const wrapper = (details, ...rest) => (passes(details, filter) ? callback(details, ...rest) : undefined);
134
+ wrappers.set(callback, wrapper);
135
+ add(wrapper);
136
+ },
137
+ },
138
+ removeListener: {
139
+ value(callback) {
140
+ const wrapper = wrappers.get(callback);
141
+ if (!wrapper)
142
+ return;
143
+ wrappers.delete(callback);
144
+ remove(wrapper);
145
+ },
146
+ },
147
+ hasListener: { value: (callback) => wrappers.has(callback) },
148
+ hasListeners: { value: () => wrappers.size > 0 },
149
+ });
150
+ }
151
+ catch { }
152
+ }
153
+ };
154
+ const isExtensionContext = process.type === 'service-worker' || (typeof location !== 'undefined' && location.href.startsWith('chrome-extension://'));
155
+ if (isExtensionContext) {
156
+ try {
157
+ contextBridge.executeInMainWorld({ func: patchExtensionApis });
158
+ }
159
+ catch (e) {
160
+ console.error('[stage] extension-compat preload failed', e);
161
+ }
162
+ }
163
+ }
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ // Preload for the overlay UI view (sandbox: false, contextIsolation: true).
4
+ const electron_1 = require("electron");
5
+ const browser_action_1 = require("electron-chrome-extensions/browser-action");
6
+ const contract_1 = require("../shared/contract");
7
+ (0, browser_action_1.injectBrowserAction)(); // the <browser-action-list> element for extension icons
8
+ const command = (name) => (...args) => electron_1.ipcRenderer.send((0, contract_1.channel)(name), ...args);
9
+ const query = (name) => (...args) => electron_1.ipcRenderer.invoke((0, contract_1.channel)(name), ...args);
10
+ const api = {
11
+ getState: query('getState'),
12
+ suggest: query('suggest'),
13
+ onState(listener) {
14
+ const handler = (_e, state) => listener(state);
15
+ electron_1.ipcRenderer.on((0, contract_1.channel)('state'), handler);
16
+ return () => electron_1.ipcRenderer.removeListener((0, contract_1.channel)('state'), handler);
17
+ },
18
+ activateTab: command('activateTab'),
19
+ closeTab: command('closeTab'),
20
+ moveTab: command('moveTab'),
21
+ showTabMenu: command('showTabMenu'),
22
+ openOmnibox: command('openOmnibox'),
23
+ closeOverlay: command('closeOverlay'),
24
+ submitOmnibox: command('submitOmnibox'),
25
+ back: command('back'),
26
+ forward: command('forward'),
27
+ reload: command('reload'),
28
+ setBarHover: command('setBarHover'),
29
+ passClick: command('passClick'),
30
+ startWindowDrag: command('startWindowDrag'),
31
+ endWindowDrag: command('endWindowDrag'),
32
+ };
33
+ electron_1.contextBridge.exposeInMainWorld('stage', api);
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ // The interface between the main process and the overlay UI. See docs/CONTRACT.md.
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.channel = void 0;
5
+ const channel = (name) => `stage:${name}`;
6
+ exports.channel = channel;