stage-browser 0.1.0 → 0.2.0

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 (172) hide show
  1. package/README.md +92 -45
  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 +73 -0
  10. package/dist/main/main.js +282 -0
  11. package/dist/main/menu.js +140 -0
  12. package/dist/main/reveal.js +170 -0
  13. package/dist/main/selftest.js +570 -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/ui-window.js +133 -0
  18. package/dist/main/url.js +38 -0
  19. package/dist/main/window.js +133 -0
  20. package/dist/preload/extension-compat.js +163 -0
  21. package/dist/preload/ui-preload.js +34 -0
  22. package/dist/shared/contract.js +6 -0
  23. package/dist/ui/app.js +692 -0
  24. package/{src → dist}/ui/index.html +15 -5
  25. package/dist/ui/mock.js +500 -0
  26. package/{src → dist}/ui/styles.css +55 -14
  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 +35 -11
  155. package/bin/stage.js +0 -52
  156. package/src/main/cli-args.js +0 -28
  157. package/src/main/context-menu.js +0 -64
  158. package/src/main/extensions.js +0 -61
  159. package/src/main/main.js +0 -310
  160. package/src/main/menu.js +0 -171
  161. package/src/main/reveal.js +0 -141
  162. package/src/main/selftest.js +0 -383
  163. package/src/main/store.js +0 -77
  164. package/src/main/suggest.js +0 -50
  165. package/src/main/tabs.js +0 -351
  166. package/src/main/url.js +0 -37
  167. package/src/main/window.js +0 -71
  168. package/src/preload/extension-compat.js +0 -34
  169. package/src/preload/ui-preload.js +0 -40
  170. package/src/ui/app.js +0 -588
  171. package/src/ui/mock.js +0 -455
  172. /package/{src → dist}/ui/newtab.html +0 -0
