@ai-ecoverse/sliccy-browser 0.1.47 → 0.1.49
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/package.json +1 -1
- package/src/browser.js +398 -0
- package/src/guard.js +29 -0
- package/src/version.js +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-ecoverse/sliccy-browser",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.49",
|
|
4
4
|
"description": "sliccy:browser for jsh, over CDP. Discovers Chrome via SLICC_CDP_URL, slicc browsers --json, DevToolsActivePort under slicc profiles (live /json/version must match the file's websocket path), then 127.0.0.1:9222. Discovered endpoints refuse seven/vault/extension/error pages; pre-attach websocket frames are dropped with a one-time warning. Holds a dialog session on each tab it attaches to, so a page's alert, confirm or prompt is answered instead of freezing the tab.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "Apache-2.0",
|
package/src/browser.js
CHANGED
|
@@ -14,6 +14,8 @@ import { resolveCdpEndpoint } from './discover.js';
|
|
|
14
14
|
import { buildBrowserFetchScript } from './fetch-script.js';
|
|
15
15
|
import {
|
|
16
16
|
dropProtectedCookies,
|
|
17
|
+
inheritingDocumentUrl,
|
|
18
|
+
isProtectedDocument,
|
|
17
19
|
isProtectedHost,
|
|
18
20
|
isProtectedUrl,
|
|
19
21
|
REFUSAL,
|
|
@@ -56,6 +58,11 @@ const held = new Map();
|
|
|
56
58
|
const recorders = new Map();
|
|
57
59
|
const networkless = new Map();
|
|
58
60
|
const subscribers = new Map();
|
|
61
|
+
const documents = new Map();
|
|
62
|
+
const mainFrames = new Map();
|
|
63
|
+
const childFrames = new Map();
|
|
64
|
+
const frameTreeReads = new Map();
|
|
65
|
+
const documentGens = new Map();
|
|
59
66
|
let seq = 1;
|
|
60
67
|
let listening = false;
|
|
61
68
|
let active = 0;
|
|
@@ -151,6 +158,11 @@ function closeIdle() {
|
|
|
151
158
|
held.clear();
|
|
152
159
|
recorders.clear();
|
|
153
160
|
networkless.clear();
|
|
161
|
+
documents.clear();
|
|
162
|
+
mainFrames.clear();
|
|
163
|
+
childFrames.clear();
|
|
164
|
+
frameTreeReads.clear();
|
|
165
|
+
documentGens.clear();
|
|
154
166
|
listening = false;
|
|
155
167
|
closing.then(
|
|
156
168
|
(client) => client.close(),
|
|
@@ -176,6 +188,7 @@ async function sessionFor(targetId) {
|
|
|
176
188
|
listen(client);
|
|
177
189
|
const sessionId = await client.attach(targetId);
|
|
178
190
|
tabsBySession.set(sessionId, targetId);
|
|
191
|
+
if (guarded) forgetDocument(targetId);
|
|
179
192
|
await client.send('Page.enable', {}, sessionId).catch(ignoreMethod('Page.enable:'));
|
|
180
193
|
await client.send('Runtime.enable', {}, sessionId).catch(ignoreMethod('Runtime.enable:'));
|
|
181
194
|
await client.send('Network.enable', {}, sessionId).catch((error) => {
|
|
@@ -183,6 +196,8 @@ async function sessionFor(targetId) {
|
|
|
183
196
|
networkless.set(sessionId, error.message);
|
|
184
197
|
});
|
|
185
198
|
sessions.set(targetId, sessionId);
|
|
199
|
+
if (guarded) await seedDocumentClass(client, targetId, sessionId);
|
|
200
|
+
if (guarded) await seedFrameTree(client, targetId, sessionId);
|
|
186
201
|
await hold(endpoint, targetId);
|
|
187
202
|
return { client, sessionId };
|
|
188
203
|
}
|
|
@@ -193,6 +208,10 @@ function listen(client) {
|
|
|
193
208
|
client.on('Network.webSocketCreated', (message) => {
|
|
194
209
|
const { requestId, url } = message?.params ?? {};
|
|
195
210
|
if (typeof requestId !== 'string' || typeof url !== 'string') return;
|
|
211
|
+
if (guarded) {
|
|
212
|
+
const targetId = tabsBySession.get(message.sessionId);
|
|
213
|
+
if (targetId === undefined || !tabOrdinary(targetId)) return;
|
|
214
|
+
}
|
|
196
215
|
sockets.set(socketKey(message.sessionId, requestId), url);
|
|
197
216
|
});
|
|
198
217
|
client.on('Network.webSocketClosed', (message) => {
|
|
@@ -202,6 +221,20 @@ function listen(client) {
|
|
|
202
221
|
});
|
|
203
222
|
client.on('Network.webSocketFrameReceived', (message) => dispatchFrame(message));
|
|
204
223
|
client.on('Network.webSocketFrameSent', (message) => void learnUrl(client, message));
|
|
224
|
+
if (guarded) {
|
|
225
|
+
client.on('Page.frameNavigated', (message) => onFrameNavigated(message));
|
|
226
|
+
client.on('Page.frameAttached', (message) => onFrameAttached(message));
|
|
227
|
+
client.on('Page.frameDetached', (message) => onFrameDetached(message));
|
|
228
|
+
client.on('Page.navigatedWithinDocument', (message) => onNavigatedWithinDocument(message));
|
|
229
|
+
client.on('Target.targetInfoChanged', (message) => onTargetInfo(message?.params?.targetInfo));
|
|
230
|
+
client.on('Target.targetCreated', (message) => onTargetInfo(message?.params?.targetInfo));
|
|
231
|
+
client.on('Target.detachedFromTarget', (message) => onSessionEnded(message));
|
|
232
|
+
client.on('Target.targetDestroyed', (message) => onTargetGone(message?.params?.targetId));
|
|
233
|
+
client.on('Target.targetCrashed', (message) => onTargetGone(message?.params?.targetId));
|
|
234
|
+
client.on('Inspector.targetCrashed', (message) => onSessionEnded(message));
|
|
235
|
+
client.on('Inspector.detached', (message) => onSessionEnded(message));
|
|
236
|
+
void client.send('Target.setDiscoverTargets', { discover: true }).catch(() => undefined);
|
|
237
|
+
}
|
|
205
238
|
}
|
|
206
239
|
|
|
207
240
|
function socketKey(sessionId, requestId) {
|
|
@@ -240,6 +273,7 @@ function noteUnknownDrop(targetId) {
|
|
|
240
273
|
|
|
241
274
|
function route(targetId, url, raw, which) {
|
|
242
275
|
if (guarded && (typeof url !== 'string' || isProtectedUrl(url))) return;
|
|
276
|
+
if (guarded && !tabOrdinary(targetId)) return;
|
|
243
277
|
for (const sub of subscribers.values()) {
|
|
244
278
|
if (sub.targetId !== targetId || !which(sub) || !urlMatches(sub, url)) continue;
|
|
245
279
|
const body = parseFrame(raw, sub.filter?.parseAs);
|
|
@@ -248,6 +282,369 @@ function route(targetId, url, raw, which) {
|
|
|
248
282
|
}
|
|
249
283
|
}
|
|
250
284
|
|
|
285
|
+
function frameUrl(frame) {
|
|
286
|
+
const base = typeof frame?.url === 'string' ? frame.url : '';
|
|
287
|
+
const fragment = typeof frame?.urlFragment === 'string' ? frame.urlFragment : '';
|
|
288
|
+
return `${base}${fragment}`;
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function clearTabSockets(targetId) {
|
|
292
|
+
const sessionIds = new Set();
|
|
293
|
+
for (const [sessionId, tab] of tabsBySession) {
|
|
294
|
+
if (tab === targetId) sessionIds.add(sessionId);
|
|
295
|
+
}
|
|
296
|
+
const current = sessions.get(targetId);
|
|
297
|
+
if (typeof current === 'string') sessionIds.add(current);
|
|
298
|
+
for (const key of [...sockets.keys()]) {
|
|
299
|
+
const at = key.indexOf(' ');
|
|
300
|
+
const sessionId = at === -1 ? key : key.slice(0, at);
|
|
301
|
+
if (!sessionIds.has(sessionId)) continue;
|
|
302
|
+
sockets.delete(key);
|
|
303
|
+
held.delete(key);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function setDocumentClass(targetId, protectedDocument) {
|
|
308
|
+
if (!guarded) return;
|
|
309
|
+
const next = protectedDocument ? 'protected' : 'ordinary';
|
|
310
|
+
documents.set(targetId, next);
|
|
311
|
+
if (next !== 'protected') return;
|
|
312
|
+
queueMicrotask(() => {
|
|
313
|
+
clearTabSockets(targetId);
|
|
314
|
+
dropSubscribers(targetId);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
function bumpDocumentGen(targetId) {
|
|
319
|
+
documentGens.set(targetId, (documentGens.get(targetId) ?? 0) + 1);
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
function forgetDocument(targetId) {
|
|
323
|
+
documents.delete(targetId);
|
|
324
|
+
mainFrames.delete(targetId);
|
|
325
|
+
childFrames.delete(targetId);
|
|
326
|
+
frameTreeReads.delete(targetId);
|
|
327
|
+
bumpDocumentGen(targetId);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
function tabOrdinary(targetId) {
|
|
331
|
+
if (documents.get(targetId) !== 'ordinary') return false;
|
|
332
|
+
const kids = childFrames.get(targetId);
|
|
333
|
+
if (!kids) return true;
|
|
334
|
+
for (const cls of kids.values()) {
|
|
335
|
+
if (cls !== 'ordinary') return false;
|
|
336
|
+
}
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
function clearChildFrames(targetId) {
|
|
341
|
+
childFrames.delete(targetId);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
function setChildFrameClass(targetId, frameId, next) {
|
|
345
|
+
if (!guarded || typeof frameId !== 'string') return;
|
|
346
|
+
let kids = childFrames.get(targetId);
|
|
347
|
+
if (!kids) {
|
|
348
|
+
kids = new Map();
|
|
349
|
+
childFrames.set(targetId, kids);
|
|
350
|
+
}
|
|
351
|
+
kids.set(frameId, next);
|
|
352
|
+
if (next !== 'protected') return;
|
|
353
|
+
clearTabSockets(targetId);
|
|
354
|
+
dropSubscribers(targetId);
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function scheduleFrameTreeRead(targetId) {
|
|
358
|
+
if (!guarded) return;
|
|
359
|
+
let state = frameTreeReads.get(targetId);
|
|
360
|
+
if (!state) {
|
|
361
|
+
state = { dirty: false, running: false };
|
|
362
|
+
frameTreeReads.set(targetId, state);
|
|
363
|
+
}
|
|
364
|
+
state.dirty = true;
|
|
365
|
+
if (state.running) return;
|
|
366
|
+
state.running = true;
|
|
367
|
+
queueMicrotask(() => {
|
|
368
|
+
void runFrameTreeReads(targetId);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
async function runFrameTreeReads(targetId) {
|
|
373
|
+
const state = frameTreeReads.get(targetId);
|
|
374
|
+
if (!state) return;
|
|
375
|
+
try {
|
|
376
|
+
while (guarded && state.dirty) {
|
|
377
|
+
state.dirty = false;
|
|
378
|
+
const sessionId = sessions.get(targetId);
|
|
379
|
+
if (typeof sessionId !== 'string') break;
|
|
380
|
+
const gen = documentGens.get(targetId) ?? 0;
|
|
381
|
+
const client = await openClient().catch(() => undefined);
|
|
382
|
+
if (!client || !guarded || sessions.get(targetId) !== sessionId) break;
|
|
383
|
+
const result = await client.send('Page.getFrameTree', {}, sessionId);
|
|
384
|
+
if (!guarded || sessions.get(targetId) !== sessionId) break;
|
|
385
|
+
if ((documentGens.get(targetId) ?? 0) !== gen) continue;
|
|
386
|
+
const tree = result?.frameTree;
|
|
387
|
+
if (!tree || typeof tree !== 'object') continue;
|
|
388
|
+
applyFrameTree(targetId, tree, { onlyUnknown: true });
|
|
389
|
+
}
|
|
390
|
+
} catch {
|
|
391
|
+
undefined;
|
|
392
|
+
} finally {
|
|
393
|
+
state.running = false;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
function applyFrameTree(targetId, tree, { onlyUnknown = false } = {}) {
|
|
398
|
+
const root = tree.frame;
|
|
399
|
+
if (root && typeof root.id === 'string' && !mainFrames.has(targetId)) {
|
|
400
|
+
mainFrames.set(targetId, root.id);
|
|
401
|
+
}
|
|
402
|
+
walkFrameTree(targetId, tree.childFrames, root?.id, onlyUnknown);
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
function resolveTreeFrame(targetId, frame, parentId, onlyUnknown) {
|
|
406
|
+
const current = childFrames.get(targetId)?.get(frame.id);
|
|
407
|
+
if (onlyUnknown && current !== 'unknown') return;
|
|
408
|
+
if (!onlyUnknown && current !== undefined && current !== 'unknown') return;
|
|
409
|
+
const url = typeof frame.url === 'string' ? frame.url : '';
|
|
410
|
+
if (url.length === 0) {
|
|
411
|
+
if (current === undefined) setChildFrameClass(targetId, frame.id, 'unknown');
|
|
412
|
+
return;
|
|
413
|
+
}
|
|
414
|
+
const pid = typeof frame.parentId === 'string' ? frame.parentId : parentId;
|
|
415
|
+
setChildFrameClass(
|
|
416
|
+
targetId,
|
|
417
|
+
frame.id,
|
|
418
|
+
classifyChildFrame(targetId, pid, frameUrl(frame), {
|
|
419
|
+
documentURL: frame.url,
|
|
420
|
+
unreachableURL: frame.unreachableUrl,
|
|
421
|
+
})
|
|
422
|
+
);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
function walkFrameTree(targetId, list, parentId, onlyUnknown) {
|
|
426
|
+
if (!Array.isArray(list)) return;
|
|
427
|
+
for (const node of list) {
|
|
428
|
+
if (!node || typeof node !== 'object') continue;
|
|
429
|
+
const frame = node.frame;
|
|
430
|
+
if (!frame || typeof frame.id !== 'string') continue;
|
|
431
|
+
resolveTreeFrame(targetId, frame, parentId, onlyUnknown);
|
|
432
|
+
walkFrameTree(targetId, node.childFrames, frame.id, onlyUnknown);
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
function parentFrameClass(targetId, parentId) {
|
|
437
|
+
const main = mainFrames.get(targetId);
|
|
438
|
+
if (parentId === undefined || parentId === main || parentId === targetId) {
|
|
439
|
+
return documents.get(targetId);
|
|
440
|
+
}
|
|
441
|
+
return childFrames.get(targetId)?.get(parentId);
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function childUrlProtected(url, extra = {}) {
|
|
445
|
+
if (typeof url !== 'string' || url.length === 0) return false;
|
|
446
|
+
if (url.startsWith('chrome-error:')) return true;
|
|
447
|
+
if (url.startsWith('data:') || inheritingDocumentUrl(url)) return false;
|
|
448
|
+
return isProtectedDocument({ url, previous: false, ...extra });
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
function classifyChildFrame(targetId, parentId, url, extra = {}) {
|
|
452
|
+
if (childUrlProtected(url, extra)) return 'protected';
|
|
453
|
+
const parentCls = parentFrameClass(targetId, parentId);
|
|
454
|
+
if (parentCls === undefined || parentCls === 'unknown') return 'unknown';
|
|
455
|
+
if (typeof url === 'string' && url.startsWith('data:')) return parentCls;
|
|
456
|
+
const previous = parentCls === 'protected';
|
|
457
|
+
return isProtectedDocument({ url, previous, ...extra }) ? 'protected' : 'ordinary';
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
function dropSubscribers(targetId) {
|
|
461
|
+
let removed = false;
|
|
462
|
+
for (const [id, sub] of subscribers) {
|
|
463
|
+
if (sub.targetId !== targetId) continue;
|
|
464
|
+
subscribers.delete(id);
|
|
465
|
+
removed = true;
|
|
466
|
+
}
|
|
467
|
+
if (removed) release();
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
function applyDocumentUrl(targetId, fields) {
|
|
471
|
+
if (!guarded) return;
|
|
472
|
+
const url = fields.url;
|
|
473
|
+
if (typeof url !== 'string' || url.length === 0) return;
|
|
474
|
+
if (!documents.has(targetId) && inheritingDocumentUrl(url)) return;
|
|
475
|
+
const previous = documents.get(targetId) === 'protected';
|
|
476
|
+
setDocumentClass(
|
|
477
|
+
targetId,
|
|
478
|
+
isProtectedDocument({
|
|
479
|
+
...fields,
|
|
480
|
+
url,
|
|
481
|
+
previous,
|
|
482
|
+
})
|
|
483
|
+
);
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
function endTabSession(targetId, sessionId) {
|
|
487
|
+
if (typeof sessionId === 'string') {
|
|
488
|
+
tabsBySession.delete(sessionId);
|
|
489
|
+
networkless.delete(sessionId);
|
|
490
|
+
recorders.delete(sessionId);
|
|
491
|
+
}
|
|
492
|
+
if (sessions.get(targetId) === sessionId || sessionId === undefined) {
|
|
493
|
+
sessions.delete(targetId);
|
|
494
|
+
}
|
|
495
|
+
forgetDocument(targetId);
|
|
496
|
+
dropSubscribers(targetId);
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
function onSessionEnded(message) {
|
|
500
|
+
if (!guarded) return;
|
|
501
|
+
const sessionId = message?.params?.sessionId ?? message?.sessionId;
|
|
502
|
+
if (typeof sessionId !== 'string') return;
|
|
503
|
+
const targetId = tabsBySession.get(sessionId);
|
|
504
|
+
if (targetId === undefined) return;
|
|
505
|
+
endTabSession(targetId, sessionId);
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
function onTargetGone(targetId) {
|
|
509
|
+
if (!guarded || typeof targetId !== 'string') return;
|
|
510
|
+
const sessionId = sessions.get(targetId);
|
|
511
|
+
endTabSession(targetId, sessionId);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
async function seedDocumentClass(client, targetId, sessionId) {
|
|
515
|
+
if (!guarded || documents.has(targetId)) return;
|
|
516
|
+
const result = await client.send('Target.getTargets').catch(() => undefined);
|
|
517
|
+
if (!guarded || documents.has(targetId)) return;
|
|
518
|
+
if (sessions.get(targetId) !== sessionId) return;
|
|
519
|
+
const infos = Array.isArray(result?.targetInfos) ? result.targetInfos : [];
|
|
520
|
+
const info = infos.find(
|
|
521
|
+
(entry) => entry && typeof entry.targetId === 'string' && entry.targetId === targetId
|
|
522
|
+
);
|
|
523
|
+
if (!info || typeof info.url !== 'string' || info.url.length === 0) return;
|
|
524
|
+
if (inheritingDocumentUrl(info.url)) return;
|
|
525
|
+
if (documents.has(targetId)) return;
|
|
526
|
+
if (sessions.get(targetId) !== sessionId) return;
|
|
527
|
+
applyDocumentUrl(targetId, { url: info.url, type: info.type });
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
function onFrameNavigated(message) {
|
|
531
|
+
const frame = message?.params?.frame;
|
|
532
|
+
if (!frame || typeof frame !== 'object') return;
|
|
533
|
+
const targetId = tabsBySession.get(message.sessionId);
|
|
534
|
+
if (targetId === undefined) return;
|
|
535
|
+
if (frame.parentId === undefined) {
|
|
536
|
+
bumpDocumentGen(targetId);
|
|
537
|
+
clearChildFrames(targetId);
|
|
538
|
+
clearTabSockets(targetId);
|
|
539
|
+
if (typeof frame.id === 'string') mainFrames.set(targetId, frame.id);
|
|
540
|
+
applyDocumentUrl(targetId, {
|
|
541
|
+
url: frameUrl(frame),
|
|
542
|
+
documentURL: typeof frame.url === 'string' ? frame.url : undefined,
|
|
543
|
+
unreachableURL: frame.unreachableUrl,
|
|
544
|
+
});
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (typeof frame.id !== 'string') return;
|
|
548
|
+
if (typeof frame.url !== 'string' || frame.url.length === 0) {
|
|
549
|
+
scheduleFrameTreeRead(targetId);
|
|
550
|
+
return;
|
|
551
|
+
}
|
|
552
|
+
const parentId = typeof frame.parentId === 'string' ? frame.parentId : undefined;
|
|
553
|
+
setChildFrameClass(
|
|
554
|
+
targetId,
|
|
555
|
+
frame.id,
|
|
556
|
+
classifyChildFrame(targetId, parentId, frameUrl(frame), {
|
|
557
|
+
documentURL: frame.url,
|
|
558
|
+
unreachableURL: frame.unreachableUrl,
|
|
559
|
+
})
|
|
560
|
+
);
|
|
561
|
+
scheduleFrameTreeRead(targetId);
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
function onFrameAttached(message) {
|
|
565
|
+
const params = message?.params ?? {};
|
|
566
|
+
const targetId = tabsBySession.get(message.sessionId);
|
|
567
|
+
if (targetId === undefined) return;
|
|
568
|
+
const frameId = typeof params.frameId === 'string' ? params.frameId : undefined;
|
|
569
|
+
if (frameId === undefined) return;
|
|
570
|
+
setChildFrameClass(targetId, frameId, 'unknown');
|
|
571
|
+
scheduleFrameTreeRead(targetId);
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
function onFrameDetached(message) {
|
|
575
|
+
const params = message?.params ?? {};
|
|
576
|
+
const targetId = tabsBySession.get(message.sessionId);
|
|
577
|
+
if (targetId === undefined) return;
|
|
578
|
+
const frameId = typeof params.frameId === 'string' ? params.frameId : undefined;
|
|
579
|
+
if (frameId === undefined) return;
|
|
580
|
+
const kids = childFrames.get(targetId);
|
|
581
|
+
if (!kids) return;
|
|
582
|
+
kids.delete(frameId);
|
|
583
|
+
if (kids.size === 0) childFrames.delete(targetId);
|
|
584
|
+
scheduleFrameTreeRead(targetId);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function onNavigatedWithinDocument(message) {
|
|
588
|
+
const params = message?.params ?? {};
|
|
589
|
+
const targetId = tabsBySession.get(message.sessionId);
|
|
590
|
+
if (targetId === undefined) return;
|
|
591
|
+
const frameId = typeof params.frameId === 'string' ? params.frameId : undefined;
|
|
592
|
+
const main = mainFrames.get(targetId);
|
|
593
|
+
if (frameId !== undefined && frameId !== main && frameId !== targetId) {
|
|
594
|
+
if (typeof params.url !== 'string' || params.url.length === 0) {
|
|
595
|
+
scheduleFrameTreeRead(targetId);
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
const url = params.url;
|
|
599
|
+
const current = childFrames.get(targetId)?.get(frameId);
|
|
600
|
+
if (current === undefined || current === 'unknown') {
|
|
601
|
+
if (childUrlProtected(url)) {
|
|
602
|
+
setChildFrameClass(targetId, frameId, 'protected');
|
|
603
|
+
} else if (current === undefined) {
|
|
604
|
+
setChildFrameClass(targetId, frameId, 'unknown');
|
|
605
|
+
}
|
|
606
|
+
scheduleFrameTreeRead(targetId);
|
|
607
|
+
return;
|
|
608
|
+
}
|
|
609
|
+
if (url.startsWith('chrome-error:')) {
|
|
610
|
+
setChildFrameClass(targetId, frameId, 'protected');
|
|
611
|
+
scheduleFrameTreeRead(targetId);
|
|
612
|
+
return;
|
|
613
|
+
}
|
|
614
|
+
if (url.startsWith('data:')) {
|
|
615
|
+
setChildFrameClass(targetId, frameId, current);
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
const previous = current === 'protected';
|
|
619
|
+
setChildFrameClass(
|
|
620
|
+
targetId,
|
|
621
|
+
frameId,
|
|
622
|
+
isProtectedDocument({ url, previous }) ? 'protected' : 'ordinary'
|
|
623
|
+
);
|
|
624
|
+
scheduleFrameTreeRead(targetId);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
if (typeof params.url !== 'string') return;
|
|
628
|
+
applyDocumentUrl(targetId, { url: params.url });
|
|
629
|
+
}
|
|
630
|
+
|
|
631
|
+
async function seedFrameTree(client, targetId, sessionId) {
|
|
632
|
+
if (!guarded) return;
|
|
633
|
+
const gen = documentGens.get(targetId) ?? 0;
|
|
634
|
+
const result = await client.send('Page.getFrameTree', {}, sessionId).catch(() => undefined);
|
|
635
|
+
if (!guarded || sessions.get(targetId) !== sessionId) return;
|
|
636
|
+
if ((documentGens.get(targetId) ?? 0) !== gen) return;
|
|
637
|
+
const tree = result?.frameTree;
|
|
638
|
+
if (!tree || typeof tree !== 'object') return;
|
|
639
|
+
applyFrameTree(targetId, tree, { onlyUnknown: false });
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
function onTargetInfo(info) {
|
|
643
|
+
if (!info || typeof info.targetId !== 'string' || typeof info.url !== 'string') return;
|
|
644
|
+
if (info.url.length === 0) return;
|
|
645
|
+
applyDocumentUrl(info.targetId, { url: info.url, type: info.type });
|
|
646
|
+
}
|
|
647
|
+
|
|
251
648
|
function holdFrame(sessionId, targetId, key, raw) {
|
|
252
649
|
const wanted = [...subscribers.values()].some(
|
|
253
650
|
(sub) => sub.targetId === targetId && sub.urlMatch !== undefined
|
|
@@ -857,6 +1254,7 @@ export const websocket = {
|
|
|
857
1254
|
const urlMatchRe =
|
|
858
1255
|
urlMatch === undefined ? undefined : compilePattern(urlMatch, 'browser.websocket');
|
|
859
1256
|
const { sessionId } = await sessionFor(targetId);
|
|
1257
|
+
if (guarded && !tabOrdinary(targetId)) throw new Error(REFUSAL);
|
|
860
1258
|
if (networkless.has(sessionId)) {
|
|
861
1259
|
throw new Error(`browser.websocket: ${networkless.get(sessionId)}`);
|
|
862
1260
|
}
|
package/src/guard.js
CHANGED
|
@@ -127,3 +127,32 @@ export function dropProtectedCookies(cookies) {
|
|
|
127
127
|
export function refuseProtected(text) {
|
|
128
128
|
if (isProtectedUrl(text)) throw new Error(REFUSAL);
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
export function inheritingDocumentUrl(text) {
|
|
132
|
+
return inheritingAbout(text);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function isProtectedDocument({
|
|
136
|
+
url,
|
|
137
|
+
type,
|
|
138
|
+
documentURL,
|
|
139
|
+
unreachableURL,
|
|
140
|
+
previous = false,
|
|
141
|
+
opener,
|
|
142
|
+
navigating = false,
|
|
143
|
+
contextOrigin,
|
|
144
|
+
} = {}) {
|
|
145
|
+
const text = typeof url === 'string' ? url : '';
|
|
146
|
+
const documentText = typeof documentURL === 'string' ? documentURL : '';
|
|
147
|
+
if (text.startsWith('chrome-error:') || documentText.startsWith('chrome-error:')) return true;
|
|
148
|
+
return guard.target({
|
|
149
|
+
url: text,
|
|
150
|
+
type,
|
|
151
|
+
documentURL,
|
|
152
|
+
unreachableURL,
|
|
153
|
+
previous: Boolean(previous),
|
|
154
|
+
opener,
|
|
155
|
+
navigating: Boolean(navigating),
|
|
156
|
+
contextOrigin,
|
|
157
|
+
});
|
|
158
|
+
}
|
package/src/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = '0.1.
|
|
1
|
+
export const version = '0.1.49';
|