Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
ulixee
GitHub Repository: ulixee/secret-agent
Path: blob/main/core/models/FramesTable.ts
1028 views
1
import { Database as SqliteDatabase } from 'better-sqlite3';
2
import SqliteTable from '@secret-agent/commons/SqliteTable';
3
4
export default class FramesTable extends SqliteTable<IFrameRecord> {
5
public frameDomNodePathsById = new Map<number, string>();
6
7
constructor(readonly db: SqliteDatabase) {
8
super(
9
db,
10
'Frames',
11
[
12
['id', 'INTEGER', 'NOT NULL PRIMARY KEY'],
13
['tabId', 'INTEGER'],
14
['domNodeId', 'INTEGER'],
15
['parentId', 'INTEGER'],
16
['name', 'TEXT'],
17
['securityOrigin', 'TEXT'],
18
['startCommandId', 'INTEGER'],
19
['devtoolsFrameId', 'TEXT'],
20
['createdTimestamp', 'INTEGER'],
21
],
22
true,
23
);
24
}
25
26
public insert(frame: IFrameRecord) {
27
this.recordDomNodePath(frame);
28
return this.queuePendingInsert([
29
frame.id,
30
frame.tabId,
31
frame.domNodeId,
32
frame.parentId,
33
frame.name,
34
frame.securityOrigin,
35
frame.startCommandId,
36
frame.devtoolsFrameId,
37
frame.createdTimestamp,
38
]);
39
}
40
41
public all(): IFrameRecord[] {
42
const all = super.all();
43
for (const frame of all) {
44
this.recordDomNodePath(frame);
45
}
46
return all;
47
}
48
49
private recordDomNodePath(frame: IFrameRecord) {
50
if (!frame.parentId) {
51
this.frameDomNodePathsById.set(frame.id, 'main');
52
}
53
if (frame.domNodeId) {
54
const parentPath = this.frameDomNodePathsById.get(frame.parentId);
55
this.frameDomNodePathsById.set(frame.id, `${parentPath ?? ''}_${frame.domNodeId}`);
56
}
57
}
58
}
59
60
export interface IFrameRecord {
61
id: number;
62
tabId: number;
63
parentId?: number; // if null, top level frame
64
domNodeId?: number;
65
startCommandId: number;
66
name?: string;
67
securityOrigin?: string;
68
devtoolsFrameId: string;
69
createdTimestamp: number;
70
}
71
72