@revoengine/cli 1.0.38 → 2.0.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/CHANGELOG.md +33 -0
- package/README.md +22 -10
- package/dist/src/argument-contract.js +5 -5
- package/dist/src/automation-contract.generated.d.ts +6 -30
- package/dist/src/automation-contract.generated.js +6 -30
- package/dist/src/client.d.ts +2 -2
- package/dist/src/client.js +4 -14
- package/dist/src/commands/component.js +16 -0
- package/dist/src/commands/database-tables.js +1 -1
- package/dist/src/commands/emulate.js +67 -74
- package/dist/src/commands/terminal-browser-human-input.d.ts +28 -0
- package/dist/src/commands/terminal-browser-human-input.js +56 -7
- package/dist/src/commands/terminal-browser-live-protocol.d.ts +13 -1
- package/dist/src/commands/terminal-browser-live-protocol.js +20 -4
- package/dist/src/commands/terminal-browser-live-transport.d.ts +2 -0
- package/dist/src/commands/terminal-browser-live-transport.js +21 -4
- package/dist/src/commands/terminal-browser-live.d.ts +36 -1
- package/dist/src/commands/terminal-browser-live.js +435 -106
- package/dist/src/commands/terminal-browser-observation.d.ts +1 -1
- package/dist/src/commands/terminal-browser-observation.js +10 -1
- package/dist/src/commands/terminal-browser-page-input.d.ts +1 -0
- package/dist/src/commands/terminal-browser-page-input.js +20 -0
- package/dist/src/commands/terminal-browser-profile-sync.d.ts +5 -1
- package/dist/src/commands/terminal-browser-profile-sync.js +13 -2
- package/dist/src/commands/terminal-browser-profile-sync.protocol.d.ts +2 -0
- package/dist/src/commands/terminal-browser-recording.d.ts +6 -3
- package/dist/src/commands/terminal-browser-recording.js +45 -15
- package/dist/src/commands/terminal-browser.d.ts +17 -0
- package/dist/src/commands/terminal-browser.js +318 -111
- package/dist/src/commands/terminal-operational-log.js +2 -1
- package/dist/src/commands/terminal-output-buffer.d.ts +2 -0
- package/dist/src/commands/terminal-output-buffer.js +6 -0
- package/dist/src/commands/terminal-reconnect-grace.d.ts +1 -0
- package/dist/src/commands/terminal-reconnect-grace.js +1 -0
- package/dist/src/commands/terminal-sandbox.js +22 -6
- package/dist/src/commands/terminal.js +136 -40
- package/dist/src/endpoint-emulator.d.ts +16 -13
- package/dist/src/endpoint-emulator.js +26 -35
- package/dist/src/project.js +1 -0
- package/dist/src/request-contract.d.ts +2 -0
- package/dist/src/request-contract.js +11 -1
- package/dist/src/resource-syncs/database-table-sync.d.ts +2 -1
- package/dist/src/resource-syncs/database-table-sync.js +60 -23
- package/dist/src/sync-omit.js +1 -1
- package/dist/src/types.d.ts +0 -3
- package/dist/src/ui.js +2 -2
- package/package.json +1 -1
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import { canUseOtherBrowserTab } from "./terminal-browser-live-protocol.js";
|
|
1
2
|
import fs from 'node:fs';
|
|
2
3
|
import { readPublicWebPage } from "./terminal-public-web.js";
|
|
3
4
|
import path from 'node:path';
|
|
4
5
|
import { randomUUID } from 'node:crypto';
|
|
6
|
+
import { clipTerminalText } from "./terminal-output-buffer.js";
|
|
5
7
|
import { browserProfileScopeId } from "./terminal-browser-profile.js";
|
|
6
8
|
import { validBrowserInteraction } from "./terminal-browser-interaction.js";
|
|
7
9
|
import { BrowserObservations } from "./terminal-browser-observation.js";
|
|
@@ -10,8 +12,10 @@ import { applyPageInteraction, clearSecretInputs, releasePageInput, describeFocu
|
|
|
10
12
|
const MAX_BROWSER_SESSIONS = 4;
|
|
11
13
|
const BROWSER_SESSION_IDLE_MS = 60 * 60_000;
|
|
12
14
|
const MAX_BROWSER_TABS = 16;
|
|
15
|
+
const MAX_SHARED_TABS = 32;
|
|
13
16
|
const browserSessions = new Map();
|
|
14
|
-
const creatingSessions = new
|
|
17
|
+
const creatingSessions = new Map();
|
|
18
|
+
const sharedContexts = new Map();
|
|
15
19
|
const sessionQueues = new Map();
|
|
16
20
|
const FORM_ACTIONS = new Set(['click', 'fill', 'check', 'select', 'press']);
|
|
17
21
|
const INTERACTIVE_ACTIONS = new Set([...FORM_ACTIONS, 'scroll', 'interact']);
|
|
@@ -139,6 +143,15 @@ async function closeSession(id, options = {}) {
|
|
|
139
143
|
await session.live?.settled();
|
|
140
144
|
if (session.networkLeaseTimer)
|
|
141
145
|
clearTimeout(session.networkLeaseTimer);
|
|
146
|
+
if (session.shared) {
|
|
147
|
+
try {
|
|
148
|
+
await Promise.all([...session.tabs.values()].map(page => page.close().catch(() => undefined)));
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await releaseSharedMember(id, session.shared, session.sharedMember);
|
|
152
|
+
}
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
142
155
|
try {
|
|
143
156
|
await session.browser.close().catch(() => undefined);
|
|
144
157
|
}
|
|
@@ -147,9 +160,32 @@ async function closeSession(id, options = {}) {
|
|
|
147
160
|
await session.authProfile?.release();
|
|
148
161
|
}
|
|
149
162
|
}
|
|
163
|
+
async function releaseSharedMember(id, group, member) {
|
|
164
|
+
if (!group.members.delete(id))
|
|
165
|
+
return;
|
|
166
|
+
if (!group.members.size) {
|
|
167
|
+
// Dispose the lease before yielding so a late command cannot recreate this generation.
|
|
168
|
+
sharedContexts.delete(member.contextId);
|
|
169
|
+
const released = group.profile.lease.release();
|
|
170
|
+
const resources = await group.resources.catch(() => undefined);
|
|
171
|
+
await resources?.browser.close().catch(() => undefined);
|
|
172
|
+
await released;
|
|
173
|
+
}
|
|
174
|
+
await member.releaseMember();
|
|
175
|
+
}
|
|
150
176
|
async function checkpointProfile(session) {
|
|
151
177
|
if (!session.authProfile)
|
|
152
178
|
return;
|
|
179
|
+
if (session.shared) {
|
|
180
|
+
const group = session.shared;
|
|
181
|
+
const save = group.snapshots.then(async () => {
|
|
182
|
+
if (!session.sharedMember?.authorized())
|
|
183
|
+
throw new Error('browser_profile_lease_expired');
|
|
184
|
+
await group.profile.lease.save(await session.context.storageState({ indexedDB: true }));
|
|
185
|
+
});
|
|
186
|
+
group.snapshots = save.catch(() => undefined);
|
|
187
|
+
return save;
|
|
188
|
+
}
|
|
153
189
|
session.snapshotting = true;
|
|
154
190
|
try {
|
|
155
191
|
await session.authProfile.save(await session.context.storageState({ indexedDB: true }));
|
|
@@ -223,7 +259,7 @@ export async function reconcileBrowserSessions(networkMode, policyGrantRevision)
|
|
|
223
259
|
if (session.threadScope && policyGrantRevision !== undefined
|
|
224
260
|
&& session.threadScope.policyGrantRevision !== policyGrantRevision)
|
|
225
261
|
return true;
|
|
226
|
-
if (!permanent && !session.threadScope
|
|
262
|
+
if (!permanent && !session.threadScope && !session.shared
|
|
227
263
|
&& (session.networkAccessExpiresAt === null || session.networkAccessExpiresAt <= now))
|
|
228
264
|
return true;
|
|
229
265
|
setNetworkLease(id, session, session.networkAccessExpiresAt);
|
|
@@ -241,50 +277,46 @@ export async function closeThreadBrowserSession(browserSessionId) {
|
|
|
241
277
|
await closeSession(browserSessionId);
|
|
242
278
|
}
|
|
243
279
|
export function browserSessionIds() { return [...browserSessions.keys()]; }
|
|
280
|
+
/** Local runner display. Authentication itself is known only to the website. */
|
|
281
|
+
export function browserRuntimeInventory() {
|
|
282
|
+
const contexts = new Set();
|
|
283
|
+
const sessions = [...browserSessions].flatMap(([id, session]) => {
|
|
284
|
+
if (!session.browser.isConnected())
|
|
285
|
+
return [];
|
|
286
|
+
const tabs = [...session.tabs.values()].filter(page => !page.isClosed()).length;
|
|
287
|
+
if (!tabs)
|
|
288
|
+
return [];
|
|
289
|
+
contexts.add(session.context);
|
|
290
|
+
const name = session.centralProfile?.name || session.profileScope?.name;
|
|
291
|
+
return [{ id: id.slice(0, 8), tabs, mode: session.control.mode,
|
|
292
|
+
profile: name?.replace(/[\p{C}\p{Zl}\p{Zp}]/gu, '').slice(0, 64) || null,
|
|
293
|
+
restored: !!session.authProfile?.state }];
|
|
294
|
+
});
|
|
295
|
+
return { browsers: contexts.size, tabs: sessions.reduce((total, session) => total + session.tabs, 0), sessions };
|
|
296
|
+
}
|
|
244
297
|
export function hasBrowserSessions() { return browserSessions.size > 0; }
|
|
245
298
|
/** Revocation closes only this central context and never checkpoints its authentication. */
|
|
246
299
|
export async function revokeBrowserProfileSession(browserSessionId, profileId) {
|
|
247
300
|
if (browserSessions.get(browserSessionId)?.centralProfile?.id === profileId)
|
|
248
301
|
await closeSession(browserSessionId);
|
|
249
302
|
}
|
|
250
|
-
async function
|
|
251
|
-
await
|
|
252
|
-
if (browserSessions.size + creatingSessions.size >= MAX_BROWSER_SESSIONS)
|
|
253
|
-
throw new Error('browser_session_limit');
|
|
254
|
-
creatingSessions.add(id);
|
|
255
|
-
let profileLease;
|
|
256
|
-
try {
|
|
257
|
-
profileLease = centralProfile?.lease ?? (authProfile ? await authProfile.store.openAsync(authProfile.scope) : undefined);
|
|
258
|
-
}
|
|
259
|
-
catch (error) {
|
|
260
|
-
creatingSessions.delete(id);
|
|
261
|
-
throw error;
|
|
262
|
-
}
|
|
263
|
-
const epoch = sessionEpoch;
|
|
264
|
-
const { chromium } = await import('playwright-core').catch(async (error) => {
|
|
265
|
-
await profileLease?.release();
|
|
266
|
-
creatingSessions.delete(id);
|
|
267
|
-
throw error;
|
|
268
|
-
});
|
|
303
|
+
async function createBrowserContext(localOnly, width, height, owner, profileLease) {
|
|
304
|
+
const { chromium } = await import('playwright-core');
|
|
269
305
|
const browser = await chromium.launch({ channel: 'chromium', headless: true, ignoreDefaultArgs: ['--hide-scrollbars'],
|
|
270
306
|
args: localOnly ? ['--disable-background-networking',
|
|
271
307
|
'--host-resolver-rules=MAP localhost 127.0.0.1'] : [] }).catch(error => {
|
|
272
308
|
if (error instanceof Error && error.message.includes("Executable doesn't exist at"))
|
|
273
309
|
throw new Error('browser_binary_unavailable');
|
|
274
310
|
throw error;
|
|
275
|
-
})
|
|
276
|
-
const onAbort = () => { void browser.close(); };
|
|
277
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
311
|
+
});
|
|
278
312
|
try {
|
|
279
|
-
if (signal?.aborted)
|
|
280
|
-
throw new Error('browser_cancelled');
|
|
281
313
|
const context = await browser.newContext({ viewport: { width, height }, acceptDownloads: false,
|
|
282
314
|
serviceWorkers: localOnly ? 'block' : 'allow' });
|
|
283
315
|
const geometryBinding = 'revoGeometry_' + randomUUID().replaceAll('-', '');
|
|
284
316
|
await context.exposeBinding(geometryBinding, ({ page }) => {
|
|
285
|
-
const session =
|
|
317
|
+
const session = owner(page);
|
|
286
318
|
if (session && session.tabs.size && [...session.tabs.values()].includes(page))
|
|
287
|
-
session.observations.invalidate();
|
|
319
|
+
session.observations.invalidate(page);
|
|
288
320
|
});
|
|
289
321
|
await context.addInitScript(({ binding }) => {
|
|
290
322
|
const invalidate = () => { void Reflect.get(globalThis, binding)().catch(() => undefined); };
|
|
@@ -305,7 +337,12 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
305
337
|
await context.route('**/*', async (route) => {
|
|
306
338
|
try {
|
|
307
339
|
(localOnly ? localBrowserUrl : browserUrl)(route.request().url());
|
|
308
|
-
|
|
340
|
+
let page;
|
|
341
|
+
try {
|
|
342
|
+
page = route.request().frame().page();
|
|
343
|
+
}
|
|
344
|
+
catch { /* An initial popup request may lack a frame. */ }
|
|
345
|
+
const live = page && owner(page)?.live;
|
|
309
346
|
// Do not evaluate the page while holding a navigation route: evaluation can
|
|
310
347
|
// wait for that very navigation. Fence capture, then let the request continue.
|
|
311
348
|
if (route.request().isNavigationRequest() && browserAuthPage(route.request().url()) && live && !live.private)
|
|
@@ -329,14 +366,79 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
329
366
|
socket.close();
|
|
330
367
|
}
|
|
331
368
|
});
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
369
|
+
const state = profileLease?.state;
|
|
370
|
+
if (state)
|
|
371
|
+
await context.setStorageState(state);
|
|
372
|
+
return { browser, context };
|
|
373
|
+
}
|
|
374
|
+
catch (error) {
|
|
375
|
+
await browser.close().catch(() => undefined);
|
|
376
|
+
throw error;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
async function createSession(id, url, localOnly, width, height, signal, onNavigationAttempt, actionTimeoutMs, authProfile, centralProfile, recording) {
|
|
380
|
+
await pruneIdleSessions();
|
|
381
|
+
const contextId = centralProfile?.shared?.contextId ?? id;
|
|
382
|
+
const contexts = new Set([...creatingSessions.values(),
|
|
383
|
+
...[...browserSessions].map(([sessionId, session]) => session.sharedMember?.contextId ?? sessionId)]);
|
|
384
|
+
if (!contexts.has(contextId) && contexts.size >= MAX_BROWSER_SESSIONS)
|
|
385
|
+
throw new Error('browser_session_limit');
|
|
386
|
+
creatingSessions.set(id, contextId);
|
|
387
|
+
let profileLease;
|
|
388
|
+
try {
|
|
389
|
+
profileLease = centralProfile?.lease ?? (authProfile ? await authProfile.store.openAsync(authProfile.scope) : undefined);
|
|
390
|
+
}
|
|
391
|
+
catch (error) {
|
|
392
|
+
creatingSessions.delete(id);
|
|
393
|
+
throw error;
|
|
394
|
+
}
|
|
395
|
+
const epoch = sessionEpoch;
|
|
396
|
+
const member = centralProfile?.shared;
|
|
397
|
+
let group;
|
|
398
|
+
let resources;
|
|
399
|
+
let openingPage;
|
|
400
|
+
const onAbort = () => {
|
|
401
|
+
if (group)
|
|
402
|
+
void openingPage?.close().catch(() => undefined);
|
|
403
|
+
else
|
|
404
|
+
void resources?.browser.close().catch(() => undefined);
|
|
405
|
+
};
|
|
406
|
+
signal?.addEventListener('abort', onAbort, { once: true });
|
|
407
|
+
try {
|
|
408
|
+
if (signal?.aborted || member && !member.authorized())
|
|
409
|
+
throw new Error('browser_cancelled');
|
|
410
|
+
if (member) {
|
|
411
|
+
group = sharedContexts.get(member.contextId);
|
|
412
|
+
if (group && (group.profile.lease !== profileLease || group.localOnly !== localOnly))
|
|
413
|
+
throw new Error('browser_profile_scope_changed');
|
|
414
|
+
if (!group) {
|
|
415
|
+
const members = new Set();
|
|
416
|
+
group = { members, profile: centralProfile, localOnly, snapshots: Promise.resolve(),
|
|
417
|
+
resources: createBrowserContext(localOnly, width, height, page => {
|
|
418
|
+
for (const memberId of members) {
|
|
419
|
+
const session = browserSessions.get(memberId);
|
|
420
|
+
if (session && [...session.tabs.values()].includes(page))
|
|
421
|
+
return session;
|
|
422
|
+
}
|
|
423
|
+
return undefined;
|
|
424
|
+
}, profileLease) };
|
|
425
|
+
sharedContexts.set(member.contextId, group);
|
|
426
|
+
}
|
|
427
|
+
group.members.add(id);
|
|
428
|
+
resources = await group.resources;
|
|
429
|
+
}
|
|
430
|
+
else
|
|
431
|
+
resources = await createBrowserContext(localOnly, width, height, () => browserSessions.get(id), profileLease);
|
|
432
|
+
const { browser, context } = resources;
|
|
433
|
+
if (signal?.aborted || member && !member.authorized())
|
|
434
|
+
throw new Error('browser_cancelled');
|
|
435
|
+
const page = openingPage = await context.newPage();
|
|
335
436
|
if (localOnly && !await page.evaluate(() => ['RTCPeerConnection', 'webkitRTCPeerConnection',
|
|
336
437
|
'WebTransport', 'Worker', 'SharedWorker'].every(name => typeof Reflect.get(globalThis, name) === 'undefined'
|
|
337
438
|
&& Object.getOwnPropertyDescriptor(globalThis, name)?.configurable === false)))
|
|
338
439
|
throw new Error('browser_local_network_guard_unavailable');
|
|
339
440
|
const session = { browser, context, page, localOnly, tabs: new Map(),
|
|
441
|
+
...(group && member ? { shared: group, sharedMember: member } : {}),
|
|
340
442
|
observations: new BrowserObservations(), control: { epoch: 0, mode: 'observe', private: false, connected: false },
|
|
341
443
|
...(profileLease ? { authProfile: profileLease, profileScopeId: centralProfile?.id ?? browserProfileScopeId(authProfile.scope),
|
|
342
444
|
...(centralProfile ? { centralProfile: { id: centralProfile.id, name: centralProfile.name } } : { profileScope: authProfile.scope }) } : {}),
|
|
@@ -347,17 +449,32 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
347
449
|
session.workspace = session.owner.workspace;
|
|
348
450
|
session.policyGrantRevision = recording.policyGrantRevision;
|
|
349
451
|
setNetworkLease(id, session, recording.networkAccessExpiresAt);
|
|
350
|
-
browserSessions.set(id, session);
|
|
351
452
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
453
|
+
if (recording || group)
|
|
454
|
+
browserSessions.set(id, session);
|
|
455
|
+
if (!registerTab(session, page))
|
|
456
|
+
throw new Error('browser_tab_limit');
|
|
457
|
+
if (!group)
|
|
458
|
+
context.on('page', opened => {
|
|
459
|
+
if (session.snapshotting)
|
|
460
|
+
return;
|
|
461
|
+
if (session.control.tabId) {
|
|
462
|
+
const heldPage = session.tabs.get(session.control.tabId);
|
|
463
|
+
void opened.opener().then(opener => {
|
|
464
|
+
if (!opener || opener === heldPage || ![...session.tabs.values()].includes(opener))
|
|
465
|
+
return opened.close();
|
|
466
|
+
if (registerTab(session, opened))
|
|
467
|
+
session.page = opened;
|
|
468
|
+
}).catch(() => undefined);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
if (registerTab(session, opened))
|
|
472
|
+
session.page = opened;
|
|
473
|
+
});
|
|
359
474
|
const initialPopup = page.waitForEvent('popup', { timeout: 5_000 })
|
|
360
475
|
.then(async (opened) => {
|
|
476
|
+
if (group && ![...session.tabs.values()].includes(opened))
|
|
477
|
+
return;
|
|
361
478
|
session.page = opened;
|
|
362
479
|
await opened.waitForLoadState('domcontentloaded', { timeout: 5_000 }).catch(() => undefined);
|
|
363
480
|
}).catch(() => undefined);
|
|
@@ -365,6 +482,8 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
365
482
|
await attachBrowserLive({ ...recording.options, sessionOwned: true });
|
|
366
483
|
if (browserAuthPage(url))
|
|
367
484
|
await session.live?.pauseRecording();
|
|
485
|
+
if (signal?.aborted || member && !member.authorized())
|
|
486
|
+
throw new Error('browser_cancelled');
|
|
368
487
|
onNavigationAttempt?.();
|
|
369
488
|
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: actionTimeoutMs ?? 30_000 });
|
|
370
489
|
(localOnly ? localBrowserUrl : browserUrl)(page.url());
|
|
@@ -384,11 +503,18 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
384
503
|
return session;
|
|
385
504
|
}
|
|
386
505
|
catch (error) {
|
|
387
|
-
if (browserSessions.
|
|
506
|
+
if (browserSessions.has(id))
|
|
388
507
|
await closeSession(id);
|
|
508
|
+
else if (group && member) {
|
|
509
|
+
await openingPage?.close().catch(() => undefined);
|
|
510
|
+
await releaseSharedMember(id, group, member);
|
|
511
|
+
}
|
|
389
512
|
else {
|
|
390
|
-
await browser.close().catch(() => undefined);
|
|
391
|
-
|
|
513
|
+
await resources?.browser.close().catch(() => undefined);
|
|
514
|
+
if (member)
|
|
515
|
+
await member.releaseMember();
|
|
516
|
+
else
|
|
517
|
+
await profileLease?.release();
|
|
392
518
|
}
|
|
393
519
|
throw error;
|
|
394
520
|
}
|
|
@@ -400,14 +526,24 @@ async function createSession(id, url, localOnly, width, height, signal, onNaviga
|
|
|
400
526
|
function registerTab(session, page) {
|
|
401
527
|
if ([...session.tabs.values()].includes(page))
|
|
402
528
|
return false;
|
|
403
|
-
|
|
404
|
-
|
|
529
|
+
const sharedTabCount = session.shared
|
|
530
|
+
? [...session.shared.members].reduce((count, id) => count + (browserSessions.get(id)?.tabs.size ?? 0), 0)
|
|
531
|
+
: 0;
|
|
532
|
+
if (session.tabs.size >= MAX_BROWSER_TABS || sharedTabCount >= MAX_SHARED_TABS) {
|
|
533
|
+
void page.close().catch(() => undefined);
|
|
405
534
|
return false;
|
|
406
535
|
}
|
|
407
536
|
const id = randomUUID();
|
|
408
537
|
session.tabs.set(id, page);
|
|
538
|
+
if (session.shared)
|
|
539
|
+
page.on('popup', opened => {
|
|
540
|
+
if (page.isClosed() || session.control.tabId === id || session.sharedMember?.authorized() !== true)
|
|
541
|
+
void opened.close().catch(() => undefined);
|
|
542
|
+
else if (registerTab(session, opened))
|
|
543
|
+
session.page = opened;
|
|
544
|
+
});
|
|
409
545
|
page.on('framenavigated', frame => {
|
|
410
|
-
session.observations.invalidate();
|
|
546
|
+
session.observations.invalidate(page);
|
|
411
547
|
if (frame === page.mainFrame() && browserAuthPage(page.url()))
|
|
412
548
|
void session.live?.pauseRecording().catch(() => session.live?.block());
|
|
413
549
|
});
|
|
@@ -423,26 +559,46 @@ function registerTab(session, page) {
|
|
|
423
559
|
});
|
|
424
560
|
return true;
|
|
425
561
|
}
|
|
426
|
-
async function
|
|
562
|
+
async function openTab(session) {
|
|
563
|
+
if (session.tabs.size >= MAX_BROWSER_TABS)
|
|
564
|
+
throw new Error('browser_tab_limit');
|
|
565
|
+
const page = await session.context.newPage();
|
|
566
|
+
if (session.shared && !registerTab(session, page))
|
|
567
|
+
throw new Error('browser_tab_limit');
|
|
568
|
+
session.page = page;
|
|
569
|
+
return page;
|
|
570
|
+
}
|
|
571
|
+
async function closeTab(id, session, page) {
|
|
572
|
+
if (session.tabs.size === 1) {
|
|
573
|
+
await checkpointProfile(session).catch(() => undefined);
|
|
574
|
+
await closeSession(id);
|
|
575
|
+
return true;
|
|
576
|
+
}
|
|
577
|
+
await page.close();
|
|
578
|
+
session.observations.invalidate();
|
|
579
|
+
await checkpointSession(id, session);
|
|
580
|
+
return false;
|
|
581
|
+
}
|
|
582
|
+
async function describeSession(id, session, sessionCreated, selectedPage = session?.page) {
|
|
427
583
|
const tabs = [];
|
|
428
584
|
for (const [tabId, page] of session?.tabs || []) {
|
|
429
585
|
if (page.isClosed())
|
|
430
586
|
continue;
|
|
431
587
|
const rawUrl = page.url();
|
|
432
|
-
tabs.push({ id: tabId, title: (await page.title().catch(() => '')
|
|
433
|
-
url: rawUrl === 'about:blank' ? rawUrl : safePageUrl(rawUrl), popup: !!await page.opener(), active:
|
|
588
|
+
tabs.push({ id: tabId, title: clipTerminalText(await page.title().catch(() => ''), 200),
|
|
589
|
+
url: rawUrl === 'about:blank' ? rawUrl : safePageUrl(rawUrl), popup: !!await page.opener(), active: selectedPage === page });
|
|
434
590
|
}
|
|
435
591
|
const active = tabs.find(tab => tab.active);
|
|
436
592
|
return { browserSessionId: id, activeTabId: active?.id || null,
|
|
437
593
|
tabs, pageUrl: active?.url || '', sessionCreated,
|
|
438
|
-
...(active && session ? { browserObservation: session.observations.fresh(
|
|
594
|
+
...(active && session ? { browserObservation: session.observations.fresh(selectedPage, active.id) } : {}),
|
|
439
595
|
...(session?.centralProfile ? { browserProfile: { ...session.centralProfile, persistent: true, default: false } }
|
|
440
596
|
: session?.profileScope ? { browserProfile: { id: session.profileScopeId, name: session.profileScope.name, persistent: true, default: false } } : {}) };
|
|
441
597
|
}
|
|
442
598
|
function activePage(session) {
|
|
443
599
|
if (!session.page.isClosed())
|
|
444
600
|
return session.page;
|
|
445
|
-
const remaining = session.
|
|
601
|
+
const remaining = [...session.tabs.values()].filter(page => !page.isClosed());
|
|
446
602
|
if (!remaining.length)
|
|
447
603
|
throw new Error('browser_session_missing');
|
|
448
604
|
session.page = remaining[remaining.length - 1];
|
|
@@ -498,7 +654,7 @@ async function semanticControls(page) {
|
|
|
498
654
|
if (!controls.length)
|
|
499
655
|
return '';
|
|
500
656
|
return '\n\nInteractive elements (field values omitted):\n'
|
|
501
|
-
+ controls.map((item, index) => `${index + 1}. ${JSON.stringify(item)}`).join('\n')
|
|
657
|
+
+ clipTerminalText(controls.map((item, index) => `${index + 1}. ${JSON.stringify(item)}`).join('\n'), 12_000);
|
|
502
658
|
}
|
|
503
659
|
async function guardSecretFill(page, selector) {
|
|
504
660
|
if (await isSecretControl(page, selector))
|
|
@@ -535,11 +691,25 @@ export function writePrivateScreenshot(file, bytes) {
|
|
|
535
691
|
}
|
|
536
692
|
async function runForSession(input) {
|
|
537
693
|
const existing = browserSessions.get(input.browserSessionId);
|
|
538
|
-
|
|
539
|
-
|
|
694
|
+
const assertModelAccess = (session) => {
|
|
695
|
+
if (input.signal?.aborted)
|
|
696
|
+
throw new Error('browser_cancelled');
|
|
697
|
+
if (session && session.control.mode !== 'observe'
|
|
698
|
+
&& (!canUseOtherBrowserTab(session.control.tabId, input.tabId, input.action)
|
|
699
|
+
|| session.localOnly !== (input.localOnly === true) || input.networkAccessOnce
|
|
700
|
+
|| !session.browser.isConnected()
|
|
701
|
+
|| session.networkAccessExpiresAt !== null && session.networkAccessExpiresAt <= Date.now()
|
|
702
|
+
|| session.networkAccessExpiresAt !== (input.networkAccessExpiresAt ?? null)))
|
|
703
|
+
throw new Error('browser_human_control_active');
|
|
704
|
+
};
|
|
705
|
+
assertModelAccess(existing);
|
|
706
|
+
const parallelTab = !!existing && existing.control.mode !== 'observe';
|
|
540
707
|
if (input.signal?.aborted)
|
|
541
708
|
throw new Error('browser_cancelled');
|
|
542
709
|
validateBrowserActionInput(input);
|
|
710
|
+
const shared = input.centralProfile?.shared;
|
|
711
|
+
if (shared && (!shared.authorized() || input.networkAccessOnce || input.networkAccessExpiresAt != null))
|
|
712
|
+
throw new Error('browser_profile_lease_expired');
|
|
543
713
|
const url = input.localOnly && !['tabs', 'close', 'close_tab'].includes(input.action) ? localBrowserUrl(input.url) : browserUrl(input.url);
|
|
544
714
|
let width = input.width ?? existing?.page.viewportSize()?.width ?? input.recording?.options.browserSettings?.width ?? 1440;
|
|
545
715
|
let height = input.height ?? existing?.page.viewportSize()?.height ?? input.recording?.options.browserSettings?.height ?? 900;
|
|
@@ -551,7 +721,7 @@ async function runForSession(input) {
|
|
|
551
721
|
if (session?.centralProfile && !['tabs', 'close', 'close_tab'].includes(input.action)
|
|
552
722
|
&& session.localOnly !== (input.localOnly === true)) {
|
|
553
723
|
// A new network boundary requires fresh navigation, never a replayed click/form action.
|
|
554
|
-
if (input.action !== 'navigate' || input.tabId)
|
|
724
|
+
if (session.shared || input.action !== 'navigate' || input.tabId)
|
|
555
725
|
throw new Error('browser_profile_navigation_required');
|
|
556
726
|
await checkpointSession(input.browserSessionId, session);
|
|
557
727
|
const viewport = session.page.viewportSize();
|
|
@@ -561,8 +731,8 @@ async function runForSession(input) {
|
|
|
561
731
|
await closeSession(input.browserSessionId, { retainProfileLease: true });
|
|
562
732
|
session = undefined;
|
|
563
733
|
}
|
|
564
|
-
if (session && (!['tabs', 'close', 'close_tab'].includes(input.action) && session.localOnly !== (input.localOnly === true) || !session.browser.isConnected()
|
|
565
|
-
|| session.
|
|
734
|
+
if (!parallelTab && session && (!['tabs', 'close', 'close_tab'].includes(input.action) && session.localOnly !== (input.localOnly === true) || !session.browser.isConnected()
|
|
735
|
+
|| [...session.tabs.values()].every(page => page.isClosed())
|
|
566
736
|
|| Date.now() - session.lastUsedAt >= BROWSER_SESSION_IDLE_MS)) {
|
|
567
737
|
await closeSession(input.browserSessionId);
|
|
568
738
|
session = undefined;
|
|
@@ -591,10 +761,10 @@ async function runForSession(input) {
|
|
|
591
761
|
session.owner = owner;
|
|
592
762
|
}
|
|
593
763
|
// Inventory and cleanup cannot renew, remove or widen an existing network lease.
|
|
594
|
-
if (!['tabs', 'close_tab'].includes(input.action)) {
|
|
764
|
+
if (!parallelTab && !['tabs', 'close_tab'].includes(input.action)) {
|
|
595
765
|
session.workspace = input.agentTerminalWorkspaceId ? input.workspace : undefined;
|
|
596
766
|
session.policyGrantRevision = input.policyGrantRevision;
|
|
597
|
-
session.threadScope = input.networkAccessForThread === true ? { actorUserId: input.actorUserId,
|
|
767
|
+
session.threadScope = !session.shared && input.networkAccessForThread === true ? { actorUserId: input.actorUserId,
|
|
598
768
|
threadId: input.threadId, ...(input.agentTerminalWorkspaceId ? { agentTerminalWorkspaceId: input.agentTerminalWorkspaceId } : {}), policyGrantRevision: input.policyGrantRevision } : undefined;
|
|
599
769
|
try {
|
|
600
770
|
setNetworkLease(input.browserSessionId, session, input.networkAccessExpiresAt ?? null);
|
|
@@ -605,12 +775,14 @@ async function runForSession(input) {
|
|
|
605
775
|
}
|
|
606
776
|
}
|
|
607
777
|
if (input.signal?.aborted) {
|
|
608
|
-
|
|
778
|
+
if (!parallelTab)
|
|
779
|
+
await closeSession(input.browserSessionId);
|
|
609
780
|
throw new Error('browser_cancelled');
|
|
610
781
|
}
|
|
611
|
-
if (input.recording && session.live?.sessionOwned)
|
|
782
|
+
if (!parallelTab && input.recording && session.live?.sessionOwned)
|
|
612
783
|
session.live.refreshRecordingAuthority(input.recording.options);
|
|
613
|
-
const onAbort = () => {
|
|
784
|
+
const onAbort = () => { if (!parallelTab && !session.control.tabId)
|
|
785
|
+
void closeSession(input.browserSessionId); };
|
|
614
786
|
input.signal?.addEventListener('abort', onAbort, { once: true });
|
|
615
787
|
session.active = true;
|
|
616
788
|
try {
|
|
@@ -620,7 +792,7 @@ async function runForSession(input) {
|
|
|
620
792
|
const selected = session.tabs.get(input.tabId);
|
|
621
793
|
if (!selected || selected.isClosed())
|
|
622
794
|
throw new Error('browser_tab_missing');
|
|
623
|
-
if (session.page !== selected)
|
|
795
|
+
if (session.page !== selected && !parallelTab)
|
|
624
796
|
session.observations.invalidate();
|
|
625
797
|
session.page = selected;
|
|
626
798
|
}
|
|
@@ -628,41 +800,32 @@ async function runForSession(input) {
|
|
|
628
800
|
return { dom: '', ...await describeSession(input.browserSessionId, session, created) };
|
|
629
801
|
if (input.action === 'close_tab') {
|
|
630
802
|
input.onActionAttempt?.();
|
|
631
|
-
await activePage(session)
|
|
632
|
-
|
|
633
|
-
if (!remaining.length) {
|
|
634
|
-
await closeSession(input.browserSessionId);
|
|
635
|
-
return { dom: '', ...await describeSession(input.browserSessionId, undefined, false) };
|
|
636
|
-
}
|
|
637
|
-
session.page = remaining[remaining.length - 1];
|
|
638
|
-
await checkpointSession(input.browserSessionId, session);
|
|
639
|
-
return { dom: '', ...await describeSession(input.browserSessionId, session, false) };
|
|
803
|
+
const closed = await closeTab(input.browserSessionId, session, activePage(session));
|
|
804
|
+
return { dom: '', ...await describeSession(input.browserSessionId, closed ? undefined : session, false) };
|
|
640
805
|
}
|
|
641
806
|
if (['navigate', 'new_tab'].includes(input.action) && browserAuthPage(url))
|
|
642
807
|
await session.live?.pauseRecording();
|
|
643
808
|
if (input.action === 'new_tab' && !created) {
|
|
644
|
-
|
|
645
|
-
throw new Error('browser_tab_limit');
|
|
646
|
-
session.page = await session.context.newPage();
|
|
809
|
+
const opened = await openTab(session);
|
|
647
810
|
input.onActionAttempt?.();
|
|
648
|
-
await
|
|
811
|
+
await opened.goto(url, { waitUntil: 'domcontentloaded', timeout: input.actionTimeoutMs ?? 30_000 });
|
|
649
812
|
}
|
|
650
813
|
let page = activePage(session);
|
|
651
|
-
|
|
814
|
+
if (!session.shared && !parallelTab)
|
|
815
|
+
await page.bringToFront();
|
|
652
816
|
if (!['interact', 'dom'].includes(input.action) || input.width != null || input.height != null) {
|
|
653
817
|
const old = page.viewportSize();
|
|
654
818
|
if (old?.width !== width || old?.height !== height)
|
|
655
|
-
session.observations.invalidate();
|
|
819
|
+
session.observations.invalidate(page);
|
|
656
820
|
await page.setViewportSize({ width, height });
|
|
657
821
|
}
|
|
658
822
|
if (input.action === 'navigate' && !created) {
|
|
659
|
-
|
|
660
|
-
throw new Error('browser_human_control_active');
|
|
823
|
+
assertModelAccess(session);
|
|
661
824
|
input.onActionAttempt?.();
|
|
662
825
|
await page.goto(url, { waitUntil: 'domcontentloaded', timeout: input.actionTimeoutMs ?? 30_000 });
|
|
663
826
|
}
|
|
664
827
|
(input.localOnly ? localBrowserUrl : browserUrl)(page.url());
|
|
665
|
-
if (session.live && await pageHasSecretFocus(page))
|
|
828
|
+
if (!parallelTab && session.live && await pageHasSecretFocus(page))
|
|
666
829
|
await session.live.pauseRecording();
|
|
667
830
|
const actionPage = page;
|
|
668
831
|
let target = input.selector ? page.locator(input.selector) : page.locator('body');
|
|
@@ -672,11 +835,10 @@ async function runForSession(input) {
|
|
|
672
835
|
throw new Error('browser_tab_missing');
|
|
673
836
|
const observation = session.observations.require(input.interaction.observationId, page, tabId);
|
|
674
837
|
await applyPageInteraction(page, input.interaction, observation, false, () => {
|
|
675
|
-
|
|
676
|
-
throw new Error('browser_human_control_active');
|
|
838
|
+
assertModelAccess(session);
|
|
677
839
|
input.onActionAttempt?.();
|
|
678
840
|
});
|
|
679
|
-
session.observations.invalidate();
|
|
841
|
+
session.observations.invalidate(page);
|
|
680
842
|
page = activePage(session);
|
|
681
843
|
}
|
|
682
844
|
else if (FORM_ACTIONS.has(input.action)) {
|
|
@@ -699,13 +861,12 @@ async function runForSession(input) {
|
|
|
699
861
|
? 'browser_selector_missing' : 'browser_selector_ambiguous');
|
|
700
862
|
if (input.action === 'fill')
|
|
701
863
|
await guardSecretFill(page, input.selector);
|
|
702
|
-
|
|
703
|
-
throw new Error('browser_human_control_active');
|
|
864
|
+
assertModelAccess(session);
|
|
704
865
|
const popup = input.action === 'click' || input.action === 'press'
|
|
705
866
|
? actionPage.waitForEvent('popup', { timeout: 750 }).catch(() => undefined)
|
|
706
867
|
: Promise.resolve(undefined);
|
|
707
868
|
input.onActionAttempt?.();
|
|
708
|
-
session.observations.invalidate();
|
|
869
|
+
session.observations.invalidate(page);
|
|
709
870
|
if (input.action === 'click') {
|
|
710
871
|
await target.click({ timeout: input.actionTimeoutMs ?? 10_000 });
|
|
711
872
|
}
|
|
@@ -722,7 +883,7 @@ async function runForSession(input) {
|
|
|
722
883
|
else
|
|
723
884
|
await target.press(input.key, { timeout: input.actionTimeoutMs ?? 10_000 });
|
|
724
885
|
const opened = await popup;
|
|
725
|
-
if (opened && !opened.isClosed())
|
|
886
|
+
if (opened && !opened.isClosed() && (!session.shared || [...session.tabs.values()].includes(opened)))
|
|
726
887
|
session.page = opened;
|
|
727
888
|
page = activePage(session);
|
|
728
889
|
if (page !== actionPage)
|
|
@@ -732,16 +893,15 @@ async function runForSession(input) {
|
|
|
732
893
|
else if (input.action === 'scroll') {
|
|
733
894
|
input.onActionAttempt?.();
|
|
734
895
|
await page.mouse.wheel(0, input.deltaY);
|
|
735
|
-
session.observations.invalidate();
|
|
896
|
+
session.observations.invalidate(page);
|
|
736
897
|
}
|
|
737
898
|
else if (input.action === 'wait_for') {
|
|
738
899
|
await target.waitFor({ state: input.state, timeout: Math.min(input.waitTimeoutMs, input.actionTimeoutMs ?? input.waitTimeoutMs) });
|
|
739
900
|
}
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
throw new Error('browser_human_control_active');
|
|
901
|
+
assertModelAccess(session);
|
|
902
|
+
if (!parallelTab)
|
|
903
|
+
await checkpointSession(input.browserSessionId, session);
|
|
904
|
+
assertModelAccess(session);
|
|
745
905
|
if (activePage(session) !== page) {
|
|
746
906
|
page = activePage(session);
|
|
747
907
|
(input.localOnly ? localBrowserUrl : browserUrl)(page.url());
|
|
@@ -749,13 +909,15 @@ async function runForSession(input) {
|
|
|
749
909
|
}
|
|
750
910
|
const domTarget = INTERACTIVE_ACTIONS.has(input.action)
|
|
751
911
|
|| input.action === 'wait_for' && input.state === 'hidden' ? page.locator('body') : target.first();
|
|
752
|
-
const bodyText = (await domTarget.innerText({ timeout: input.actionTimeoutMs ?? 10_000 })
|
|
753
|
-
const dom = (bodyText + await semanticControls(page)
|
|
912
|
+
const bodyText = clipTerminalText(await domTarget.innerText({ timeout: input.actionTimeoutMs ?? 10_000 }), 25_000);
|
|
913
|
+
const dom = clipTerminalText(bodyText + await semanticControls(page), 40_000);
|
|
754
914
|
const pageUrl = safePageUrl(page.url());
|
|
755
|
-
|
|
915
|
+
if (!parallelTab)
|
|
916
|
+
await session.live?.resumeRecordingIfPublic();
|
|
756
917
|
const inventory = await describeSession(input.browserSessionId, session, created);
|
|
757
|
-
if (session.control.
|
|
758
|
-
|
|
918
|
+
if (session.control.tabId)
|
|
919
|
+
inventory.tabs = inventory.tabs.map(tab => tab.id === session.control.tabId ? { ...tab, title: '', url: '' } : tab);
|
|
920
|
+
assertModelAccess(session);
|
|
759
921
|
if (input.action !== 'screenshot')
|
|
760
922
|
return { dom, ...inventory, pageUrl };
|
|
761
923
|
const root = fs.realpathSync(input.workspace);
|
|
@@ -791,8 +953,7 @@ async function runForSession(input) {
|
|
|
791
953
|
}
|
|
792
954
|
if (bytes.length > 30 * 1024 * 1024)
|
|
793
955
|
throw new Error('browser_screenshot_too_large');
|
|
794
|
-
|
|
795
|
-
throw new Error('browser_human_control_active');
|
|
956
|
+
assertModelAccess(session);
|
|
796
957
|
writePrivateScreenshot(screenshotPath, bytes);
|
|
797
958
|
inventory.browserObservation = session.observations.fresh(page, inventory.activeTabId);
|
|
798
959
|
const imageWidth = bytes.readUInt32BE(16);
|
|
@@ -824,8 +985,9 @@ export async function runBrowserAction(input) {
|
|
|
824
985
|
return { dom, pageUrl: safePageUrl(JSON.parse(dom).url), browserSessionId: input.browserSessionId,
|
|
825
986
|
activeTabId: null, tabs: [], sessionCreated: false };
|
|
826
987
|
}
|
|
827
|
-
|
|
828
|
-
|
|
988
|
+
const existing = browserSessions.get(input.browserSessionId);
|
|
989
|
+
if (existing && existing.control.mode !== 'observe'
|
|
990
|
+
&& !canUseOtherBrowserTab(existing.control.tabId, input.tabId, input.action))
|
|
829
991
|
throw new Error('browser_human_control_active');
|
|
830
992
|
const previous = sessionQueues.get(input.browserSessionId) || Promise.resolve();
|
|
831
993
|
const task = previous.catch(() => undefined).then(() => runForSession(input));
|
|
@@ -930,6 +1092,7 @@ export async function attachBrowserLive(options) {
|
|
|
930
1092
|
if (options.initialControl.mode !== 'observe') {
|
|
931
1093
|
session.control.mode = 'blocked';
|
|
932
1094
|
session.control.private = true;
|
|
1095
|
+
session.control.tabId = options.initialControl.tabId;
|
|
933
1096
|
}
|
|
934
1097
|
// A reconnect never auto-releases an existing local human/blocked fence.
|
|
935
1098
|
}
|
|
@@ -945,10 +1108,19 @@ export async function attachBrowserLive(options) {
|
|
|
945
1108
|
await previous.settled();
|
|
946
1109
|
const authorized = () => browserSessions.get(options.browserSessionId) === session && session.browser.isConnected()
|
|
947
1110
|
&& (session.networkAccessExpiresAt === null || session.networkAccessExpiresAt > Date.now());
|
|
1111
|
+
const viewerPage = () => {
|
|
1112
|
+
if (!session.control.tabId)
|
|
1113
|
+
return activePage(session);
|
|
1114
|
+
const page = session.tabs.get(session.control.tabId);
|
|
1115
|
+
if (!page || page.isClosed())
|
|
1116
|
+
throw new Error('browser_tab_missing');
|
|
1117
|
+
return page;
|
|
1118
|
+
};
|
|
1119
|
+
let viewerInput = Promise.resolve(undefined);
|
|
948
1120
|
const handle = new BrowserLiveHandle(options, {
|
|
949
1121
|
control: session.control, observations: session.observations,
|
|
950
1122
|
active: () => {
|
|
951
|
-
const page =
|
|
1123
|
+
const page = viewerPage();
|
|
952
1124
|
const tabId = [...session.tabs].find(([, current]) => current === page)?.[0];
|
|
953
1125
|
if (!tabId)
|
|
954
1126
|
throw new Error('browser_tab_missing');
|
|
@@ -956,10 +1128,20 @@ export async function attachBrowserLive(options) {
|
|
|
956
1128
|
},
|
|
957
1129
|
pages: () => [...session.tabs.values()].filter(page => !page.isClosed()),
|
|
958
1130
|
authorized, fullNetwork: () => authorized() && !session.localOnly,
|
|
959
|
-
queue: async (work) => {
|
|
1131
|
+
queue: async (work, tabInput = false) => {
|
|
1132
|
+
if (tabInput && session.control.tabId) {
|
|
1133
|
+
const task = viewerInput.catch(() => undefined).then(() => {
|
|
1134
|
+
if (!authorized())
|
|
1135
|
+
throw new Error('browser_live_scope_expired');
|
|
1136
|
+
session.lastUsedAt = Date.now();
|
|
1137
|
+
return work();
|
|
1138
|
+
});
|
|
1139
|
+
viewerInput = task;
|
|
1140
|
+
return task;
|
|
1141
|
+
}
|
|
960
1142
|
const previous = sessionQueues.get(options.browserSessionId) || Promise.resolve();
|
|
961
1143
|
const task = previous.catch(() => undefined).then(async () => {
|
|
962
|
-
if (!authorized()
|
|
1144
|
+
if (!authorized())
|
|
963
1145
|
throw new Error('browser_live_scope_expired');
|
|
964
1146
|
session.active = true;
|
|
965
1147
|
try {
|
|
@@ -980,8 +1162,9 @@ export async function attachBrowserLive(options) {
|
|
|
980
1162
|
}
|
|
981
1163
|
},
|
|
982
1164
|
state: async () => {
|
|
983
|
-
const
|
|
984
|
-
|
|
1165
|
+
const page = viewerPage();
|
|
1166
|
+
const focusId = await describeFocusedField(page);
|
|
1167
|
+
return { ...await describeSession(options.browserSessionId, session, false, page), focusEditable: !!focusId, focusId };
|
|
985
1168
|
},
|
|
986
1169
|
selectTab: async (tabId) => {
|
|
987
1170
|
const page = session.tabs.get(tabId);
|
|
@@ -991,8 +1174,32 @@ export async function attachBrowserLive(options) {
|
|
|
991
1174
|
session.page = page;
|
|
992
1175
|
await page.bringToFront();
|
|
993
1176
|
},
|
|
1177
|
+
newTab: async () => {
|
|
1178
|
+
const current = new URL(activePage(session).url());
|
|
1179
|
+
const url = (session.localOnly ? localBrowserUrl : browserUrl)(current.origin + current.pathname);
|
|
1180
|
+
const opened = await openTab(session);
|
|
1181
|
+
try {
|
|
1182
|
+
await opened.goto(url, { waitUntil: 'domcontentloaded', timeout: 30_000 });
|
|
1183
|
+
await checkpointSession(options.browserSessionId, session);
|
|
1184
|
+
}
|
|
1185
|
+
catch (error) {
|
|
1186
|
+
await opened.close().catch(() => undefined);
|
|
1187
|
+
throw error;
|
|
1188
|
+
}
|
|
1189
|
+
},
|
|
1190
|
+
closeTab: async (tabId) => {
|
|
1191
|
+
const page = session.tabs.get(tabId);
|
|
1192
|
+
if (!page || page.isClosed())
|
|
1193
|
+
throw new Error('browser_tab_missing');
|
|
1194
|
+
return closeTab(options.browserSessionId, session, page);
|
|
1195
|
+
},
|
|
1196
|
+
closeSession: async () => {
|
|
1197
|
+
await checkpointProfile(session).catch(() => undefined);
|
|
1198
|
+
await closeSession(options.browserSessionId);
|
|
1199
|
+
},
|
|
994
1200
|
release: async () => {
|
|
995
|
-
|
|
1201
|
+
const pages = session.control.tabId ? [viewerPage()] : session.tabs.values();
|
|
1202
|
+
for (const page of pages)
|
|
996
1203
|
if (!page.isClosed()) {
|
|
997
1204
|
await releasePageInput(page);
|
|
998
1205
|
await clearSecretInputs(page);
|
|
@@ -1024,7 +1231,7 @@ export async function attachBrowserLive(options) {
|
|
|
1024
1231
|
const saveCurrent = !!resolved && !choice.reset && !resolved.store.has(resolved.scope);
|
|
1025
1232
|
// Acquire the destination before changing the running browser, so a busy profile leaves it intact.
|
|
1026
1233
|
let next = same ? session.authProfile : (resolved ? await resolved.store.openAsync(resolved.scope) : undefined);
|
|
1027
|
-
if (!authorized() || !
|
|
1234
|
+
if (!authorized() || !liveOptions.isAuthorized()) {
|
|
1028
1235
|
if (next && next !== session.authProfile)
|
|
1029
1236
|
await next.release();
|
|
1030
1237
|
throw new Error('browser_live_scope_expired');
|
|
@@ -1040,7 +1247,7 @@ export async function attachBrowserLive(options) {
|
|
|
1040
1247
|
next = await resolved.store.openAsync(resolved.scope);
|
|
1041
1248
|
}
|
|
1042
1249
|
try {
|
|
1043
|
-
if (!authorized() || !
|
|
1250
|
+
if (!authorized() || !liveOptions.isAuthorized())
|
|
1044
1251
|
throw new Error('browser_live_scope_expired');
|
|
1045
1252
|
if (!same && session.authProfile)
|
|
1046
1253
|
await checkpointProfile(session);
|