@@ -1,383 +0,0 @@
1
- 'use strict'
2
- // Scripted self-test: `npm run selftest`. No human input. Writes results.json + PNGs, exits 0/1.
3
- const fs = require('fs')
4
- const path = require('path')
5
- const { app, BrowserWindow } = require('electron')
6
- const { resolveInput } = require('./url')
7
- const { parseArgs } = require('./cli-args')
8
- const { suggest } = require('./suggest')
9
- const extensions = require('./extensions')
10
- const { NEWTAB_FILE } = require('./tabs')
11
-
12
- const OUT = path.resolve(process.env.STAGE_SELFTEST_OUT || './selftest-out')
13
- const sleep = (ms) => new Promise((r) => setTimeout(r, ms))
14
-
15
- async function waitFor(fn, timeout = 25000, step = 100) {
16
- const t0 = Date.now()
17
- for (;;) {
18
- const v = await fn()
19
- if (v) return v
20
- if (Date.now() - t0 > timeout) throw new Error('timeout waiting for condition')
21
- await sleep(step)
22
- }
23
- }
24
-
25
- async function composite(layers, w, h) {
26
- // draw PNG layers on top of each other in a hidden window's canvas
27
- const win = new BrowserWindow({ show: false, webPreferences: { sandbox: true } })
28
- try {
29
- await win.loadURL('about:blank')
30
- const urls = layers.map((img) => img.toDataURL())
31
- const dataUrl = await win.webContents.executeJavaScript(`(async () => {
32
- const urls = ${JSON.stringify(urls)};
33
- 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 })));
34
- const c = document.createElement('canvas'); c.width = imgs[0].width; c.height = imgs[0].height;
35
- const g = c.getContext('2d');
36
- imgs.forEach(i => g.drawImage(i, 0, 0));
37
- return c.toDataURL('image/png');
38
- })()`)
39
- return dataUrl.replace(/^data:image\/png;base64,/, '')
40
- } finally {
41
- win.destroy()
42
- }
43
- }
44
-
45
- async function run(ctx) {
46
- fs.mkdirSync(OUT, { recursive: true })
47
- const results = []
48
- const uncaught = []
49
- ctx.holdQuit = true // keep the app alive after the close-window check so results get written
50
- process.on('uncaughtException', (e) => {
51
- uncaught.push(String((e && e.stack) || e))
52
- console.error('[selftest] uncaughtException', e)
53
- })
54
- const check = async (name, fn) => {
55
- let pass = false
56
- let detail = ''
57
- try {
58
- const r = await fn()
59
- pass = r === undefined || r === true || (r && r.pass !== false)
60
- detail = r && typeof r === 'object' ? r.detail || '' : typeof r === 'string' ? r : ''
61
- if (typeof r === 'string') pass = true
62
- } catch (e) {
63
- detail = 'threw: ' + (e && e.message)
64
- }
65
- results.push({ name, pass, detail })
66
- console.log(`[selftest] ${pass ? 'PASS' : 'FAIL'} ${name} ${detail}`)
67
- }
68
- const save = (name, buf) => fs.writeFileSync(path.join(OUT, name), buf)
69
- const loaded = (t) => !t.loading && t.url && t.title
70
- const { tabs, reveal } = ctx
71
-
72
- await check('window and UI view exist; new tab page present when empty', async () => {
73
- tabs.create({})
74
- return { pass: tabs.list.length === 1 && tabs.list[0].newTab, detail: `newtab.html exists=${fs.existsSync(NEWTAB_FILE)}` }
75
- })
76
- tabs.close(tabs.list[0].id)
77
-
78
- let t1, t2
79
- await check('launch with two URLs: both load with title', async () => {
80
- t1 = tabs.create({ url: 'https://example.com', activate: true })
81
- t2 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Web_browser', activate: false })
82
- await waitFor(() => loaded(t1) && loaded(t2))
83
- return { pass: /Example Domain/.test(t1.title) && /Web browser/i.test(t2.title), detail: `${t1.title} | ${t2.title}` }
84
- })
85
- // the empty tab we closed first was replaced by a fresh one; drop it
86
- for (const t of [...tabs.list]) if (t !== t1 && t !== t2) tabs.close(t.id)
87
-
88
- await check('favicon and state pushed (wikipedia)', async () => {
89
- await waitFor(() => t2.favicon, 15000).catch(() => {})
90
- const s = ctx.getState()
91
- const w = s.tabs.find((t) => t.id === t2.id)
92
- return { pass: !!(w && w.favicon && w.title && w.url), detail: `favicon=${w && w.favicon}` }
93
- })
94
-
95
- await check('user agent has no Electron/Stage token', async () => {
96
- const ua = await t1.wc.executeJavaScript('navigator.userAgent')
97
- const hdr = ctx.session.getUserAgent()
98
- const bad = /Electron|stage-browser|Stage\//i
99
- return { pass: !bad.test(ua) && !bad.test(hdr), detail: ua }
100
- })
101
-
102
- await check('url.js resolution cases', async () => {
103
- const cases = [
104
- ['https://a.com/x', 'https://a.com/x'],
105
- ['example.com', 'https://example.com'],
106
- ['example.com/path?q=1', 'https://example.com/path?q=1'],
107
- ['localhost:3000', 'http://localhost:3000'],
108
- ['127.0.0.1:8080/a', 'http://127.0.0.1:8080/a'],
109
- ['localhost', 'http://localhost'],
110
- ['about:blank', 'about:blank'],
111
- ['hello world', 'https://www.google.com/search?q=hello%20world'],
112
- ['stage', 'https://www.google.com/search?q=stage'],
113
- ['what is 3.5', 'https://www.google.com/search?q=what%20is%203.5'],
114
- ['zoommtg://x', 'zoommtg://x'],
115
- ]
116
- const bad = cases.filter(([i, o]) => resolveInput(i) !== o).map(([i, o]) => `${i} -> ${resolveInput(i)} (want ${o})`)
117
- return { pass: bad.length === 0, detail: bad.join('; ') }
118
- })
119
-
120
- await check('cli-args parsing', async () => {
121
- const a = parseArgs(['electron', '.', '--inspect=1', '--size', '1280x720', 'a.com', '--pin', '--fresh', 'hello world'])
122
- 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) }
123
- })
124
-
125
- await check('activate / close / reopen closed tab', async () => {
126
- tabs.activate(t1.id)
127
- const ok1 = ctx.getState().activeTabId === t1.id && t1.view.getVisible() && !t2.view.getVisible()
128
- const url2 = t2.url
129
- tabs.close(t2.id)
130
- const ok2 = tabs.list.length === 1
131
- tabs.reopenClosed()
132
- await sleep(200)
133
- const t = tabs.active
134
- t2 = tabs.list.find((x) => x.id !== t1.id)
135
- const ok3 = tabs.list.length === 2 && t.id === t2.id
136
- await waitFor(() => loaded(t2))
137
- return { pass: ok1 && ok2 && ok3 && t2.url === url2, detail: `visibleOnlyActive=${ok1} closed=${ok2} reopened=${ok3} url=${t2.url}` }
138
- })
139
-
140
- await check('closing the last tab leaves a new-tab page', async () => {
141
- const t = tabs.create({ url: 'about:blank' })
142
- for (const x of [...tabs.list]) if (x !== t) tabs.close(x.id)
143
- await sleep(100)
144
- const ok = tabs.list.length === 1
145
- tabs.close(t.id)
146
- await sleep(300)
147
- const nt = tabs.list.length === 1 && tabs.list[0].newTab
148
- // restore the working set
149
- t1 = tabs.create({ url: 'https://example.com' })
150
- t2 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Web_browser', activate: false })
151
- tabs.close(tabs.list[0].id)
152
- await waitFor(() => loaded(t1) && loaded(t2))
153
- tabs.activate(t1.id)
154
- return { pass: ok && nt, detail: `single=${ok} newtab=${nt}` }
155
- })
156
-
157
- await check("suggest('wiki') returns open tab + history", async () => {
158
- const t3 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Google_Chrome', activate: false })
159
- await waitFor(() => loaded(t3))
160
- tabs.close(t3.id)
161
- const s = suggest(ctx, 'wiki')
162
- const kinds = s.map((x) => x.kind)
163
- const okTab = s.some((x) => x.kind === 'tab' && x.tabId === t2.id)
164
- const okHist = s.some((x) => x.kind === 'history' && /Google_Chrome/.test(x.url))
165
- return { pass: s[0].kind === 'search' && okTab && okHist && s.length <= 8, detail: JSON.stringify(s.map((x) => [x.kind, x.url])) }
166
- })
167
-
168
- await check('suggest: url and search first items', async () => {
169
- const a = suggest(ctx, 'example.org')[0]
170
- const b = suggest(ctx, 'two words')[0]
171
- return { pass: a.kind === 'url' && a.url === 'https://example.org' && b.kind === 'search', detail: `${a.kind} ${b.kind}` }
172
- })
173
-
174
- const shot = async (name) => {
175
- const page = await tabs.active.wc.capturePage()
176
- const ui = await ctx.uiView.webContents.capturePage()
177
- save(`${name.replace('composite', 'page')}.png`, page.toPNG())
178
- save(`${name.replace('composite', 'ui')}.png`, ui.toPNG())
179
- const b64 = await composite([page, ui])
180
- save(`${name}.png`, Buffer.from(b64, 'base64'))
181
- return { page: page.getSize(), ui: ui.getSize() }
182
- }
183
-
184
- await check('reveal bar: state pushed visible, view shown, composite captured', async () => {
185
- reveal.setHover(true) // the real cursor is elsewhere; keep the poller from hiding the bar
186
- reveal.show()
187
- await sleep(1200)
188
- const sizes = await shot('bar-composite')
189
- reveal.setHover(false)
190
- return { pass: ctx.bar.visible && ctx.uiView.getVisible() && sizes.ui.height > 0, detail: JSON.stringify(sizes) }
191
- })
192
-
193
- await check('omnibox overlay: full-size UI view, composite captured', async () => {
194
- reveal.openOverlay('new', '')
195
- await sleep(800)
196
- await ctx.uiView.webContents.executeJavaScript(`(() => { const i = document.querySelector('input'); if (i) { i.focus(); i.value = 'wiki'; i.dispatchEvent(new Event('input', { bubbles: true })) } return !!i })()`).catch(() => {})
197
- await sleep(900)
198
- const [w, h] = ctx.win.getContentSize()
199
- const b = ctx.uiView.getBounds()
200
- const sizes = await shot('omnibox-composite')
201
- reveal.closeOverlay()
202
- return { pass: b.width === w && b.height === h && !ctx.overlay, detail: JSON.stringify({ b, sizes }) }
203
- })
204
-
205
- await check('pin: tab view bounds start at y=52; unpin: y=0', async () => {
206
- reveal.setPinned(true)
207
- const y1 = tabs.active.view.getBounds().y
208
- const h1 = tabs.active.view.getBounds().height
209
- const [, ch] = ctx.win.getContentSize()
210
- reveal.setPinned(false)
211
- const y2 = tabs.active.view.getBounds().y
212
- return { pass: y1 === 52 && h1 === ch - 52 && y2 === 0, detail: `pinned y=${y1} h=${h1}/${ch}, unpinned y=${y2}` }
213
- })
214
-
215
- await check('hide: state false, UI view invisible after timeout', async () => {
216
- reveal.hide()
217
- const stateFalse = !ctx.bar.visible
218
- await sleep(500)
219
- return { pass: stateFalse && !ctx.uiView.getVisible(), detail: `uiVisible=${ctx.uiView.getVisible()}` }
220
- })
221
-
222
- await check('UI view stays topmost after adding tabs', async () => {
223
- tabs.create({ url: 'about:blank', activate: false })
224
- const kids = ctx.win.contentView.children
225
- return { pass: kids[kids.length - 1] === ctx.uiView, detail: `children=${kids.length}` }
226
- })
227
-
228
- await check('content size 1280x720 sets and centers', async () => {
229
- ctx.win.setContentSize(1280, 720)
230
- ctx.win.center()
231
- const [w, h] = ctx.win.getContentSize()
232
- return { pass: w === 1280 && h === 720, detail: `${w}x${h}` }
233
- })
234
-
235
- await check('external scheme from page opens via shell, not in tab', async () => {
236
- const orig = require('electron').shell.openExternal
237
- let called = ''
238
- require('electron').shell.openExternal = async (u) => { called = u }
239
- const r = tabs.openHandler({ url: 'zoommtg://zoom.us/join?x=1', disposition: 'foreground-tab', features: '' })
240
- require('electron').shell.openExternal = orig
241
- return { pass: r.action === 'deny' && called.startsWith('zoommtg:'), detail: called }
242
- })
243
-
244
- // Real clicks, so Electron's own window-open path runs (not just openHandler's return value).
245
- const LINKS_PAGE =
246
- 'data:text/html,' +
247
- encodeURIComponent(
248
- '<a id="blank" target="_blank" href="https://example.com/?from=blank">blank</a>' +
249
- '<script>window.openWithOpener = () => { const w = window.open("about:blank"); return !!w && !w.closed && w.opener === window }</script>'
250
- )
251
-
252
- await check('target=_blank link opens the URL in a new active tab', async () => {
253
- const errorsBefore = uncaught.length
254
- const src = tabs.create({ url: LINKS_PAGE, activate: true })
255
- await waitFor(() => !src.loading && src.url.startsWith('data:'))
256
- const before = tabs.list.length
257
- await src.wc.executeJavaScript('document.getElementById("blank").click()', true)
258
- const t = await waitFor(() => tabs.list.length === before + 1 && tabs.list.find((x) => x.url.includes('from=blank')), 15000)
259
- const ok = tabs.activeId === t.id && uncaught.length === errorsBefore
260
- tabs.close(t.id)
261
- tabs.close(src.id)
262
- return { pass: ok, detail: t.url }
263
- })
264
-
265
- await check('window.open() opens a tab that keeps window.opener', async () => {
266
- const errorsBefore = uncaught.length
267
- const src = tabs.create({ url: LINKS_PAGE, activate: true })
268
- await waitFor(() => !src.loading && src.url.startsWith('data:'))
269
- const before = tabs.list.length
270
- const hasOpener = await src.wc.executeJavaScript('window.openWithOpener()', true)
271
- await waitFor(() => tabs.list.length === before + 1, 5000)
272
- const t = tabs.list.find((x) => x.id !== src.id && x.id === tabs.activeId)
273
- if (t) tabs.close(t.id)
274
- tabs.close(src.id)
275
- const clean = uncaught.length === errorsBefore
276
- return { pass: hasOpener === true && !!t && clean, detail: `opener=${hasOpener} tabs=${tabs.list.length} uncaught=${!clean}` }
277
- })
278
-
279
- if (process.env.STAGE_SELFTEST_OKTA) {
280
- await check('Okta Browser Plugin installs from the Web Store', async () => {
281
- await extensions.install(ctx, extensions.OKTA_ID)
282
- const list = extensions.installed(ctx)
283
- return { pass: list.some((e) => e.id === extensions.OKTA_ID), detail: JSON.stringify(list) }
284
- })
285
- // Diagnostics for extension popups: console output from every web view and from service workers.
286
- const diag = { pageConsole: [], swConsole: [], swRunning: null, popupDom: null }
287
- app.on('web-contents-created', (_e, wc) => {
288
- wc.on('console-message', (ev) => {
289
- const url = wc.isDestroyed() ? '' : wc.getURL()
290
- if (url.startsWith('chrome-extension://')) diag.pageConsole.push(`[${ev.level}] ${url.split('/').slice(3).join('/')}: ${ev.message} (${ev.sourceId}:${ev.lineNumber})`)
291
- })
292
- })
293
- ctx.session.serviceWorkers.on('console-message', (_e, d) => {
294
- diag.swConsole.push(`[${d.level}] ${d.message} (${d.sourceUrl}:${d.lineNumber})`)
295
- })
296
- await check('Okta action icon renders in the bar; popup opens', async () => {
297
- tabs.activate(t1.id)
298
- reveal.setHover(true)
299
- reveal.show()
300
- await sleep(2500)
301
- const desc = await ctx.uiView.webContents.executeJavaScript(`(() => {
302
- const l = document.querySelector('browser-action-list'); if (!l) return 'no element';
303
- const r = l.shadowRoot; const btns = r ? r.querySelectorAll('button, .action, [part]') : [];
304
- return 'buttons=' + btns.length + ' html=' + (r ? r.innerHTML.slice(0, 300) : 'no shadow')
305
- })()`)
306
- await shot('okta-bar-composite')
307
- let popupInfo = 'not attempted'
308
- const popupP = new Promise((res) => ctx.ext.once('browser-action-popup-created', res))
309
- await ctx.uiView.webContents.executeJavaScript(`(() => {
310
- const l = document.querySelector('browser-action-list'); const b = l && l.shadowRoot && l.shadowRoot.querySelector('button, .action');
311
- if (b) b.click(); return !!b })()`)
312
- const popup = await Promise.race([popupP, sleep(6000).then(() => null)])
313
- let opened = false
314
- if (popup) {
315
- await popup.whenReady().catch(() => {})
316
- await sleep(4000)
317
- const bw = popup.browserWindow
318
- if (bw && !bw.isDestroyed()) {
319
- opened = true
320
- diag.popupDom = await bw.webContents
321
- .executeJavaScript(`(() => {
322
- const t = (o) => typeof o
323
- const c = window.chrome || {}
324
- return {
325
- readyState: document.readyState,
326
- contentHtmlLength: (document.getElementById('content') || {}).innerHTML?.length,
327
- bodyText: document.body.innerText.slice(0, 300),
328
- apis: {
329
- 'runtime.sendMessage': t(c.runtime && c.runtime.sendMessage), 'storage.local': t(c.storage && c.storage.local),
330
- 'storage.session': t(c.storage && c.storage.session), 'tabs.query': t(c.tabs && c.tabs.query),
331
- scripting: t(c.scripting), declarativeNetRequest: t(c.declarativeNetRequest), webRequest: t(c.webRequest),
332
- cookies: t(c.cookies), i18n: t(c.i18n), permissions: t(c.permissions), privacy: t(c.privacy),
333
- windows: t(c.windows), action: t(c.action), alarms: t(c.alarms), idle: t(c.idle), management: t(c.management),
334
- },
335
- }
336
- })()`)
337
- .catch((e) => 'executeJavaScript failed: ' + e.message)
338
- diag.swRunning = Object.values(ctx.session.serviceWorkers.getAllRunning()).map((w) => w.scriptUrl)
339
- save('okta-popup.png', (await bw.webContents.capturePage()).toPNG())
340
- popupInfo = 'popup url=' + bw.webContents.getURL() + ' revealHeld=' + ctx.popupOpen
341
- popup.destroy()
342
- }
343
- }
344
- save('okta-diag.json', JSON.stringify(diag, null, 2))
345
- const popupText = diag.popupDom && diag.popupDom.bodyText
346
- return { pass: opened && !!popupText, detail: desc.slice(0, 80) + ' | ' + popupInfo + ' | popup text: ' + JSON.stringify(popupText) }
347
- })
348
-
349
- // Okta injects its autofill scripts with chrome.scripting.executeScript from its service worker.
350
- // A throwaway extension proves that path works end to end in Stage.
351
- await check('extension service worker can inject a script into the active tab', async () => {
352
- const dir = fs.mkdtempSync(path.join(require('os').tmpdir(), 'stage-probe-ext-'))
353
- fs.writeFileSync(path.join(dir, 'manifest.json'), JSON.stringify({
354
- manifest_version: 3, name: 'Stage probe', version: '1.0',
355
- permissions: ['scripting', 'tabs'], host_permissions: ['<all_urls>'],
356
- background: { service_worker: 'sw.js' },
357
- }))
358
- fs.writeFileSync(path.join(dir, 'sw.js'), `
359
- chrome.tabs.query({ active: true }).then(([tab]) =>
360
- chrome.scripting.executeScript({ target: { tabId: tab.id }, func: () => 'PROBE:' + document.title })
361
- ).then((r) => console.log(r[0].result)).catch((e) => console.log('PROBE-ERR:' + e.message))`)
362
- tabs.activate(t1.id)
363
- await ctx.session.extensions.loadExtension(dir)
364
- const line = await waitFor(() => diag.swConsole.find((l) => l.includes('PROBE')), 10000).catch(() => null)
365
- return { pass: !!line && line.includes('PROBE:Example Domain'), detail: line || 'no probe output' }
366
- })
367
- }
368
-
369
- await check('closing the window with a push pending does not throw', async () => {
370
- ctx.push()
371
- ctx.win.close()
372
- await sleep(800) // let the 16ms push timer, poller, save timer and hide timer all get a chance to fire
373
- return { pass: uncaught.length === 0 && ctx.quitting && ctx.win.isDestroyed(), detail: uncaught.join(' | ').slice(0, 400) }
374
- })
375
-
376
- const failed = results.filter((r) => !r.pass).length
377
- fs.writeFileSync(path.join(OUT, 'results.json'), JSON.stringify({ passed: results.length - failed, failed, results }, null, 2))
378
- console.log(`[selftest] ${results.length - failed}/${results.length} passed -> ${OUT}`)
379
- ctx.quitting = true
380
- app.exit(failed ? 1 : 0)
381
- }
382
-
383
- module.exports = { run }
package/src/main/store.js DELETED
@@ -1,77 +0,0 @@
1
- 'use strict'
2
- const fs = require('fs')
3
- const path = require('path')
4
- const { app } = require('electron')
5
-
6
- const file = (name) => path.join(app.getPath('userData'), name)
7
-
8
- function readJson(name, fallback) {
9
- try {
10
- return JSON.parse(fs.readFileSync(file(name), 'utf8'))
11
- } catch {
12
- return fallback
13
- }
14
- }
15
-
16
- function writeJson(name, data) {
17
- try {
18
- fs.mkdirSync(app.getPath('userData'), { recursive: true })
19
- const tmp = file(name) + '.tmp'
20
- fs.writeFileSync(tmp, JSON.stringify(data))
21
- fs.renameSync(tmp, file(name))
22
- } catch (e) {
23
- console.error('[stage] write failed', name, e.message)
24
- }
25
- }
26
-
27
- // ---- history -------------------------------------------------------------
28
- const HISTORY_CAP = 2000
29
- let history = null // Map url -> {url,title,visits,last}
30
- let historyTimer = null
31
-
32
- function loadHistory() {
33
- if (history) return history
34
- history = new Map()
35
- for (const h of readJson('history.json', [])) if (h && h.url) history.set(h.url, h)
36
- return history
37
- }
38
-
39
- function addVisit(url, title) {
40
- const h = loadHistory()
41
- const e = h.get(url) || { url, title: '', visits: 0, last: 0 }
42
- e.visits++
43
- e.last = Date.now()
44
- if (title) e.title = title
45
- h.delete(url)
46
- h.set(url, e)
47
- if (h.size > HISTORY_CAP) {
48
- const sorted = [...h.values()].sort((a, b) => b.last - a.last).slice(0, HISTORY_CAP)
49
- history = new Map(sorted.map((x) => [x.url, x]))
50
- }
51
- scheduleHistorySave()
52
- }
53
-
54
- function setHistoryTitle(url, title) {
55
- const e = loadHistory().get(url)
56
- if (e && title && e.title !== title) {
57
- e.title = title
58
- scheduleHistorySave()
59
- }
60
- }
61
-
62
- function scheduleHistorySave() {
63
- clearTimeout(historyTimer)
64
- historyTimer = setTimeout(flushHistory, 2000)
65
- }
66
-
67
- function flushHistory() {
68
- clearTimeout(historyTimer)
69
- historyTimer = null
70
- if (history) writeJson('history.json', [...history.values()])
71
- }
72
-
73
- function historyEntries() {
74
- return [...loadHistory().values()]
75
- }
76
-
77
- module.exports = { readJson, writeJson, addVisit, setHistoryTitle, historyEntries, flushHistory }
@@ -1,50 +0,0 @@
1
- 'use strict'
2
- const store = require('./store')
3
- const { classify } = require('./url')
4
-
5
- const MAX = 8
6
-
7
- function suggest(ctx, query) {
8
- const q = String(query || '').trim()
9
- const words = q.toLowerCase().split(/\s+/).filter(Boolean)
10
- const matches = (s) => {
11
- const l = s.toLowerCase()
12
- return words.every((w) => l.includes(w))
13
- }
14
- const out = []
15
- const seen = new Set()
16
-
17
- const first = classify(q)
18
- if (first) {
19
- out.push({
20
- kind: first.kind,
21
- title: first.kind === 'search' ? `Search Google for “${q}”` : first.url,
22
- url: first.url,
23
- })
24
- seen.add(first.url)
25
- }
26
-
27
- for (const t of ctx.tabs.list) {
28
- if (out.length >= MAX) break
29
- if (!t.url) continue
30
- if (words.length && !matches(`${t.title} ${t.url}`)) continue
31
- out.push({ kind: 'tab', title: t.title || t.url, url: t.url, tabId: t.id, favicon: t.favicon })
32
- seen.add(t.url)
33
- }
34
-
35
- if (words.length) {
36
- const now = Date.now()
37
- const scored = store
38
- .historyEntries()
39
- .filter((h) => !seen.has(h.url) && matches(`${h.title} ${h.url}`))
40
- .map((h) => ({ h, score: h.visits + Math.max(0, 7 - (now - h.last) / 86400000) }))
41
- .sort((a, b) => b.score - a.score)
42
- for (const { h } of scored) {
43
- if (out.length >= MAX) break
44
- out.push({ kind: 'history', title: h.title || h.url, url: h.url, favicon: null })
45
- }
46
- }
47
- return out.slice(0, MAX)
48
- }
49
-
50
- module.exports = { suggest }