@lobu/runtime-device 24.1.1 → 24.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/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +26 -28
- package/npm-shrinkwrap.json +155 -172
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -5
- package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
- package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
- package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
- package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
- package/vendor/cli/dist/chrome-extension/background.js +1155 -0
- package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
- package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
- package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
- package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
- package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
- package/vendor/cli/dist/chrome-extension/config.js +144 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
- package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
- package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
- package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
- package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
- package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
- package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
- package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
- package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
- package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
- package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
- package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
- package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
- package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
- package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
- package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
- package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
- package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
- package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
- package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
- package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
- package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
- package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
- package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
- package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
- package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
- package/vendor/cli/dist/chrome-extension/watch.js +348 -0
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
- package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
- package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
- package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
- package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
- package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
- package/vendor/cli/dist/commands/browser.d.ts +23 -0
- package/vendor/cli/dist/commands/browser.js +492 -0
- package/vendor/cli/dist/commands/call.d.ts +12 -0
- package/vendor/cli/dist/commands/call.js +48 -26
- package/vendor/cli/dist/commands/context.d.ts +3 -1
- package/vendor/cli/dist/commands/context.js +13 -2
- package/vendor/cli/dist/commands/daemon.js +2 -152
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
- package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
- package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -17
- package/vendor/cli/dist/commands/memory/run.js +4 -25
- package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
- package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin.ts +1 -1
- package/vendor/cli/dist/connectors/postgres.ts +5 -3
- package/vendor/cli/dist/connectors/reddit.ts +171 -5
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
- package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
- package/vendor/cli/dist/connectors/x.ts +189 -13
- package/vendor/cli/dist/index.js +46 -6
- package/vendor/cli/dist/internal/device-state.d.ts +2 -0
- package/vendor/cli/dist/internal/device-state.js +4 -0
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
- package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +5 -1
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
- package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
- package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
- package/vendor/connector-worker/dist/bin.js +2 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
- package/vendor/connector-worker/dist/daemon/automation.js +2 -12
- package/vendor/connector-worker/dist/daemon/client.d.ts +8 -2
- package/vendor/connector-worker/dist/daemon/client.js +8 -1
- package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
- package/vendor/connector-worker/dist/daemon/poll-loop.js +23 -1
- package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +5 -10
- package/vendor/connector-worker/dist/daemon/terminal-delivery.js +55 -23
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
- package/vendor/connector-worker/dist/executor/isolate.js +3 -0
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/agent-tooling.d.ts +8 -0
- package/vendor/core/dist/agent-tooling.js +9 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +5 -0
- package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
- package/vendor/core/dist/contracts/entity-reference.js +31 -0
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
- package/vendor/core/dist/contracts/tools/manage-automations.js +3 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +113 -34
- package/vendor/core/dist/contracts/tools/manage-entity.js +41 -14
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
- package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
- package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
- package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
- package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
- package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
- package/vendor/core/dist/contracts/worker/protocol.js +20 -0
- package/vendor/core/dist/reserved.d.ts +6 -3
- package/vendor/core/dist/reserved.js +6 -3
- package/vendor/core/dist/worker/auth.d.ts +3 -2
- package/vendor/core/package.json +6 -1
- package/vendor/postgres/cf/src/query.js +3 -1
- package/vendor/postgres/cjs/src/query.js +3 -1
- package/vendor/postgres/src/query.js +3 -1
- /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
// Live-watch controller. Owned by the service worker.
|
|
2
|
+
//
|
|
3
|
+
// Lifecycle:
|
|
4
|
+
// - User toggles "Live input context" in the sidepanel → sidepanel.js
|
|
5
|
+
// writes owletto.watching = true to chrome.storage.local + tells the
|
|
6
|
+
// SW (via chrome.runtime.sendMessage) to start.
|
|
7
|
+
// - SW paints the red recording dot on the toolbar icon
|
|
8
|
+
// (chrome.action.setIcon) + injects watch-observer.js into the active
|
|
9
|
+
// tab, and listens for chrome.tabs.onActivated so observation follows
|
|
10
|
+
// the user across tabs (no badge in the page — the icon is the whole
|
|
11
|
+
// indicator).
|
|
12
|
+
// - The content script streams input + submit events via
|
|
13
|
+
// chrome.runtime.sendMessage; the SW collects them into a bounded
|
|
14
|
+
// ring buffer in chrome.storage.session keyed by tab+ts.
|
|
15
|
+
//
|
|
16
|
+
// The toolbar icon is the ONLY watch indicator, and icon trumps badge:
|
|
17
|
+
// chrome.action.setIcon is used here because the badge text/color is
|
|
18
|
+
// owned by other states (page-activation counts and permission errors).
|
|
19
|
+
// Owning the icon is also why MV3 service-worker restarts need a sync —
|
|
20
|
+
// the persisted owletto.watching flag survives eviction, but the painted
|
|
21
|
+
// icon and the injected observer don't, so syncWatchState re-paints the
|
|
22
|
+
// icon and re-injects the current active HTTP(S) tab on every SW wake.
|
|
23
|
+
//
|
|
24
|
+
// v2: the buffered observations now flow to the gateway like any other
|
|
25
|
+
// ambient feed. `feed_watch_observations` (registered as the
|
|
26
|
+
// chrome.watch_observations feed in background.js) drains the buffer on
|
|
27
|
+
// each scheduled feed run using the same peek-then-commit contract as
|
|
28
|
+
// feeds.js — entries are only dropped after the /stream POST succeeds, so
|
|
29
|
+
// a transient failure preserves them for the next run. The buffer stays
|
|
30
|
+
// SW-local + ephemeral (chrome.storage.session) between drains, and is
|
|
31
|
+
// empty whenever watch is off, so the feed is a no-op cost when unused.
|
|
32
|
+
|
|
33
|
+
import {
|
|
34
|
+
digestBrowserIdentity,
|
|
35
|
+
sanitizeBrowserRecord,
|
|
36
|
+
} from "./browser-url-sanitizer.js";
|
|
37
|
+
import { redactWatchEvent } from "./watch-redact.js";
|
|
38
|
+
|
|
39
|
+
const WATCH_FLAG = "owletto.watching";
|
|
40
|
+
const LIVE_BUFFER_KEY = "owletto.live_buffer";
|
|
41
|
+
const LIVE_BUFFER_MAX = 500;
|
|
42
|
+
const IDENTITY_DIGEST_RE = /^[a-f\d]{64}$/;
|
|
43
|
+
const REDACTION_MARKER_RE =
|
|
44
|
+
/\[REDACTED\]|%(?:25)*5Bredacted%(?:25)*5D|about(?:%(?:25)*3A|:)REDACTED(?![A-Za-z0-9])|(?:=|%(?:25)*3D|,|%(?:25)*2C)REDACTED(?![A-Za-z0-9])/i;
|
|
45
|
+
|
|
46
|
+
function watchIdentityParts(event) {
|
|
47
|
+
if (event?.op === "watch-input") {
|
|
48
|
+
return [event.url, event.field_label || event.tag || "field"];
|
|
49
|
+
}
|
|
50
|
+
if (event?.op === "watch-submit") return [event.url];
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
async function sanitizeWatchEvent(rawEvent) {
|
|
55
|
+
// Credential-shaped typed text is dropped before anything is buffered.
|
|
56
|
+
const event = redactWatchEvent(rawEvent);
|
|
57
|
+
const sanitized = sanitizeBrowserRecord(event);
|
|
58
|
+
if (!event || typeof event !== "object" || !sanitized) return sanitized;
|
|
59
|
+
delete sanitized.identity_digest;
|
|
60
|
+
const rawIdentity = watchIdentityParts(event);
|
|
61
|
+
const safeIdentity = watchIdentityParts(sanitized);
|
|
62
|
+
if (!rawIdentity || !safeIdentity) return sanitized;
|
|
63
|
+
if (JSON.stringify(rawIdentity) !== JSON.stringify(safeIdentity)) {
|
|
64
|
+
sanitized.identity_digest = await digestBrowserIdentity(rawIdentity);
|
|
65
|
+
return sanitized;
|
|
66
|
+
}
|
|
67
|
+
// A retry only has the already-sanitized identity fields. Preserve a digest
|
|
68
|
+
// we previously generated, but never accept an arbitrary non-digest string.
|
|
69
|
+
if (
|
|
70
|
+
typeof event.identity_digest === "string" &&
|
|
71
|
+
IDENTITY_DIGEST_RE.test(event.identity_digest) &&
|
|
72
|
+
rawIdentity.some(
|
|
73
|
+
(value) => typeof value === "string" && REDACTION_MARKER_RE.test(value),
|
|
74
|
+
)
|
|
75
|
+
) {
|
|
76
|
+
sanitized.identity_digest = event.identity_digest;
|
|
77
|
+
}
|
|
78
|
+
return sanitized;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
async function sanitizeWatchBuffer(buffer) {
|
|
82
|
+
return Promise.all(buffer.map((event) => sanitizeWatchEvent(event)));
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Default extension icon vs the red-recording-glyph variant. Paths are
|
|
86
|
+
// relative to the extension root (as chrome.action.setIcon expects).
|
|
87
|
+
export const BASE_ICON = {
|
|
88
|
+
16: "icons/icon-16.png",
|
|
89
|
+
32: "icons/icon-32.png",
|
|
90
|
+
48: "icons/icon-48.png",
|
|
91
|
+
128: "icons/icon-128.png",
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export const WATCH_ICON = {
|
|
95
|
+
16: "icons/icon-16-rec.png",
|
|
96
|
+
32: "icons/icon-32-rec.png",
|
|
97
|
+
48: "icons/icon-48-rec.png",
|
|
98
|
+
128: "icons/icon-128-rec.png",
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
export async function isWatching(chromeApi = chrome) {
|
|
102
|
+
const stored = await chromeApi.storage.local.get(WATCH_FLAG);
|
|
103
|
+
return Boolean(stored[WATCH_FLAG]);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function setWatching(on, chromeApi = chrome) {
|
|
107
|
+
await chromeApi.storage.local.set({ [WATCH_FLAG]: !!on });
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// The single watch indicator is the toolbar icon: red recording glyph while
|
|
111
|
+
// live, base icon otherwise. Never touches setBadgeText — the badge text is
|
|
112
|
+
// owned by page-activation counts and permission-error markers.
|
|
113
|
+
export async function paintWatchIcon(chromeApi, on) {
|
|
114
|
+
await chromeApi.action.setIcon({ path: on ? WATCH_ICON : BASE_ICON });
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
export async function startWatching(chromeApi) {
|
|
118
|
+
await setWatching(true, chromeApi);
|
|
119
|
+
await paintWatchIcon(chromeApi, true);
|
|
120
|
+
await injectActiveTab(chromeApi);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function stopWatching(chromeApi) {
|
|
124
|
+
await setWatching(false, chromeApi);
|
|
125
|
+
await paintWatchIcon(chromeApi, false);
|
|
126
|
+
// Tell any tab that has the observer to clean up.
|
|
127
|
+
const tabs = await chromeApi.tabs.query({});
|
|
128
|
+
for (const t of tabs) {
|
|
129
|
+
if (!t.id) continue;
|
|
130
|
+
try {
|
|
131
|
+
await chromeApi.tabs.sendMessage(t.id, { op: "watch-stop" });
|
|
132
|
+
} catch {
|
|
133
|
+
// Tab has no content script — fine.
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// MV3 service-workers are evicted between events. The persisted
|
|
139
|
+
// owletto.watching flag survives, but the painted icon and injected
|
|
140
|
+
// observer do not. Call at SW startup: re-paint the icon to match the
|
|
141
|
+
// persisted flag, and when live, re-inject the observer into the current
|
|
142
|
+
// active HTTP(S) tab. Both operations are idempotent.
|
|
143
|
+
export async function syncWatchState(chromeApi) {
|
|
144
|
+
const on = await isWatching(chromeApi);
|
|
145
|
+
await paintWatchIcon(chromeApi, on);
|
|
146
|
+
if (on) await injectActiveTab(chromeApi);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const OBSERVER_FILE = "watch-observer.js";
|
|
150
|
+
|
|
151
|
+
// Single injection point. Skips chrome:// and other privileged URLs, and
|
|
152
|
+
// swallows a missing host grant (optional <all_urls> not opted into) — the
|
|
153
|
+
// user just won't get observation on origins without access.
|
|
154
|
+
async function injectObserver(chromeApi, tabId, url) {
|
|
155
|
+
if (!tabId) return;
|
|
156
|
+
if (!/^https?:/.test(url ?? "")) return;
|
|
157
|
+
try {
|
|
158
|
+
await chromeApi.scripting.executeScript({
|
|
159
|
+
target: { tabId },
|
|
160
|
+
files: [OBSERVER_FILE],
|
|
161
|
+
});
|
|
162
|
+
} catch {}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
async function injectActiveTab(chromeApi) {
|
|
166
|
+
const [active] = await chromeApi.tabs.query({ active: true, currentWindow: true });
|
|
167
|
+
if (!active) return;
|
|
168
|
+
await injectObserver(chromeApi, active.id, active.url);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// Hook this from background.js. Two ways the observer stops matching the
|
|
172
|
+
// actively used tab, both of which must re-inject:
|
|
173
|
+
//
|
|
174
|
+
// onActivated — the user switches tabs. Each tab gets its own observer
|
|
175
|
+
// once activated; the previous tab keeps its listeners until tear-down,
|
|
176
|
+
// which is intentional.
|
|
177
|
+
//
|
|
178
|
+
// onUpdated — the user navigates WITHIN a tab. A content script dies with
|
|
179
|
+
// its document, so following a link (or submitting a form, which is the
|
|
180
|
+
// single most common thing this feature observes) silently ended
|
|
181
|
+
// observation while the toolbar dot still claimed it was live. The old
|
|
182
|
+
// in-page pill at least disappeared and told the truth; the icon can't,
|
|
183
|
+
// so the re-injection has to be real. Active tab only — re-injecting
|
|
184
|
+
// into background tabs would observe more than "the tab you're actively
|
|
185
|
+
// using" advertises.
|
|
186
|
+
export function installWatchActivationListener(chromeApi) {
|
|
187
|
+
chromeApi.tabs.onActivated.addListener(async ({ tabId }) => {
|
|
188
|
+
if (!(await isWatching(chromeApi))) return;
|
|
189
|
+
try {
|
|
190
|
+
const tab = await chromeApi.tabs.get(tabId);
|
|
191
|
+
await injectObserver(chromeApi, tabId, tab?.url);
|
|
192
|
+
} catch {}
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
chromeApi.tabs.onUpdated.addListener(async (tabId, changeInfo, tab) => {
|
|
196
|
+
if (changeInfo?.status !== "complete") return;
|
|
197
|
+
if (!tab?.active) return;
|
|
198
|
+
if (!(await isWatching(chromeApi))) return;
|
|
199
|
+
await injectObserver(chromeApi, tabId, tab.url);
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
// Hook from background.js: chrome.runtime.onMessage. Append watch
|
|
204
|
+
// observations to a bounded ring buffer in session storage. (Persistence
|
|
205
|
+
// across browser restarts is deliberately NOT a goal — live observation
|
|
206
|
+
// is supposed to be ephemeral.)
|
|
207
|
+
export async function recordWatchObservation(event) {
|
|
208
|
+
const stored = await chrome.storage.session.get(LIVE_BUFFER_KEY);
|
|
209
|
+
const buf = Array.isArray(stored[LIVE_BUFFER_KEY])
|
|
210
|
+
? await sanitizeWatchBuffer(stored[LIVE_BUFFER_KEY])
|
|
211
|
+
: [];
|
|
212
|
+
buf.push(await sanitizeWatchEvent(event));
|
|
213
|
+
const trimmed = buf.length > LIVE_BUFFER_MAX ? buf.slice(-LIVE_BUFFER_MAX) : buf;
|
|
214
|
+
await chrome.storage.session.set({ [LIVE_BUFFER_KEY]: trimmed });
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
export async function readWatchBuffer() {
|
|
218
|
+
const stored = await chrome.storage.session.get(LIVE_BUFFER_KEY);
|
|
219
|
+
const buf = Array.isArray(stored[LIVE_BUFFER_KEY])
|
|
220
|
+
? await sanitizeWatchBuffer(stored[LIVE_BUFFER_KEY])
|
|
221
|
+
: [];
|
|
222
|
+
if (LIVE_BUFFER_KEY in stored) {
|
|
223
|
+
await chrome.storage.session.set({ [LIVE_BUFFER_KEY]: buf });
|
|
224
|
+
}
|
|
225
|
+
return buf;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
export async function clearWatchBuffer() {
|
|
229
|
+
await chrome.storage.session.remove(LIVE_BUFFER_KEY);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// Consume the first `count` observations from the buffer. Any events that
|
|
233
|
+
// landed between the peek (feed_watch_observations) and this commit are
|
|
234
|
+
// preserved — we only drop the prefix we successfully streamed. Mirrors
|
|
235
|
+
// feeds.js clearBuffered.
|
|
236
|
+
async function consumeWatchBuffer(count) {
|
|
237
|
+
const stored = await chrome.storage.session.get(LIVE_BUFFER_KEY);
|
|
238
|
+
const buf = Array.isArray(stored[LIVE_BUFFER_KEY])
|
|
239
|
+
? await sanitizeWatchBuffer(stored[LIVE_BUFFER_KEY])
|
|
240
|
+
: [];
|
|
241
|
+
const remaining = buf.slice(count);
|
|
242
|
+
if (remaining.length === 0) {
|
|
243
|
+
await chrome.storage.session.remove(LIVE_BUFFER_KEY);
|
|
244
|
+
} else {
|
|
245
|
+
await chrome.storage.session.set({ [LIVE_BUFFER_KEY]: remaining });
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
// Map a buffered watch observation (a `watch-input` / `watch-submit`
|
|
250
|
+
// message from watch-observer.js) to a gateway feed item. Sensitive
|
|
251
|
+
// Values are redacted in the content script and scrubbed again when read from
|
|
252
|
+
// the buffer. Returns null for unknown shapes.
|
|
253
|
+
//
|
|
254
|
+
// The origin id is `watch-<kind>-<sha256>` over the observation identity
|
|
255
|
+
// (URL or its redaction digest, then the field and its typing session's start
|
|
256
|
+
// for input, or the timestamp for submit). The URL and field label are
|
|
257
|
+
// page-controlled and unbounded, and the server rejects a whole batch when any
|
|
258
|
+
// origin_id passes 2048 bytes, so the id never embeds them raw. The hash keeps
|
|
259
|
+
// the id deterministic for the same observation, which upsert dedupe keys on.
|
|
260
|
+
//
|
|
261
|
+
// An input id names the typing SESSION, not the snapshot: watch-observer.js
|
|
262
|
+
// reports a field's value again as the user keeps typing, and each later
|
|
263
|
+
// snapshot must supersede the earlier one on ingest rather than land as a
|
|
264
|
+
// near-duplicate event. An input without a session start is malformed.
|
|
265
|
+
async function toWatchItem(e) {
|
|
266
|
+
e = sanitizeBrowserRecord(redactWatchEvent(e));
|
|
267
|
+
const ts = e?.ts ?? new Date().toISOString();
|
|
268
|
+
const identity = e?.identity_digest
|
|
269
|
+
? `redacted-${e.identity_digest}`
|
|
270
|
+
: e?.url;
|
|
271
|
+
if (e?.op === "watch-input") {
|
|
272
|
+
if (typeof e.session_started_at !== "string") return null;
|
|
273
|
+
const field = e.field_label || e.tag || "field";
|
|
274
|
+
const originId = `watch-input-${await digestBrowserIdentity([identity, e.session_started_at, field])}`;
|
|
275
|
+
return sanitizeBrowserRecord({
|
|
276
|
+
id: originId,
|
|
277
|
+
title: `Typed in ${field}`,
|
|
278
|
+
payload_type: "text",
|
|
279
|
+
payload_text: `Typed in "${field}" on ${e.url}: ${e.value ?? ""}`,
|
|
280
|
+
occurred_at: ts,
|
|
281
|
+
source_url: e.url,
|
|
282
|
+
origin_type: "watch_observation",
|
|
283
|
+
semantic_type: "watch_observation",
|
|
284
|
+
metadata: {
|
|
285
|
+
source: "chrome_watch",
|
|
286
|
+
origin_id: originId,
|
|
287
|
+
event_type: "input",
|
|
288
|
+
url: e.url,
|
|
289
|
+
field_label: e.field_label,
|
|
290
|
+
tag: e.tag,
|
|
291
|
+
type: e.type,
|
|
292
|
+
length: e.length,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
if (e?.op === "watch-submit") {
|
|
297
|
+
const originId = `watch-submit-${await digestBrowserIdentity([identity, ts])}`;
|
|
298
|
+
const summary = Array.isArray(e.fields)
|
|
299
|
+
? e.fields.map((f) => `${f.label}: ${f.value}`).join("; ")
|
|
300
|
+
: "";
|
|
301
|
+
return sanitizeBrowserRecord({
|
|
302
|
+
id: originId,
|
|
303
|
+
title: `Submitted form on ${e.url}`,
|
|
304
|
+
payload_type: "text",
|
|
305
|
+
payload_text: summary
|
|
306
|
+
? `Submitted form on ${e.url} — ${summary}`
|
|
307
|
+
: `Submitted form on ${e.url}`,
|
|
308
|
+
occurred_at: ts,
|
|
309
|
+
source_url: e.url,
|
|
310
|
+
origin_type: "watch_observation",
|
|
311
|
+
semantic_type: "watch_observation",
|
|
312
|
+
metadata: {
|
|
313
|
+
source: "chrome_watch",
|
|
314
|
+
origin_id: originId,
|
|
315
|
+
event_type: "submit",
|
|
316
|
+
url: e.url,
|
|
317
|
+
form_action: e.form_action,
|
|
318
|
+
fields: e.fields,
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
}
|
|
322
|
+
return null;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
// Feed run (peek-then-commit, same contract as feeds.js): emit the
|
|
326
|
+
// buffered watch observations as feed items; commit drops only the prefix
|
|
327
|
+
// we streamed. Empty (and cheap) whenever watch is off.
|
|
328
|
+
export async function feed_watch_observations() {
|
|
329
|
+
const buf = await readWatchBuffer();
|
|
330
|
+
// Capture the consumed count at peek time — don't read buf.length lazily in
|
|
331
|
+
// the commit closure, so we drop exactly what we streamed regardless of
|
|
332
|
+
// whether storage handed back a live reference or a clone.
|
|
333
|
+
const consumed = buf.length;
|
|
334
|
+
// Several snapshots of one typing session can wait in the buffer; send only
|
|
335
|
+
// the latest per origin id (the buffer is in arrival order).
|
|
336
|
+
const latest = new Map();
|
|
337
|
+
for (const item of (await Promise.all(buf.map(toWatchItem))).filter(Boolean)) {
|
|
338
|
+
latest.delete(item.id);
|
|
339
|
+
latest.set(item.id, item);
|
|
340
|
+
}
|
|
341
|
+
const items = [...latest.values()];
|
|
342
|
+
return {
|
|
343
|
+
items,
|
|
344
|
+
commit: async () => {
|
|
345
|
+
await consumeWatchBuffer(consumed);
|
|
346
|
+
},
|
|
347
|
+
};
|
|
348
|
+
}
|
|
@@ -199,10 +199,11 @@ export interface DesiredConnectorDefinition {
|
|
|
199
199
|
key: string | null;
|
|
200
200
|
/**
|
|
201
201
|
* Best-effort static `definition.key` parsed from `sourceCode` WITHOUT a
|
|
202
|
-
* compile. Used
|
|
202
|
+
* compile. Used to widen the pre-diff schema-skip set so re-applying a
|
|
203
203
|
* local connector whose feed set changed doesn't validate the connection
|
|
204
|
-
* against the stale server schema
|
|
205
|
-
* stays the authoritative
|
|
204
|
+
* against the stale server schema, and to label the plan row update vs
|
|
205
|
+
* create. NOT used for pruning — `key` stays the authoritative
|
|
206
|
+
* (server-compiled) value there.
|
|
206
207
|
*/
|
|
207
208
|
declaredKeyHint?: string;
|
|
208
209
|
/** Local `.ts` path (absolute) — mutually exclusive with `sourceUrl`. */
|
|
@@ -421,7 +422,8 @@ interface LoadDesiredStateOptions {
|
|
|
421
422
|
* key: "linkedin", ...`. Returns `null` when the shape can't be matched with
|
|
422
423
|
* confidence, preserving the prior null-key semantics (the server remains the
|
|
423
424
|
* authoritative source of the compiled key; this hint only affects which
|
|
424
|
-
* connectors the pre-diff pass treats as locally-declared
|
|
425
|
+
* connectors the pre-diff pass treats as locally-declared, and the plan's
|
|
426
|
+
* update/create label).
|
|
425
427
|
*/
|
|
426
428
|
export declare function extractDeclaredConnectorKey(sourceCode: string): string | null;
|
|
427
429
|
/**
|
|
@@ -381,7 +381,8 @@ export function validateAuthProfileAgainstConnector(profile, schemas) {
|
|
|
381
381
|
* key: "linkedin", ...`. Returns `null` when the shape can't be matched with
|
|
382
382
|
* confidence, preserving the prior null-key semantics (the server remains the
|
|
383
383
|
* authoritative source of the compiled key; this hint only affects which
|
|
384
|
-
* connectors the pre-diff pass treats as locally-declared
|
|
384
|
+
* connectors the pre-diff pass treats as locally-declared, and the plan's
|
|
385
|
+
* update/create label).
|
|
385
386
|
*/
|
|
386
387
|
export function extractDeclaredConnectorKey(sourceCode) {
|
|
387
388
|
// Anchor on the `definition` assignment so we don't pick up an unrelated
|
|
@@ -428,8 +429,9 @@ function resolveConnectorSources(sources, cwd) {
|
|
|
428
429
|
// `key` stays null: the server compiles the source and is the
|
|
429
430
|
// authoritative source of the real key, and null-ness gates the diff /
|
|
430
431
|
// prune logic (see diff.ts `hasUnnamedLocalDefs`). We keep a separate
|
|
431
|
-
// best-effort static hint (no compile)
|
|
432
|
-
// schema-skip set
|
|
432
|
+
// best-effort static hint (no compile) to widen the pre-diff
|
|
433
|
+
// schema-skip set (see `localConnectorKeyHints` in apply-cmd) and to label
|
|
434
|
+
// the plan row (diff.ts `diffConnectorDefinition`). Without it,
|
|
433
435
|
// re-applying a connector whose feed set changed (e.g. folding takeout
|
|
434
436
|
// feeds into `linkedin`) validates the connection against the STALE
|
|
435
437
|
// server schema and rejects the new feeds.
|
|
@@ -1122,9 +1122,10 @@ function diffConnectorDefinition(desired, installedKeys) {
|
|
|
1122
1122
|
// hash is of the *compiled* output) — so we always emit a "sync" row;
|
|
1123
1123
|
// `install_connector` is idempotent and reports `updated:false` on apply
|
|
1124
1124
|
// when the code is byte-identical, so this never churns remote state.
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1125
|
+
// Local files have no resolved key during planning; the static hint lets
|
|
1126
|
+
// the plan recognise an installed definition without compiling the source.
|
|
1127
|
+
const key = desired.key ?? desired.declaredKeyHint;
|
|
1128
|
+
const installedRemotely = key ? installedKeys.has(key) : false;
|
|
1128
1129
|
return {
|
|
1129
1130
|
kind: "connector-definition",
|
|
1130
1131
|
// "update" (re-push) when already installed; `install_connector` is
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export interface ResolveBrowserOptions {
|
|
2
|
+
fetchImpl?: typeof fetch;
|
|
3
|
+
now?: () => number;
|
|
4
|
+
log?: (message: string) => void;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* The Chrome for Testing executable for named browsers. Uses the cached Stable
|
|
8
|
+
* build, checking Google for a newer one at most once a day; a failed check
|
|
9
|
+
* falls back to the newest cached build. `LOBU_BROWSER_PATH` points at an
|
|
10
|
+
* existing Chromium or Chrome for Testing binary instead.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveBrowserExecutable(options?: ResolveBrowserOptions): Promise<string>;
|
|
13
|
+
//# sourceMappingURL=chrome-for-testing.d.ts.map
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
import { createWriteStream, existsSync } from "node:fs";
|
|
3
|
+
import { mkdir, mkdtemp, readdir, readFile, rename, rm, writeFile, } from "node:fs/promises";
|
|
4
|
+
import { homedir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { Readable } from "node:stream";
|
|
7
|
+
import { pipeline } from "node:stream/promises";
|
|
8
|
+
import { promisify } from "node:util";
|
|
9
|
+
// `lobu browser` runs Chrome for Testing, not the user's Google Chrome: branded
|
|
10
|
+
// Chrome ignores --load-extension, which is how the Lobu extension gets into a
|
|
11
|
+
// named browser. Google publishes the builds and this version index.
|
|
12
|
+
const VERSIONS_URL = "https://googlechromelabs.github.io/chrome-for-testing/last-known-good-versions-with-downloads.json";
|
|
13
|
+
const DOWNLOAD_HOST = "storage.googleapis.com";
|
|
14
|
+
/** How often `start` asks Google for a newer Stable build. */
|
|
15
|
+
const CHECK_INTERVAL_MS = 24 * 60 * 60 * 1000;
|
|
16
|
+
const MAX_ARCHIVE_BYTES = 1024 * 1024 * 1024;
|
|
17
|
+
const VERSION_PATTERN = /^\d+(\.\d+)+$/;
|
|
18
|
+
const execFileAsync = promisify(execFile);
|
|
19
|
+
function cacheRoot() {
|
|
20
|
+
return join(homedir(), ".cache", "lobu", "chrome-for-testing");
|
|
21
|
+
}
|
|
22
|
+
function chromePlatform() {
|
|
23
|
+
if (process.platform === "darwin") {
|
|
24
|
+
return process.arch === "arm64" ? "mac-arm64" : "mac-x64";
|
|
25
|
+
}
|
|
26
|
+
if (process.platform === "linux") {
|
|
27
|
+
if (process.arch === "x64")
|
|
28
|
+
return "linux64";
|
|
29
|
+
if (process.arch === "arm64")
|
|
30
|
+
return "linux-arm64";
|
|
31
|
+
}
|
|
32
|
+
throw new Error(`lobu browser supports macOS and Linux on x64 or arm64, not ${process.platform}/${process.arch}.`);
|
|
33
|
+
}
|
|
34
|
+
function executablePath(versionDir, platform) {
|
|
35
|
+
const root = join(versionDir, `chrome-${platform}`);
|
|
36
|
+
return platform.startsWith("mac")
|
|
37
|
+
? join(root, "Google Chrome for Testing.app", "Contents", "MacOS", "Google Chrome for Testing")
|
|
38
|
+
: join(root, "chrome");
|
|
39
|
+
}
|
|
40
|
+
/** A build is usable once fully unpacked and marked complete. */
|
|
41
|
+
function isInstalled(versionDir, platform) {
|
|
42
|
+
return (existsSync(join(versionDir, ".complete")) &&
|
|
43
|
+
existsSync(executablePath(versionDir, platform)));
|
|
44
|
+
}
|
|
45
|
+
function compareVersions(a, b) {
|
|
46
|
+
const left = a.split(".").map(Number);
|
|
47
|
+
const right = b.split(".").map(Number);
|
|
48
|
+
for (let i = 0; i < Math.max(left.length, right.length); i++) {
|
|
49
|
+
const diff = (left[i] ?? 0) - (right[i] ?? 0);
|
|
50
|
+
if (diff !== 0)
|
|
51
|
+
return diff;
|
|
52
|
+
}
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
async function installedVersions(root, platform) {
|
|
56
|
+
let entries;
|
|
57
|
+
try {
|
|
58
|
+
entries = await readdir(root);
|
|
59
|
+
}
|
|
60
|
+
catch {
|
|
61
|
+
return [];
|
|
62
|
+
}
|
|
63
|
+
return entries
|
|
64
|
+
.filter((entry) => VERSION_PATTERN.test(entry) && isInstalled(join(root, entry), platform))
|
|
65
|
+
.sort(compareVersions);
|
|
66
|
+
}
|
|
67
|
+
async function readLatest(root) {
|
|
68
|
+
try {
|
|
69
|
+
const parsed = JSON.parse(await readFile(join(root, "latest.json"), "utf8"));
|
|
70
|
+
return typeof parsed.version === "string" &&
|
|
71
|
+
typeof parsed.checkedAt === "number"
|
|
72
|
+
? { version: parsed.version, checkedAt: parsed.checkedAt }
|
|
73
|
+
: null;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
async function fetchStable(platform, fetchImpl) {
|
|
80
|
+
const response = await fetchImpl(VERSIONS_URL, {
|
|
81
|
+
signal: AbortSignal.timeout(15_000),
|
|
82
|
+
});
|
|
83
|
+
if (!response.ok) {
|
|
84
|
+
throw new Error(`Chrome for Testing version index returned ${response.status}`);
|
|
85
|
+
}
|
|
86
|
+
const index = (await response.json());
|
|
87
|
+
const stable = index.channels?.Stable;
|
|
88
|
+
const url = stable?.downloads?.chrome?.find((entry) => entry.platform === platform)?.url;
|
|
89
|
+
if (!stable?.version || !VERSION_PATTERN.test(stable.version) || !url) {
|
|
90
|
+
throw new Error(`Chrome for Testing has no Stable build for ${platform}`);
|
|
91
|
+
}
|
|
92
|
+
const parsed = new URL(url);
|
|
93
|
+
if (parsed.protocol !== "https:" || parsed.hostname !== DOWNLOAD_HOST) {
|
|
94
|
+
throw new Error(`Unexpected Chrome for Testing download origin: ${parsed.origin}`);
|
|
95
|
+
}
|
|
96
|
+
return { version: stable.version, url };
|
|
97
|
+
}
|
|
98
|
+
async function download(url, file, fetchImpl) {
|
|
99
|
+
const response = await fetchImpl(url, {
|
|
100
|
+
signal: AbortSignal.timeout(15 * 60_000),
|
|
101
|
+
});
|
|
102
|
+
if (!response.ok || !response.body) {
|
|
103
|
+
throw new Error(`Chrome for Testing download failed (${response.status})`);
|
|
104
|
+
}
|
|
105
|
+
await pipeline(Readable.fromWeb(response.body), async function* limit(chunks) {
|
|
106
|
+
let bytes = 0;
|
|
107
|
+
for await (const chunk of chunks) {
|
|
108
|
+
bytes += chunk.length;
|
|
109
|
+
if (bytes > MAX_ARCHIVE_BYTES) {
|
|
110
|
+
throw new Error("Chrome for Testing archive exceeds 1 GiB");
|
|
111
|
+
}
|
|
112
|
+
yield chunk;
|
|
113
|
+
}
|
|
114
|
+
}, createWriteStream(file));
|
|
115
|
+
}
|
|
116
|
+
async function unzip(archive, destination) {
|
|
117
|
+
// macOS: ditto keeps the app bundle's framework symlinks and permissions.
|
|
118
|
+
const [command, args] = process.platform === "darwin"
|
|
119
|
+
? ["ditto", ["-x", "-k", archive, destination]]
|
|
120
|
+
: ["unzip", ["-q", archive, "-d", destination]];
|
|
121
|
+
try {
|
|
122
|
+
await execFileAsync(command, args, { maxBuffer: 16 * 1024 * 1024 });
|
|
123
|
+
}
|
|
124
|
+
catch (error) {
|
|
125
|
+
const missing = error.code === "ENOENT";
|
|
126
|
+
throw new Error(missing
|
|
127
|
+
? `\`${command}\` is required to unpack Chrome for Testing; install it and retry.`
|
|
128
|
+
: `Could not unpack Chrome for Testing: ${error instanceof Error ? error.message : String(error)}`);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
async function install(root, version, url, platform, fetchImpl, log) {
|
|
132
|
+
const staging = await mkdtemp(join(root, `.staging-${version}-`));
|
|
133
|
+
try {
|
|
134
|
+
log(`Downloading Chrome for Testing ${version}…`);
|
|
135
|
+
const archive = join(staging, "chrome.zip");
|
|
136
|
+
await download(url, archive, fetchImpl);
|
|
137
|
+
await unzip(archive, staging);
|
|
138
|
+
await rm(archive);
|
|
139
|
+
if (!existsSync(executablePath(staging, platform))) {
|
|
140
|
+
throw new Error("Chrome for Testing archive has an unexpected layout");
|
|
141
|
+
}
|
|
142
|
+
await writeFile(join(staging, ".complete"), `${version}\n`);
|
|
143
|
+
const target = join(root, version);
|
|
144
|
+
try {
|
|
145
|
+
await rename(staging, target);
|
|
146
|
+
}
|
|
147
|
+
catch (error) {
|
|
148
|
+
// Another start may have published the same build while we downloaded.
|
|
149
|
+
// Never replace it: a browser may already be executing from that path.
|
|
150
|
+
const code = error.code;
|
|
151
|
+
if ((code !== "EEXIST" && code !== "ENOTEMPTY") ||
|
|
152
|
+
!isInstalled(target, platform)) {
|
|
153
|
+
throw error;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
finally {
|
|
158
|
+
await rm(staging, { recursive: true, force: true });
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* Delete superseded builds that no running process was started from. A named
|
|
163
|
+
* browser can stay open across several updates and keeps loading resources
|
|
164
|
+
* from its own build, so only the process table proves a build is unused.
|
|
165
|
+
*/
|
|
166
|
+
async function prune(root, current, platform) {
|
|
167
|
+
let processes;
|
|
168
|
+
try {
|
|
169
|
+
({ stdout: processes } = await execFileAsync("ps", ["-axww", "-o", "command="], { maxBuffer: 64 * 1024 * 1024 }));
|
|
170
|
+
}
|
|
171
|
+
catch {
|
|
172
|
+
return;
|
|
173
|
+
}
|
|
174
|
+
for (const version of await installedVersions(root, platform)) {
|
|
175
|
+
const dir = join(root, version);
|
|
176
|
+
if (version !== current && !processes.includes(`${dir}/`)) {
|
|
177
|
+
await rm(dir, { recursive: true, force: true });
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* The Chrome for Testing executable for named browsers. Uses the cached Stable
|
|
183
|
+
* build, checking Google for a newer one at most once a day; a failed check
|
|
184
|
+
* falls back to the newest cached build. `LOBU_BROWSER_PATH` points at an
|
|
185
|
+
* existing Chromium or Chrome for Testing binary instead.
|
|
186
|
+
*/
|
|
187
|
+
export async function resolveBrowserExecutable(options = {}) {
|
|
188
|
+
const override = process.env.LOBU_BROWSER_PATH?.trim();
|
|
189
|
+
if (override) {
|
|
190
|
+
if (!existsSync(override)) {
|
|
191
|
+
throw new Error(`LOBU_BROWSER_PATH points at a missing file: ${override}`);
|
|
192
|
+
}
|
|
193
|
+
return override;
|
|
194
|
+
}
|
|
195
|
+
const fetchImpl = options.fetchImpl ?? fetch;
|
|
196
|
+
const now = options.now ?? Date.now;
|
|
197
|
+
const log = options.log ?? ((message) => console.error(message));
|
|
198
|
+
const platform = chromePlatform();
|
|
199
|
+
const root = cacheRoot();
|
|
200
|
+
await mkdir(root, { recursive: true });
|
|
201
|
+
const installed = await installedVersions(root, platform);
|
|
202
|
+
const latest = await readLatest(root);
|
|
203
|
+
if (latest &&
|
|
204
|
+
now() - latest.checkedAt < CHECK_INTERVAL_MS &&
|
|
205
|
+
installed.includes(latest.version)) {
|
|
206
|
+
return executablePath(join(root, latest.version), platform);
|
|
207
|
+
}
|
|
208
|
+
let stable;
|
|
209
|
+
try {
|
|
210
|
+
stable = await fetchStable(platform, fetchImpl);
|
|
211
|
+
}
|
|
212
|
+
catch (error) {
|
|
213
|
+
const newest = installed.at(-1);
|
|
214
|
+
if (!newest)
|
|
215
|
+
throw error;
|
|
216
|
+
log(`Could not check for a newer Chrome for Testing (${error instanceof Error ? error.message : String(error)}); using ${newest}.`);
|
|
217
|
+
return executablePath(join(root, newest), platform);
|
|
218
|
+
}
|
|
219
|
+
if (!installed.includes(stable.version)) {
|
|
220
|
+
await install(root, stable.version, stable.url, platform, fetchImpl, log);
|
|
221
|
+
await prune(root, stable.version, platform);
|
|
222
|
+
}
|
|
223
|
+
await writeFile(join(root, "latest.json"), `${JSON.stringify({ version: stable.version, checkedAt: now() })}\n`);
|
|
224
|
+
return executablePath(join(root, stable.version), platform);
|
|
225
|
+
}
|
|
226
|
+
//# sourceMappingURL=chrome-for-testing.js.map
|