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.
- package/README.md +92 -45
- package/build/icon.icns +0 -0
- package/build/icon.png +0 -0
- package/dist/bin/stage.js +111 -0
- package/dist/main/cli-args.js +28 -0
- package/dist/main/context-menu.js +68 -0
- package/dist/main/context.js +2 -0
- package/dist/main/extensions.js +78 -0
- package/dist/main/ipc.js +73 -0
- package/dist/main/main.js +282 -0
- package/dist/main/menu.js +140 -0
- package/dist/main/reveal.js +170 -0
- package/dist/main/selftest.js +570 -0
- package/dist/main/store.js +85 -0
- package/dist/main/suggest.js +43 -0
- package/dist/main/tabs.js +324 -0
- package/dist/main/ui-window.js +133 -0
- package/dist/main/url.js +38 -0
- package/dist/main/window.js +133 -0
- package/dist/preload/extension-compat.js +163 -0
- package/dist/preload/ui-preload.js +34 -0
- package/dist/shared/contract.js +6 -0
- package/dist/ui/app.js +692 -0
- package/{src → dist}/ui/index.html +15 -5
- package/dist/ui/mock.js +500 -0
- package/{src → dist}/ui/styles.css +55 -14
- package/node_modules/@types/chrome/LICENSE +21 -0
- package/node_modules/@types/chrome/README.md +15 -0
- package/node_modules/@types/chrome/chrome-cast/index.d.ts +1156 -0
- package/node_modules/@types/chrome/har-format/index.d.ts +6 -0
- package/node_modules/@types/chrome/index.d.ts +13786 -0
- package/node_modules/@types/chrome/package.json +99 -0
- package/node_modules/@types/filesystem/LICENSE +21 -0
- package/node_modules/@types/filesystem/README.md +15 -0
- package/node_modules/@types/filesystem/index.d.ts +564 -0
- package/node_modules/@types/filesystem/package.json +26 -0
- package/node_modules/@types/filewriter/LICENSE +21 -0
- package/node_modules/@types/filewriter/README.md +15 -0
- package/node_modules/@types/filewriter/index.d.ts +166 -0
- package/node_modules/@types/filewriter/package.json +25 -0
- package/node_modules/@types/har-format/LICENSE +21 -0
- package/node_modules/@types/har-format/README.md +15 -0
- package/node_modules/@types/har-format/index.d.ts +938 -0
- package/node_modules/@types/har-format/package.json +31 -0
- package/node_modules/adm-zip/LICENSE +21 -0
- package/node_modules/adm-zip/README.md +90 -0
- package/node_modules/adm-zip/adm-zip.js +1020 -0
- package/node_modules/adm-zip/headers/entryHeader.js +396 -0
- package/node_modules/adm-zip/headers/index.js +2 -0
- package/node_modules/adm-zip/headers/mainHeader.js +177 -0
- package/node_modules/adm-zip/methods/deflater.js +33 -0
- package/node_modules/adm-zip/methods/index.js +3 -0
- package/node_modules/adm-zip/methods/inflater.js +64 -0
- package/node_modules/adm-zip/methods/zipcrypto.js +175 -0
- package/node_modules/adm-zip/package.json +56 -0
- package/node_modules/adm-zip/types.d.ts +223 -0
- package/node_modules/adm-zip/util/constants.js +142 -0
- package/node_modules/adm-zip/util/decoder.js +5 -0
- package/node_modules/adm-zip/util/errors.js +66 -0
- package/node_modules/adm-zip/util/fattr.js +76 -0
- package/node_modules/adm-zip/util/index.js +5 -0
- package/node_modules/adm-zip/util/utils.js +481 -0
- package/node_modules/adm-zip/zipEntry.js +415 -0
- package/node_modules/adm-zip/zipFile.js +466 -0
- package/node_modules/debug/LICENSE +20 -0
- package/node_modules/debug/README.md +481 -0
- package/node_modules/debug/package.json +64 -0
- package/node_modules/debug/src/browser.js +272 -0
- package/node_modules/debug/src/common.js +292 -0
- package/node_modules/debug/src/index.js +10 -0
- package/node_modules/debug/src/node.js +263 -0
- package/node_modules/electron-chrome-web-store/README.md +143 -0
- package/node_modules/electron-chrome-web-store/dist/chrome-web-store.preload.js +299 -0
- package/node_modules/electron-chrome-web-store/dist/cjs/browser/index.js +1674 -0
- package/node_modules/electron-chrome-web-store/dist/esm/browser/index.mjs +950 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/api.d.ts +2 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/crx3.d.ts +20 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/id.d.ts +9 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/index.d.ts +62 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/installer.d.ts +29 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/loader.d.ts +18 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/types.d.ts +21 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/updater.d.ts +6 -0
- package/node_modules/electron-chrome-web-store/dist/types/browser/utils.d.ts +4 -0
- package/node_modules/electron-chrome-web-store/dist/types/common/constants.d.ts +44 -0
- package/node_modules/electron-chrome-web-store/dist/types/renderer/chrome-web-store.preload.d.ts +1 -0
- package/node_modules/electron-chrome-web-store/package.json +43 -0
- package/node_modules/ms/index.js +162 -0
- package/node_modules/ms/license.md +21 -0
- package/node_modules/ms/package.json +38 -0
- package/node_modules/ms/readme.md +59 -0
- package/node_modules/pbf/LICENSE +27 -0
- package/node_modules/pbf/README.md +293 -0
- package/node_modules/pbf/bin/pbf +17 -0
- package/node_modules/pbf/compile.js +441 -0
- package/node_modules/pbf/dist/pbf-dev.js +838 -0
- package/node_modules/pbf/dist/pbf.js +1 -0
- package/node_modules/pbf/index.d.ts +206 -0
- package/node_modules/pbf/index.js +830 -0
- package/node_modules/pbf/package.json +63 -0
- package/node_modules/protocol-buffers-schema/.travis.yml +7 -0
- package/node_modules/protocol-buffers-schema/LICENSE +21 -0
- package/node_modules/protocol-buffers-schema/README.md +122 -0
- package/node_modules/protocol-buffers-schema/example.js +11 -0
- package/node_modules/protocol-buffers-schema/example.proto +13 -0
- package/node_modules/protocol-buffers-schema/index.js +6 -0
- package/node_modules/protocol-buffers-schema/package.json +31 -0
- package/node_modules/protocol-buffers-schema/parse.js +769 -0
- package/node_modules/protocol-buffers-schema/stringify.js +206 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/basic.proto +11 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.json +99 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/comments.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.json +125 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/complex.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.json +42 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/enum.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.json +32 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/escaped-quotes.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.json +167 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/extend.proto +19 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/import.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.json +33 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/map.proto +3 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/no-tags.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.json +41 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/oneof.proto +6 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.json +364 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/option.proto +72 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.json +47 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/options.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/pheromon-trajectories.proto +8 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.json +55 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/reserved.proto +17 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.json +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/search.proto +5 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.json +108 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/service.proto +30 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/valid-packed.proto +35 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.json +90 -0
- package/node_modules/protocol-buffers-schema/test/fixtures/version.proto +13 -0
- package/node_modules/protocol-buffers-schema/test/index.js +157 -0
- package/node_modules/protocol-buffers-schema/tokenize.js +56 -0
- package/node_modules/resolve-protobuf-schema/.travis.yml +3 -0
- package/node_modules/resolve-protobuf-schema/LICENSE +21 -0
- package/node_modules/resolve-protobuf-schema/README.md +49 -0
- package/node_modules/resolve-protobuf-schema/index.js +50 -0
- package/node_modules/resolve-protobuf-schema/package.json +25 -0
- package/node_modules/resolve-protobuf-schema/test/a.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/b.proto +5 -0
- package/node_modules/resolve-protobuf-schema/test/c.proto +3 -0
- package/node_modules/resolve-protobuf-schema/test/index.js +49 -0
- package/package.json +35 -11
- package/bin/stage.js +0 -52
- package/src/main/cli-args.js +0 -28
- package/src/main/context-menu.js +0 -64
- package/src/main/extensions.js +0 -61
- package/src/main/main.js +0 -310
- package/src/main/menu.js +0 -171
- package/src/main/reveal.js +0 -141
- package/src/main/selftest.js +0 -383
- package/src/main/store.js +0 -77
- package/src/main/suggest.js +0 -50
- package/src/main/tabs.js +0 -351
- package/src/main/url.js +0 -37
- package/src/main/window.js +0 -71
- package/src/preload/extension-compat.js +0 -34
- package/src/preload/ui-preload.js +0 -40
- package/src/ui/app.js +0 -588
- package/src/ui/mock.js +0 -455
- /package/{src → dist}/ui/newtab.html +0 -0
|
@@ -0,0 +1,570 @@
|
|
|
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
|
+
const sameRect = (a, b) => a.x === b.x && a.y === b.y && a.width === b.width && a.height === b.height;
|
|
58
|
+
// Resolves on the window event, or after `ms` if it never comes.
|
|
59
|
+
const once = (win, event, ms = 3000) => new Promise((r) => {
|
|
60
|
+
const t = setTimeout(r, ms);
|
|
61
|
+
win.once(event, () => {
|
|
62
|
+
clearTimeout(t);
|
|
63
|
+
r();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
async function run(ctx) {
|
|
67
|
+
(0, node_fs_1.mkdirSync)(OUT, { recursive: true });
|
|
68
|
+
const results = [];
|
|
69
|
+
const uncaught = [];
|
|
70
|
+
ctx.holdQuit = true; // keep the app alive after the close-window check so results get written
|
|
71
|
+
process.on('uncaughtException', (e) => {
|
|
72
|
+
uncaught.push(String(e.stack ?? e));
|
|
73
|
+
console.error('[selftest] uncaughtException', e);
|
|
74
|
+
});
|
|
75
|
+
const check = async (name, fn) => {
|
|
76
|
+
let outcome;
|
|
77
|
+
try {
|
|
78
|
+
outcome = await fn();
|
|
79
|
+
}
|
|
80
|
+
catch (e) {
|
|
81
|
+
outcome = { pass: false, detail: 'threw: ' + (e instanceof Error ? e.message : String(e)) };
|
|
82
|
+
}
|
|
83
|
+
const result = { name, pass: outcome.pass, detail: outcome.detail ?? '' };
|
|
84
|
+
results.push(result);
|
|
85
|
+
console.log(`[selftest] ${result.pass ? 'PASS' : 'FAIL'} ${name} ${result.detail}`);
|
|
86
|
+
};
|
|
87
|
+
const save = (name, data) => (0, node_fs_1.writeFileSync)((0, node_path_1.join)(OUT, name), data);
|
|
88
|
+
const { tabs, reveal, win } = ctx;
|
|
89
|
+
const uiWin = ctx.ui.win;
|
|
90
|
+
const ui = ctx.ui.view.webContents;
|
|
91
|
+
// The UI window should sit exactly over the page window's content area, `height` tall.
|
|
92
|
+
const overContent = (height) => {
|
|
93
|
+
const c = win.getContentBounds();
|
|
94
|
+
return uiWin.isVisible() && sameRect(uiWin.getBounds(), { ...c, height });
|
|
95
|
+
};
|
|
96
|
+
const activeTab = () => {
|
|
97
|
+
const t = tabs.active;
|
|
98
|
+
if (!t)
|
|
99
|
+
throw new Error('no active tab');
|
|
100
|
+
return t;
|
|
101
|
+
};
|
|
102
|
+
const only = (keep) => {
|
|
103
|
+
for (const t of tabs.list.filter((x) => !keep.includes(x)))
|
|
104
|
+
tabs.close(t.id);
|
|
105
|
+
};
|
|
106
|
+
await check('page window and UI child window exist; new tab page present when empty', async () => {
|
|
107
|
+
tabs.create();
|
|
108
|
+
const child = win.getChildWindows().some((w) => w.id === uiWin.id) && uiWin.getParentWindow()?.id === win.id;
|
|
109
|
+
const protectedUi = uiWin.isContentProtected() && !uiWin.isFocusable();
|
|
110
|
+
return {
|
|
111
|
+
pass: tabs.list.length === 1 && !!tabs.list[0]?.newTab && child && protectedUi,
|
|
112
|
+
detail: `newtab.html exists=${(0, node_fs_1.existsSync)(tabs_1.NEWTAB_FILE)} child=${child} protected+unfocusable=${protectedUi}`,
|
|
113
|
+
};
|
|
114
|
+
});
|
|
115
|
+
only([]);
|
|
116
|
+
let t1;
|
|
117
|
+
let t2;
|
|
118
|
+
const openWorkingSet = () => {
|
|
119
|
+
t1 = tabs.create({ url: 'https://example.com', activate: true });
|
|
120
|
+
t2 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Web_browser', activate: false });
|
|
121
|
+
};
|
|
122
|
+
await check('launch with two URLs: both load with title', async () => {
|
|
123
|
+
openWorkingSet();
|
|
124
|
+
await waitFor(() => loaded(t1) && loaded(t2));
|
|
125
|
+
return { pass: /Example Domain/.test(t1.title) && /Web browser/i.test(t2.title), detail: `${t1.title} | ${t2.title}` };
|
|
126
|
+
});
|
|
127
|
+
only([t1, t2]); // drop the fresh tab that replaced the one closed above
|
|
128
|
+
await check('favicon and state pushed (wikipedia)', async () => {
|
|
129
|
+
await waitFor(() => t2.favicon, 15_000).catch(() => { });
|
|
130
|
+
const w = ctx.getState().tabs.find((t) => t.id === t2.id);
|
|
131
|
+
return { pass: !!(w?.favicon && w.title && w.url), detail: `favicon=${w?.favicon}` };
|
|
132
|
+
});
|
|
133
|
+
await check('user agent has no Electron/Stage token', async () => {
|
|
134
|
+
const ua = await t1.wc.executeJavaScript('navigator.userAgent');
|
|
135
|
+
const bad = /Electron|stage-browser|Stage\//i;
|
|
136
|
+
return { pass: !bad.test(ua) && !bad.test(ctx.session.getUserAgent()), detail: ua };
|
|
137
|
+
});
|
|
138
|
+
await check('url resolution cases', async () => {
|
|
139
|
+
const cases = [
|
|
140
|
+
['https://a.com/x', 'https://a.com/x'],
|
|
141
|
+
['example.com', 'https://example.com'],
|
|
142
|
+
['example.com/path?q=1', 'https://example.com/path?q=1'],
|
|
143
|
+
['localhost:3000', 'http://localhost:3000'],
|
|
144
|
+
['127.0.0.1:8080/a', 'http://127.0.0.1:8080/a'],
|
|
145
|
+
['localhost', 'http://localhost'],
|
|
146
|
+
['about:blank', 'about:blank'],
|
|
147
|
+
['hello world', 'https://www.google.com/search?q=hello%20world'],
|
|
148
|
+
['stage', 'https://www.google.com/search?q=stage'],
|
|
149
|
+
['what is 3.5', 'https://www.google.com/search?q=what%20is%203.5'],
|
|
150
|
+
['zoommtg://x', 'zoommtg://x'],
|
|
151
|
+
];
|
|
152
|
+
const bad = cases.filter(([i, o]) => (0, url_1.resolveInput)(i) !== o).map(([i, o]) => `${i} -> ${(0, url_1.resolveInput)(i)} (want ${o})`);
|
|
153
|
+
return { pass: bad.length === 0, detail: bad.join('; ') };
|
|
154
|
+
});
|
|
155
|
+
await check('cli-args parsing', async () => {
|
|
156
|
+
const a = (0, cli_args_1.parseArgs)(['electron', '.', '--inspect=1', '--size', '1280x720', 'a.com', '--pin', '--fresh', 'hello world']);
|
|
157
|
+
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) };
|
|
158
|
+
});
|
|
159
|
+
await check('activate / close / reopen closed tab', async () => {
|
|
160
|
+
tabs.activate(t1.id);
|
|
161
|
+
const ok1 = ctx.getState().activeTabId === t1.id && t1.view.getVisible() && !t2.view.getVisible();
|
|
162
|
+
const url2 = t2.url;
|
|
163
|
+
tabs.close(t2.id);
|
|
164
|
+
const ok2 = tabs.list.length === 1;
|
|
165
|
+
tabs.reopenClosed();
|
|
166
|
+
await sleep(200);
|
|
167
|
+
const reopened = tabs.list.find((x) => x.id !== t1.id);
|
|
168
|
+
if (!reopened)
|
|
169
|
+
return { pass: false, detail: 'nothing reopened' };
|
|
170
|
+
t2 = reopened;
|
|
171
|
+
const ok3 = tabs.list.length === 2 && tabs.activeId === t2.id;
|
|
172
|
+
await waitFor(() => loaded(t2));
|
|
173
|
+
return { pass: ok1 && ok2 && ok3 && t2.url === url2, detail: `visibleOnlyActive=${ok1} closed=${ok2} reopened=${ok3} url=${t2.url}` };
|
|
174
|
+
});
|
|
175
|
+
await check('closing the last tab leaves a new-tab page', async () => {
|
|
176
|
+
const t = tabs.create({ url: 'about:blank' });
|
|
177
|
+
only([t]);
|
|
178
|
+
await sleep(100);
|
|
179
|
+
const single = tabs.list.length === 1;
|
|
180
|
+
tabs.close(t.id);
|
|
181
|
+
await sleep(300);
|
|
182
|
+
const newTab = tabs.list.length === 1 && !!tabs.list[0]?.newTab;
|
|
183
|
+
const placeholder = tabs.list[0];
|
|
184
|
+
openWorkingSet();
|
|
185
|
+
if (placeholder)
|
|
186
|
+
tabs.close(placeholder.id);
|
|
187
|
+
await waitFor(() => loaded(t1) && loaded(t2));
|
|
188
|
+
tabs.activate(t1.id);
|
|
189
|
+
return { pass: single && newTab, detail: `single=${single} newtab=${newTab}` };
|
|
190
|
+
});
|
|
191
|
+
await check("suggest('wiki') returns open tab + history", async () => {
|
|
192
|
+
const t3 = tabs.create({ url: 'https://en.wikipedia.org/wiki/Google_Chrome', activate: false });
|
|
193
|
+
await waitFor(() => loaded(t3));
|
|
194
|
+
tabs.close(t3.id);
|
|
195
|
+
const s = (0, suggest_1.suggest)(tabs.list, 'wiki');
|
|
196
|
+
const okTab = s.some((x) => x.kind === 'tab' && x.tabId === t2.id);
|
|
197
|
+
const okHist = s.some((x) => x.kind === 'history' && /Google_Chrome/.test(x.url));
|
|
198
|
+
return { pass: s[0]?.kind === 'search' && okTab && okHist && s.length <= 8, detail: JSON.stringify(s.map((x) => [x.kind, x.url])) };
|
|
199
|
+
});
|
|
200
|
+
await check('suggest: url and search first items', async () => {
|
|
201
|
+
const a = (0, suggest_1.suggest)(tabs.list, 'example.org')[0];
|
|
202
|
+
const b = (0, suggest_1.suggest)(tabs.list, 'two words')[0];
|
|
203
|
+
return { pass: a?.kind === 'url' && a.url === 'https://example.org' && b?.kind === 'search', detail: `${a?.kind} ${b?.kind}` };
|
|
204
|
+
});
|
|
205
|
+
const shot = async (name) => {
|
|
206
|
+
const page = await activeTab().wc.capturePage();
|
|
207
|
+
const bar = await ui.capturePage();
|
|
208
|
+
save(`${name.replace('composite', 'page')}.png`, page.toPNG());
|
|
209
|
+
save(`${name.replace('composite', 'ui')}.png`, bar.toPNG());
|
|
210
|
+
save(`${name}.png`, Buffer.from(await composite([page, bar]), 'base64'));
|
|
211
|
+
return { page: page.getSize(), ui: bar.getSize() };
|
|
212
|
+
};
|
|
213
|
+
await check('reveal bar: state pushed visible, UI window shown over the strip, composite captured', async () => {
|
|
214
|
+
reveal.setHover(true); // the real cursor is elsewhere; keep the poller from hiding the bar
|
|
215
|
+
try {
|
|
216
|
+
reveal.show();
|
|
217
|
+
await sleep(1200);
|
|
218
|
+
const sizes = await shot('bar-composite');
|
|
219
|
+
const over = overContent(72);
|
|
220
|
+
return { pass: ctx.bar.visible && over && sizes.ui.height > 0, detail: JSON.stringify({ sizes, ui: uiWin.getBounds(), content: win.getContentBounds() }) };
|
|
221
|
+
}
|
|
222
|
+
finally {
|
|
223
|
+
reveal.setHover(false); // a failed capture must not leave the bar pinned for later checks
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
await check('UI window follows the page window when it moves', async () => {
|
|
227
|
+
reveal.setHover(true);
|
|
228
|
+
reveal.show();
|
|
229
|
+
const [x = 0, y = 0] = win.getPosition();
|
|
230
|
+
win.setPosition(x + 40, y + 30);
|
|
231
|
+
await sleep(100);
|
|
232
|
+
const moved = overContent(72);
|
|
233
|
+
win.setPosition(x, y);
|
|
234
|
+
await sleep(100);
|
|
235
|
+
const back = overContent(72);
|
|
236
|
+
reveal.setHover(false);
|
|
237
|
+
return { pass: moved && back, detail: JSON.stringify({ moved, back, ui: uiWin.getBounds(), content: win.getContentBounds() }) };
|
|
238
|
+
});
|
|
239
|
+
await check('omnibox overlay: UI window covers the content area and takes focus, composite captured', async () => {
|
|
240
|
+
reveal.openOverlay('new', '');
|
|
241
|
+
await sleep(800);
|
|
242
|
+
await ui
|
|
243
|
+
.executeJavaScript(`(() => { const i = document.querySelector('input'); if (i) { i.focus(); i.value = 'wiki'; i.dispatchEvent(new Event('input', { bubbles: true })) } return !!i })()`)
|
|
244
|
+
.catch(() => { });
|
|
245
|
+
await sleep(900);
|
|
246
|
+
const [, h = 0] = win.getContentSize();
|
|
247
|
+
const full = overContent(h);
|
|
248
|
+
const focusable = uiWin.isFocusable();
|
|
249
|
+
const sizes = await shot('omnibox-composite');
|
|
250
|
+
reveal.closeOverlay();
|
|
251
|
+
const released = !uiWin.isFocusable();
|
|
252
|
+
return { pass: full && focusable && released && !ctx.overlay, detail: JSON.stringify({ full, focusable, released, sizes }) };
|
|
253
|
+
});
|
|
254
|
+
await check('pin: tab view still fills the content area, UI window is the 52px strip over it', async () => {
|
|
255
|
+
reveal.setPinned(true);
|
|
256
|
+
await sleep(100);
|
|
257
|
+
const [cw = 0, ch = 0] = win.getContentSize();
|
|
258
|
+
const fills = sameRect(activeTab().view.getBounds(), { x: 0, y: 0, width: cw, height: ch });
|
|
259
|
+
const strip = overContent(52);
|
|
260
|
+
reveal.setPinned(false);
|
|
261
|
+
const unpinned = sameRect(activeTab().view.getBounds(), { x: 0, y: 0, width: cw, height: ch });
|
|
262
|
+
return { pass: fills && strip && unpinned, detail: JSON.stringify({ fills, strip, unpinned, view: activeTab().view.getBounds() }) };
|
|
263
|
+
});
|
|
264
|
+
await check('hide: state false, UI window hidden after timeout', async () => {
|
|
265
|
+
reveal.hide();
|
|
266
|
+
const stateFalse = !ctx.bar.visible;
|
|
267
|
+
await sleep(500);
|
|
268
|
+
return { pass: stateFalse && !uiWin.isVisible(), detail: `uiVisible=${uiWin.isVisible()}` };
|
|
269
|
+
});
|
|
270
|
+
await check('minimize hides the UI window; restore brings it back', async () => {
|
|
271
|
+
reveal.setPinned(true);
|
|
272
|
+
await sleep(100);
|
|
273
|
+
const before = overContent(52);
|
|
274
|
+
const minimized = once(win, 'minimize');
|
|
275
|
+
win.minimize();
|
|
276
|
+
await minimized;
|
|
277
|
+
await sleep(200);
|
|
278
|
+
const hiddenWhileMin = win.isMinimized() && !uiWin.isVisible();
|
|
279
|
+
const restored = once(win, 'restore');
|
|
280
|
+
win.restore();
|
|
281
|
+
await restored;
|
|
282
|
+
await sleep(300);
|
|
283
|
+
const after = overContent(52);
|
|
284
|
+
reveal.setPinned(false);
|
|
285
|
+
reveal.hide();
|
|
286
|
+
return { pass: before && hiddenWhileMin && after, detail: JSON.stringify({ before, hiddenWhileMin, after }) };
|
|
287
|
+
});
|
|
288
|
+
await check('full screen: the UI window covers the strip of the full-screen window; leaving restores it', async () => {
|
|
289
|
+
reveal.setPinned(true);
|
|
290
|
+
await sleep(100);
|
|
291
|
+
const entered = once(win, 'enter-full-screen', 5000);
|
|
292
|
+
win.setFullScreen(true);
|
|
293
|
+
await entered;
|
|
294
|
+
await sleep(500);
|
|
295
|
+
const inFull = win.isFullScreen() && overContent(52) && ctx.getState().fullscreen;
|
|
296
|
+
const left = once(win, 'leave-full-screen', 5000);
|
|
297
|
+
win.setFullScreen(false);
|
|
298
|
+
await left;
|
|
299
|
+
await sleep(500);
|
|
300
|
+
const out = !win.isFullScreen() && overContent(52);
|
|
301
|
+
reveal.setPinned(false);
|
|
302
|
+
reveal.hide();
|
|
303
|
+
return { pass: inFull && out, detail: JSON.stringify({ inFull, out, ui: uiWin.getBounds(), content: win.getContentBounds() }) };
|
|
304
|
+
});
|
|
305
|
+
await check('floating bar has room for its shadow; clicks under the strip reach the page', async () => {
|
|
306
|
+
const page = 'data:text/html,' +
|
|
307
|
+
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>');
|
|
308
|
+
reveal.closeOverlay();
|
|
309
|
+
reveal.setPinned(false);
|
|
310
|
+
const tab = tabs.create({ url: page, activate: true });
|
|
311
|
+
await waitFor(() => !tab.loading && tab.url.startsWith('data:'));
|
|
312
|
+
reveal.show();
|
|
313
|
+
await sleep(400);
|
|
314
|
+
const floatH = uiWin.getBounds().height;
|
|
315
|
+
for (const type of ['mouseDown', 'mouseUp'])
|
|
316
|
+
ui.sendInputEvent({ type, x: 420, y: 62, button: 'left', clickCount: 1 });
|
|
317
|
+
const clicked = await waitFor(() => tab.wc.executeJavaScript('window.clicked || 0'), 3000).catch(() => 0);
|
|
318
|
+
const hidden = !ctx.bar.visible && !uiWin.isVisible();
|
|
319
|
+
reveal.setPinned(true);
|
|
320
|
+
await sleep(100);
|
|
321
|
+
const pinnedH = uiWin.getBounds().height;
|
|
322
|
+
reveal.setPinned(false);
|
|
323
|
+
reveal.hide();
|
|
324
|
+
tabs.close(tab.id);
|
|
325
|
+
return { pass: floatH === 72 && clicked === 1 && hidden && pinnedH === 52, detail: JSON.stringify({ floatH, clicked, hidden, pinnedH }) };
|
|
326
|
+
});
|
|
327
|
+
await check('extension icons: shown with a button extension, hidden by the menu option, gone with none installed', async () => {
|
|
328
|
+
const dir = writeExtension('stage-action-ext-', { manifest_version: 3, name: 'Stage action probe', version: '1.0', action: { default_title: 'Probe' } });
|
|
329
|
+
const probe = await ctx.session.extensions.loadExtension(dir);
|
|
330
|
+
const controlsShown = () => ui.executeJavaScript("document.getElementById('controls').checkVisibility()");
|
|
331
|
+
reveal.show();
|
|
332
|
+
await sleep(400);
|
|
333
|
+
const withExt = await controlsShown();
|
|
334
|
+
ctx.setHideExtensionIcons(true);
|
|
335
|
+
await sleep(250);
|
|
336
|
+
const hiddenByOption = !(await controlsShown());
|
|
337
|
+
const item = electron_1.Menu.getApplicationMenu()
|
|
338
|
+
?.items.find((i) => i.label === 'Extensions')
|
|
339
|
+
?.submenu?.items.find((i) => i.label === 'Hide Icons in Tab Bar');
|
|
340
|
+
const checked = !!item?.checked;
|
|
341
|
+
const saved = (0, store_1.readPrefs)().hideExtensionIcons;
|
|
342
|
+
ctx.setHideExtensionIcons(false);
|
|
343
|
+
await sleep(250);
|
|
344
|
+
const back = await controlsShown();
|
|
345
|
+
ctx.session.extensions.removeExtension(probe.id);
|
|
346
|
+
await sleep(400);
|
|
347
|
+
const goneWithNone = !(await controlsShown());
|
|
348
|
+
const noPinButton = await ui.executeJavaScript("!document.getElementById('pin')");
|
|
349
|
+
reveal.hide();
|
|
350
|
+
const r = { withExt, hiddenByOption, checked, saved, back, goneWithNone, noPinButton };
|
|
351
|
+
return { pass: Object.values(r).every(Boolean), detail: JSON.stringify(r) };
|
|
352
|
+
});
|
|
353
|
+
await check('the page window holds only tab views', async () => {
|
|
354
|
+
tabs.create({ url: 'about:blank', activate: false });
|
|
355
|
+
const kids = win.contentView.children;
|
|
356
|
+
const onlyTabs = kids.length === tabs.list.length && kids.every((v) => tabs.list.some((t) => t.view === v));
|
|
357
|
+
return { pass: onlyTabs, detail: `children=${kids.length} tabs=${tabs.list.length}` };
|
|
358
|
+
});
|
|
359
|
+
await check('content size 1280x720 sets and centers', async () => {
|
|
360
|
+
win.setContentSize(1280, 720);
|
|
361
|
+
win.center();
|
|
362
|
+
const [w, h] = win.getContentSize();
|
|
363
|
+
return { pass: w === 1280 && h === 720, detail: `${w}x${h}` };
|
|
364
|
+
});
|
|
365
|
+
await check('external scheme from page opens via shell, not in tab', async () => {
|
|
366
|
+
const original = electron_1.shell.openExternal;
|
|
367
|
+
let called = '';
|
|
368
|
+
electron_1.shell.openExternal = async (url) => {
|
|
369
|
+
called = url;
|
|
370
|
+
};
|
|
371
|
+
try {
|
|
372
|
+
const r = tabs.openHandler({
|
|
373
|
+
url: 'zoommtg://zoom.us/join?x=1',
|
|
374
|
+
frameName: '',
|
|
375
|
+
features: '',
|
|
376
|
+
disposition: 'foreground-tab',
|
|
377
|
+
referrer: { url: '', policy: 'default' },
|
|
378
|
+
});
|
|
379
|
+
return { pass: r.action === 'deny' && called.startsWith('zoommtg:'), detail: called };
|
|
380
|
+
}
|
|
381
|
+
finally {
|
|
382
|
+
electron_1.shell.openExternal = original;
|
|
383
|
+
}
|
|
384
|
+
});
|
|
385
|
+
// Real clicks, so Electron's own window-open path runs (not just openHandler's return value).
|
|
386
|
+
const LINKS_PAGE = 'data:text/html,' +
|
|
387
|
+
encodeURIComponent('<a id="blank" target="_blank" href="https://example.com/?from=blank">blank</a>' +
|
|
388
|
+
'<script>window.openWithOpener = () => { const w = window.open("about:blank"); return !!w && !w.closed && w.opener === window }</script>');
|
|
389
|
+
const openLinksPage = async () => {
|
|
390
|
+
const src = tabs.create({ url: LINKS_PAGE, activate: true });
|
|
391
|
+
await waitFor(() => !src.loading && src.url.startsWith('data:'));
|
|
392
|
+
return src;
|
|
393
|
+
};
|
|
394
|
+
await check('target=_blank link opens the URL in a new active tab', async () => {
|
|
395
|
+
const errorsBefore = uncaught.length;
|
|
396
|
+
const src = await openLinksPage();
|
|
397
|
+
const before = tabs.list.length;
|
|
398
|
+
await src.wc.executeJavaScript('document.getElementById("blank").click()', true);
|
|
399
|
+
const t = await waitFor(() => tabs.list.length === before + 1 && tabs.list.find((x) => x.url.includes('from=blank')), 15_000);
|
|
400
|
+
const ok = tabs.activeId === t.id && uncaught.length === errorsBefore;
|
|
401
|
+
tabs.close(t.id);
|
|
402
|
+
tabs.close(src.id);
|
|
403
|
+
return { pass: ok, detail: t.url };
|
|
404
|
+
});
|
|
405
|
+
await check('window.open() opens a tab that keeps window.opener', async () => {
|
|
406
|
+
const errorsBefore = uncaught.length;
|
|
407
|
+
const src = await openLinksPage();
|
|
408
|
+
const before = tabs.list.length;
|
|
409
|
+
const hasOpener = await src.wc.executeJavaScript('window.openWithOpener()', true);
|
|
410
|
+
await waitFor(() => tabs.list.length === before + 1, 5000);
|
|
411
|
+
const t = tabs.list.find((x) => x.id !== src.id && x.id === tabs.activeId);
|
|
412
|
+
if (t)
|
|
413
|
+
tabs.close(t.id);
|
|
414
|
+
tabs.close(src.id);
|
|
415
|
+
const clean = uncaught.length === errorsBefore;
|
|
416
|
+
return { pass: hasOpener && !!t && clean, detail: `opener=${hasOpener} tabs=${tabs.list.length} uncaught=${!clean}` };
|
|
417
|
+
});
|
|
418
|
+
// Opt-in compatibility suite against a real extension from the Web Store. The app itself
|
|
419
|
+
// installs nothing. STAGE_SELFTEST_EXT_ID=<web store id> targets any other extension.
|
|
420
|
+
if (process.env.STAGE_SELFTEST_OKTA || process.env.STAGE_SELFTEST_EXT_ID) {
|
|
421
|
+
const extId = process.env.STAGE_SELFTEST_EXT_ID || OKTA_ID;
|
|
422
|
+
// Console output from every extension page and service worker, recorded from before the
|
|
423
|
+
// install so startup errors are caught.
|
|
424
|
+
const diag = { pageConsole: [], swConsole: [], swRunning: null, popupDom: null };
|
|
425
|
+
electron_1.app.on('web-contents-created', (_e, wc) => {
|
|
426
|
+
wc.on('console-message', (ev) => {
|
|
427
|
+
const url = wc.isDestroyed() ? '' : wc.getURL();
|
|
428
|
+
if (url.startsWith('chrome-extension://'))
|
|
429
|
+
diag.pageConsole.push(`[${ev.level}] ${url.split('/').slice(3).join('/')}: ${ev.message} (${ev.sourceId}:${ev.lineNumber})`);
|
|
430
|
+
});
|
|
431
|
+
});
|
|
432
|
+
ctx.session.serviceWorkers.on('console-message', (_e, d) => {
|
|
433
|
+
diag.swConsole.push(`[${d.level}] ${d.message} (${d.sourceUrl}:${d.lineNumber})`);
|
|
434
|
+
});
|
|
435
|
+
const heard = (marker) => diag.swConsole.filter((l) => l.includes(marker)).length;
|
|
436
|
+
await check(`extension ${extId} installs from the Web Store`, async () => {
|
|
437
|
+
await (0, extensions_1.install)(ctx.session, extId);
|
|
438
|
+
const list = (0, extensions_1.installed)(ctx.session);
|
|
439
|
+
return { pass: list.some((e) => e.id === extId), detail: JSON.stringify(list) };
|
|
440
|
+
});
|
|
441
|
+
await check('extension responds to its toolbar button (popup or page)', async () => {
|
|
442
|
+
tabs.activate(t1.id);
|
|
443
|
+
reveal.setHover(true);
|
|
444
|
+
reveal.show();
|
|
445
|
+
await sleep(2500);
|
|
446
|
+
const desc = await ui.executeJavaScript(`(() => {
|
|
447
|
+
const l = document.querySelector('browser-action-list'); if (!l) return 'no element';
|
|
448
|
+
const r = l.shadowRoot; const btns = r ? r.querySelectorAll('button, .action, [part]') : [];
|
|
449
|
+
return 'buttons=' + btns.length + ' html=' + (r ? r.innerHTML.slice(0, 300) : 'no shadow')
|
|
450
|
+
})()`);
|
|
451
|
+
await shot('ext-bar-composite').catch(() => { }); // screenshots need an awake display; the check doesn't
|
|
452
|
+
let popupInfo = 'not attempted';
|
|
453
|
+
const tabsBefore = new Set(tabs.list.map((t) => t.id));
|
|
454
|
+
const popupCreated = new Promise((res) => ctx.ext.once('browser-action-popup-created', (p) => res(p)));
|
|
455
|
+
await ui.executeJavaScript(`(() => {
|
|
456
|
+
const l = document.querySelector('browser-action-list'); const b = l && l.shadowRoot && l.shadowRoot.querySelector('button, .action');
|
|
457
|
+
if (b) b.click(); return !!b })()`);
|
|
458
|
+
const popup = await Promise.race([popupCreated, sleep(6000).then(() => null)]);
|
|
459
|
+
let opened = false;
|
|
460
|
+
const bw = popup && (await popup.whenReady().catch(() => { }), await sleep(4000), popup.browserWindow);
|
|
461
|
+
if (popup && bw && !bw.isDestroyed()) {
|
|
462
|
+
opened = true;
|
|
463
|
+
diag.popupDom = await bw.webContents
|
|
464
|
+
.executeJavaScript(`(() => {
|
|
465
|
+
const t = (o) => typeof o
|
|
466
|
+
const c = window.chrome || {}
|
|
467
|
+
return {
|
|
468
|
+
readyState: document.readyState,
|
|
469
|
+
contentHtmlLength: (document.getElementById('content') || {}).innerHTML?.length,
|
|
470
|
+
bodyText: document.body.innerText.slice(0, 300),
|
|
471
|
+
apis: {
|
|
472
|
+
'runtime.sendMessage': t(c.runtime && c.runtime.sendMessage), 'storage.local': t(c.storage && c.storage.local),
|
|
473
|
+
'storage.session': t(c.storage && c.storage.session), 'tabs.query': t(c.tabs && c.tabs.query),
|
|
474
|
+
scripting: t(c.scripting), declarativeNetRequest: t(c.declarativeNetRequest), webRequest: t(c.webRequest),
|
|
475
|
+
cookies: t(c.cookies), i18n: t(c.i18n), permissions: t(c.permissions), privacy: t(c.privacy),
|
|
476
|
+
windows: t(c.windows), action: t(c.action), alarms: t(c.alarms), idle: t(c.idle), management: t(c.management),
|
|
477
|
+
downloads: t(c.downloads), offscreen: t(c.offscreen), contextMenus: t(c.contextMenus), notifications: t(c.notifications),
|
|
478
|
+
'runtime.connectNative': t(c.runtime && c.runtime.connectNative), 'runtime.sendNativeMessage': t(c.runtime && c.runtime.sendNativeMessage),
|
|
479
|
+
identity: t(c.identity), commands: t(c.commands), sidePanel: t(c.sidePanel), 'privacy.services': t(c.privacy && c.privacy.services),
|
|
480
|
+
},
|
|
481
|
+
}
|
|
482
|
+
})()`)
|
|
483
|
+
.catch((e) => 'executeJavaScript failed: ' + e.message);
|
|
484
|
+
diag.swRunning = Object.values(ctx.session.serviceWorkers.getAllRunning()).map((w) => w.scriptUrl);
|
|
485
|
+
await bw.webContents
|
|
486
|
+
.capturePage()
|
|
487
|
+
.then((img) => save('ext-popup.png', img.toPNG()))
|
|
488
|
+
.catch(() => { });
|
|
489
|
+
popupInfo = 'popup url=' + bw.webContents.getURL() + ' revealHeld=' + ctx.popupOpen;
|
|
490
|
+
popup.destroy();
|
|
491
|
+
}
|
|
492
|
+
// An extension may answer a click by opening a page instead (1Password does on first run).
|
|
493
|
+
if (!popup)
|
|
494
|
+
await sleep(3000);
|
|
495
|
+
const newTabs = tabs.list.filter((t) => !tabsBefore.has(t.id));
|
|
496
|
+
diag.newTabsAfterClick = newTabs.map((t) => (t.wc.isDestroyed() ? '' : t.wc.getURL()));
|
|
497
|
+
for (const t of newTabs) {
|
|
498
|
+
await waitFor(() => !t.loading, 10_000).catch(() => { });
|
|
499
|
+
await t.wc
|
|
500
|
+
.capturePage()
|
|
501
|
+
.then((img) => save('ext-click-tab.png', img.toPNG()))
|
|
502
|
+
.catch(() => { });
|
|
503
|
+
diag.newTabText = await t.wc.executeJavaScript('document.body ? document.body.innerText.slice(0, 300) : ""').catch(() => '');
|
|
504
|
+
}
|
|
505
|
+
save('ext-diag.json', JSON.stringify(diag, null, 2));
|
|
506
|
+
const dom = diag.popupDom;
|
|
507
|
+
const popupText = dom && typeof dom === 'object' && 'bodyText' in dom ? String(dom.bodyText) : '';
|
|
508
|
+
const respondedWithPage = newTabs.length > 0 && !!diag.newTabText;
|
|
509
|
+
return {
|
|
510
|
+
pass: (opened && !!popupText) || respondedWithPage,
|
|
511
|
+
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(' | '),
|
|
512
|
+
};
|
|
513
|
+
});
|
|
514
|
+
// Okta injects its autofill scripts with chrome.scripting.executeScript from its service worker.
|
|
515
|
+
await check('extension service worker can inject a script into the active tab', async () => {
|
|
516
|
+
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' } }, {
|
|
517
|
+
'sw.js': `
|
|
518
|
+
chrome.tabs.query({ active: true }).then(([tab]) =>
|
|
519
|
+
chrome.scripting.executeScript({ target: { tabId: tab.id }, func: () => 'PROBE:' + document.title })
|
|
520
|
+
).then((r) => console.log(r[0].result)).catch((e) => console.log('PROBE-ERR:' + e.message))`,
|
|
521
|
+
});
|
|
522
|
+
tabs.activate(t1.id);
|
|
523
|
+
await ctx.session.extensions.loadExtension(dir);
|
|
524
|
+
const line = await waitFor(() => diag.swConsole.find((l) => l.includes('PROBE')), 10_000).catch(() => null);
|
|
525
|
+
return { pass: !!line?.includes('PROBE:Example Domain'), detail: line ?? 'no probe output' };
|
|
526
|
+
});
|
|
527
|
+
// Regression: a tracker iframe whose URL contains a UUID made Okta take over the tab, because
|
|
528
|
+
// webNavigation URL filters were ignored.
|
|
529
|
+
const UUID_IFRAME_PAGE = 'data:text/html,' + encodeURIComponent('<h1>host</h1><iframe src="https://example.com/?id=11111111-2222-4333-8444-555555555555"></iframe>');
|
|
530
|
+
await check('webNavigation URL filters: listeners hear only matching URLs', async () => {
|
|
531
|
+
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' } }, {
|
|
532
|
+
'sw.js': `
|
|
533
|
+
const oktaLike = '^https://personal\\\\.okta\\\\.com/okta-personal-app/([0-9a-f-]{36})/launch'
|
|
534
|
+
chrome.webNavigation.onBeforeNavigate.addListener((d) => console.log('NAVOKTA:' + d.url), { url: [{ urlMatches: oktaLike }] })
|
|
535
|
+
chrome.webNavigation.onBeforeNavigate.addListener((d) => console.log('NAVORG:' + d.url), { url: [{ hostEquals: 'example.org' }] })
|
|
536
|
+
chrome.webNavigation.onBeforeNavigate.addListener((d) => { if (d.url.includes('11111111-2222')) console.log('NAVALL:' + d.url) })`,
|
|
537
|
+
});
|
|
538
|
+
await ctx.session.extensions.loadExtension(dir);
|
|
539
|
+
await sleep(1000);
|
|
540
|
+
const tab = tabs.create({ url: UUID_IFRAME_PAGE, activate: true });
|
|
541
|
+
await waitFor(() => heard('NAVALL:') > 0, 10_000).catch(() => { });
|
|
542
|
+
tab.wc.loadURL('https://example.org/').catch(() => { });
|
|
543
|
+
await waitFor(() => heard('NAVORG:') > 0, 10_000).catch(() => { });
|
|
544
|
+
tabs.close(tab.id);
|
|
545
|
+
const ok = heard('NAVALL:') > 0 && heard('NAVOKTA:') === 0 && heard('NAVORG:') > 0 && heard('NAVORG:https://example.com') === 0;
|
|
546
|
+
return { pass: ok, detail: `unfiltered=${heard('NAVALL:')} oktaPattern=${heard('NAVOKTA:')} example.org=${heard('NAVORG:')}` };
|
|
547
|
+
});
|
|
548
|
+
await check('Okta does not take over a tab when an iframe URL contains a UUID', async () => {
|
|
549
|
+
const tab = tabs.create({ url: UUID_IFRAME_PAGE, activate: true });
|
|
550
|
+
await waitFor(() => !tab.loading && tab.url.startsWith('data:'), 10_000).catch(() => { });
|
|
551
|
+
await sleep(4000); // the takeover ran within about a second of the iframe navigating
|
|
552
|
+
const url = tab.wc.isDestroyed() ? '(destroyed)' : tab.wc.getURL();
|
|
553
|
+
tabs.close(tab.id);
|
|
554
|
+
return { pass: !url.startsWith('chrome-extension://'), detail: url.slice(0, 120) };
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
await check('closing the window with a push pending does not throw, and takes the UI window with it', async () => {
|
|
558
|
+
ctx.push();
|
|
559
|
+
win.close();
|
|
560
|
+
await sleep(800); // give the push, poll, save and hide timers a chance to fire
|
|
561
|
+
const left = electron_1.BaseWindow.getAllWindows().filter((w) => !w.isDestroyed()).length;
|
|
562
|
+
const ok = uncaught.length === 0 && ctx.quitting && win.isDestroyed() && uiWin.isDestroyed() && ui.isDestroyed() && left === 0;
|
|
563
|
+
return { pass: ok, detail: `windows left=${left} ${uncaught.join(' | ').slice(0, 400)}` };
|
|
564
|
+
});
|
|
565
|
+
const failed = results.filter((r) => !r.pass).length;
|
|
566
|
+
(0, node_fs_1.writeFileSync)((0, node_path_1.join)(OUT, 'results.json'), JSON.stringify({ passed: results.length - failed, failed, results }, null, 2));
|
|
567
|
+
console.log(`[selftest] ${results.length - failed}/${results.length} passed -> ${OUT}`);
|
|
568
|
+
ctx.quitting = true;
|
|
569
|
+
electron_1.app.exit(failed ? 1 : 0);
|
|
570
|
+
}
|
|
@@ -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
|
+
}
|