chromium-tabs 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +55 -1
- package/dist/chunk-NDM7JYY6.js +40 -0
- package/dist/chunk-NDM7JYY6.js.map +1 -0
- package/dist/{chunk-2DTGNBUT.js → chunk-XUPBZES2.js} +7 -38
- package/dist/chunk-XUPBZES2.js.map +1 -0
- package/dist/command-storage-backend-BLy7EP79.d.cts +318 -0
- package/dist/command-storage-backend-CDoXkRtc.d.ts +318 -0
- package/dist/core/index.d.cts +5 -629
- package/dist/core/index.d.ts +5 -629
- package/dist/core/index.js +7 -5
- package/dist/index.d.cts +5 -2
- package/dist/index.d.ts +5 -2
- package/dist/index.js +7 -5
- package/dist/index.js.map +1 -1
- package/dist/session/index.cjs +1406 -0
- package/dist/session/index.cjs.map +1 -0
- package/dist/session/index.d.cts +479 -0
- package/dist/session/index.d.ts +479 -0
- package/dist/session/index.js +1320 -0
- package/dist/session/index.js.map +1 -0
- package/dist/session/node.cjs +76 -0
- package/dist/session/node.cjs.map +1 -0
- package/dist/session/node.d.cts +34 -0
- package/dist/session/node.d.ts +34 -0
- package/dist/session/node.js +51 -0
- package/dist/session/node.js.map +1 -0
- package/dist/tab-strip-model-DSFYavJO.d.cts +496 -0
- package/dist/tab-strip-model-JBpyUyRs.d.ts +496 -0
- package/dist/types-CYa7ouKw.d.cts +137 -0
- package/dist/types-CYa7ouKw.d.ts +137 -0
- package/package.json +12 -1
- package/dist/chunk-2DTGNBUT.js.map +0 -1
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { d as TabId, T as TabGroupId, a as TabGroupVisualData } from './types-CYa7ouKw.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Session snapshot types. Ported from
|
|
5
|
+
* chromium-reference/components/sessions/core/session_types.h and
|
|
6
|
+
* serialized_navigation_entry.h.
|
|
7
|
+
*
|
|
8
|
+
* These are the plain-data structures produced by replaying a command log
|
|
9
|
+
* (restoreSessionFromCommands) and consumed by session restore. Chrome's
|
|
10
|
+
* SessionTab carries WebContents-specific state (user agent overrides,
|
|
11
|
+
* extension app ids, session storage ids); this port carries the library's
|
|
12
|
+
* generic `data` payload instead, plus the same extra-data escape hatch.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Identifies a window (one TabStripModel) within a session. Chrome uses
|
|
17
|
+
* monotonic int32 SessionIDs (session_id.h); this port uses caller-supplied
|
|
18
|
+
* strings so ids stay stable across process restarts.
|
|
19
|
+
*/
|
|
20
|
+
type SessionWindowId = string;
|
|
21
|
+
declare const DEFAULT_WINDOW_ID: SessionWindowId;
|
|
22
|
+
/**
|
|
23
|
+
* One entry in a tab's navigation history. Trimmed from
|
|
24
|
+
* SerializedNavigationEntry (serialized_navigation_entry.h:88): we keep the
|
|
25
|
+
* fields a headless tab strip can act on. `state` is the analog of Chrome's
|
|
26
|
+
* encoded_page_state — an opaque app-defined blob (scroll position, form
|
|
27
|
+
* state, …) that must be JSON-serializable.
|
|
28
|
+
*/
|
|
29
|
+
interface SerializedNavigationEntry {
|
|
30
|
+
/**
|
|
31
|
+
* Position in the tab's navigation list. Like Chrome's
|
|
32
|
+
* SerializedNavigationEntry::index_, values may have gaps after pruning;
|
|
33
|
+
* order is what matters.
|
|
34
|
+
*/
|
|
35
|
+
index: number;
|
|
36
|
+
url: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
/** Opaque app state for this entry (encoded_page_state analog). */
|
|
39
|
+
state?: unknown;
|
|
40
|
+
/** Wall-clock ms when the entry was created/updated. */
|
|
41
|
+
timestamp?: number;
|
|
42
|
+
}
|
|
43
|
+
/** Mirrors SessionTab (session_types.h:34), adapted to this library. */
|
|
44
|
+
interface SessionTab {
|
|
45
|
+
tabId: TabId;
|
|
46
|
+
windowId: SessionWindowId;
|
|
47
|
+
/**
|
|
48
|
+
* Visual position in the window. Mirrors tab_visual_index. May contain
|
|
49
|
+
* gaps (closed tabs leave holes); restore sorts by it.
|
|
50
|
+
*/
|
|
51
|
+
visualIndex: number;
|
|
52
|
+
pinned: boolean;
|
|
53
|
+
groupId: TabGroupId | null;
|
|
54
|
+
/**
|
|
55
|
+
* Serialized tab data payload (the result of serializeTabData). This is
|
|
56
|
+
* where your url lives if you don't use navigation tracking. Analog of
|
|
57
|
+
* kCommandSetTabData's key/value map, generalized to one JSON value.
|
|
58
|
+
*/
|
|
59
|
+
data: unknown;
|
|
60
|
+
/** Navigation history, sorted ascending by entry index. */
|
|
61
|
+
navigations: SerializedNavigationEntry[];
|
|
62
|
+
/**
|
|
63
|
+
* While rebuilding this is a navigation *index value*; after
|
|
64
|
+
* restoreSessionFromCommands completes it has been remapped to a position
|
|
65
|
+
* in `navigations` (AddTabsToWindows, session_service_commands.cc:404), or
|
|
66
|
+
* -1 when there are no navigations.
|
|
67
|
+
*/
|
|
68
|
+
currentNavigationIndex: number;
|
|
69
|
+
/** Wall-clock ms the tab was last active, if recorded. */
|
|
70
|
+
lastActiveTime?: number;
|
|
71
|
+
/** App-defined string map (kCommandAddTabExtraData). */
|
|
72
|
+
extraData: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
/** Mirrors SessionTabGroup (session_types.h:103). */
|
|
75
|
+
interface SessionTabGroup {
|
|
76
|
+
groupId: TabGroupId;
|
|
77
|
+
visualData: TabGroupVisualData;
|
|
78
|
+
}
|
|
79
|
+
/** Mirrors SessionWindow (session_types.h:120), minus desktop geometry. */
|
|
80
|
+
interface SessionWindow {
|
|
81
|
+
windowId: SessionWindowId;
|
|
82
|
+
/**
|
|
83
|
+
* While rebuilding this is the selected tab's *visual index*; after
|
|
84
|
+
* restoreSessionFromCommands completes it has been remapped to a position
|
|
85
|
+
* in `tabs` (UpdateSelectedTabIndex, session_service_commands.cc:265).
|
|
86
|
+
*/
|
|
87
|
+
selectedTabIndex: number;
|
|
88
|
+
/** Tabs sorted by visual order (SortTabsBasedOnVisualOrderAndClear). */
|
|
89
|
+
tabs: SessionTab[];
|
|
90
|
+
/** Groups referenced by this window's tabs. */
|
|
91
|
+
tabGroups: SessionTabGroup[];
|
|
92
|
+
/** App-defined string map (kCommandAddWindowExtraData). */
|
|
93
|
+
extraData: Record<string, string>;
|
|
94
|
+
}
|
|
95
|
+
/** The result of reading back a persisted session. */
|
|
96
|
+
interface SessionSnapshot {
|
|
97
|
+
/** Windows with at least one restorable tab, in stable windowId order. */
|
|
98
|
+
windows: SessionWindow[];
|
|
99
|
+
activeWindowId: SessionWindowId | null;
|
|
100
|
+
/**
|
|
101
|
+
* True when the log was truncated, corrupted, or contained an unknown
|
|
102
|
+
* command. Mirrors ReadCommandsResult::error_reading — whatever was
|
|
103
|
+
* readable is still returned (the rebuild is fault-tolerant).
|
|
104
|
+
*/
|
|
105
|
+
errorReading: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The selected navigation entry of a restored tab, or null when the tab was
|
|
109
|
+
* persisted without navigation tracking. Convenience over
|
|
110
|
+
* normalized_navigation_index() (session_types.h:62).
|
|
111
|
+
*/
|
|
112
|
+
declare function currentNavigationEntry(tab: SessionTab): SerializedNavigationEntry | null;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Session commands: the persisted mutation log and its rebuild algorithm.
|
|
116
|
+
* Ported from chromium-reference/components/sessions/core/session_service_commands.cc.
|
|
117
|
+
*
|
|
118
|
+
* Chrome appends fixed-size binary payloads (pickles) to an SNSS file; this
|
|
119
|
+
* port keeps the same command ids and semantics but encodes each command as a
|
|
120
|
+
* JSON-serializable object. Restoring a session means replaying the log into
|
|
121
|
+
* SessionTab/SessionWindow structures (RestoreSessionFromCommands, cc:1398).
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Command ids, numbered as in session_service_commands.cc:58-106. Ids that
|
|
126
|
+
* only make sense for a real browser (window bounds, user agent overrides,
|
|
127
|
+
* extension app ids, session storage, split tabs) are not ported; their
|
|
128
|
+
* numbers stay reserved so logs remain comparable to Chrome's.
|
|
129
|
+
*/
|
|
130
|
+
declare const SessionCommandId: {
|
|
131
|
+
readonly SET_TAB_WINDOW: 0;
|
|
132
|
+
readonly SET_TAB_INDEX_IN_WINDOW: 2;
|
|
133
|
+
readonly UPDATE_TAB_NAVIGATION: 6;
|
|
134
|
+
readonly SET_SELECTED_NAVIGATION_INDEX: 7;
|
|
135
|
+
readonly SET_SELECTED_TAB_IN_INDEX: 8;
|
|
136
|
+
readonly SET_PINNED_STATE: 12;
|
|
137
|
+
readonly TAB_CLOSED: 16;
|
|
138
|
+
readonly WINDOW_CLOSED: 17;
|
|
139
|
+
readonly SET_ACTIVE_WINDOW: 20;
|
|
140
|
+
readonly LAST_ACTIVE_TIME: 21;
|
|
141
|
+
readonly TAB_NAVIGATION_PATH_PRUNED: 24;
|
|
142
|
+
readonly SET_TAB_GROUP: 25;
|
|
143
|
+
readonly SET_TAB_GROUP_METADATA2: 27;
|
|
144
|
+
readonly SET_TAB_DATA: 30;
|
|
145
|
+
readonly ADD_TAB_EXTRA_DATA: 33;
|
|
146
|
+
readonly ADD_WINDOW_EXTRA_DATA: 34;
|
|
147
|
+
};
|
|
148
|
+
type SessionCommand = {
|
|
149
|
+
id: 0;
|
|
150
|
+
windowId: SessionWindowId;
|
|
151
|
+
tabId: TabId;
|
|
152
|
+
} | {
|
|
153
|
+
id: 2;
|
|
154
|
+
tabId: TabId;
|
|
155
|
+
index: number;
|
|
156
|
+
} | {
|
|
157
|
+
id: 6;
|
|
158
|
+
tabId: TabId;
|
|
159
|
+
navigation: SerializedNavigationEntry;
|
|
160
|
+
} | {
|
|
161
|
+
id: 7;
|
|
162
|
+
tabId: TabId;
|
|
163
|
+
index: number;
|
|
164
|
+
} | {
|
|
165
|
+
id: 8;
|
|
166
|
+
windowId: SessionWindowId;
|
|
167
|
+
index: number;
|
|
168
|
+
} | {
|
|
169
|
+
id: 12;
|
|
170
|
+
tabId: TabId;
|
|
171
|
+
pinned: boolean;
|
|
172
|
+
} | {
|
|
173
|
+
id: 16;
|
|
174
|
+
tabId: TabId;
|
|
175
|
+
closeTime: number;
|
|
176
|
+
} | {
|
|
177
|
+
id: 17;
|
|
178
|
+
windowId: SessionWindowId;
|
|
179
|
+
closeTime: number;
|
|
180
|
+
} | {
|
|
181
|
+
id: 20;
|
|
182
|
+
windowId: SessionWindowId;
|
|
183
|
+
} | {
|
|
184
|
+
id: 21;
|
|
185
|
+
tabId: TabId;
|
|
186
|
+
lastActiveTime: number;
|
|
187
|
+
} | {
|
|
188
|
+
id: 24;
|
|
189
|
+
tabId: TabId;
|
|
190
|
+
index: number;
|
|
191
|
+
count: number;
|
|
192
|
+
} | {
|
|
193
|
+
id: 25;
|
|
194
|
+
tabId: TabId;
|
|
195
|
+
groupId: TabGroupId | null;
|
|
196
|
+
} | {
|
|
197
|
+
id: 27;
|
|
198
|
+
groupId: TabGroupId;
|
|
199
|
+
visualData: TabGroupVisualData;
|
|
200
|
+
} | {
|
|
201
|
+
id: 30;
|
|
202
|
+
tabId: TabId;
|
|
203
|
+
data: unknown;
|
|
204
|
+
} | {
|
|
205
|
+
id: 33;
|
|
206
|
+
tabId: TabId;
|
|
207
|
+
key: string;
|
|
208
|
+
value: string;
|
|
209
|
+
} | {
|
|
210
|
+
id: 34;
|
|
211
|
+
windowId: SessionWindowId;
|
|
212
|
+
key: string;
|
|
213
|
+
value: string;
|
|
214
|
+
};
|
|
215
|
+
declare function createSetTabWindowCommand(windowId: SessionWindowId, tabId: TabId): SessionCommand;
|
|
216
|
+
declare function createSetTabIndexInWindowCommand(tabId: TabId, index: number): SessionCommand;
|
|
217
|
+
declare function createUpdateTabNavigationCommand(tabId: TabId, navigation: SerializedNavigationEntry): SessionCommand;
|
|
218
|
+
declare function createSetSelectedNavigationIndexCommand(tabId: TabId, index: number): SessionCommand;
|
|
219
|
+
declare function createSetSelectedTabInWindowCommand(windowId: SessionWindowId, index: number): SessionCommand;
|
|
220
|
+
declare function createPinnedStateCommand(tabId: TabId, pinned: boolean): SessionCommand;
|
|
221
|
+
declare function createTabClosedCommand(tabId: TabId, closeTime?: number): SessionCommand;
|
|
222
|
+
declare function createWindowClosedCommand(windowId: SessionWindowId, closeTime?: number): SessionCommand;
|
|
223
|
+
declare function createSetActiveWindowCommand(windowId: SessionWindowId): SessionCommand;
|
|
224
|
+
declare function createLastActiveTimeCommand(tabId: TabId, lastActiveTime: number): SessionCommand;
|
|
225
|
+
declare function createTabNavigationPathPrunedCommand(tabId: TabId, index: number, count: number): SessionCommand;
|
|
226
|
+
declare function createTabGroupCommand(tabId: TabId, groupId: TabGroupId | null): SessionCommand;
|
|
227
|
+
declare function createTabGroupMetadataUpdateCommand(groupId: TabGroupId, visualData: TabGroupVisualData): SessionCommand;
|
|
228
|
+
declare function createSetTabDataCommand(tabId: TabId, data: unknown): SessionCommand;
|
|
229
|
+
declare function createAddTabExtraDataCommand(tabId: TabId, key: string, value: string): SessionCommand;
|
|
230
|
+
declare function createAddWindowExtraDataCommand(windowId: SessionWindowId, key: string, value: string): SessionCommand;
|
|
231
|
+
/**
|
|
232
|
+
* True for commands recording a close. Closing commands never trigger a
|
|
233
|
+
* rebuild — resetting right after a close could lose the state we want to
|
|
234
|
+
* restore. Mirrors IsClosingCommand (session_service_commands.cc:1374).
|
|
235
|
+
*/
|
|
236
|
+
declare function isClosingCommand(command: SessionCommand): boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Returns the position of the first navigation whose index is >= `index`,
|
|
239
|
+
* or navigations.length. Navigations are sorted ascending by index.
|
|
240
|
+
* Mirrors FindClosestNavigationWithIndex (session_service_commands.cc:339).
|
|
241
|
+
*/
|
|
242
|
+
declare function findClosestNavigationWithIndex(navigations: readonly SerializedNavigationEntry[], index: number): number;
|
|
243
|
+
/**
|
|
244
|
+
* Removes `count` navigation entries starting at index value `index`,
|
|
245
|
+
* fixing up the selected index and renumbering survivors. Mirrors
|
|
246
|
+
* ProcessTabNavigationPathPrunedCommand (session_service_commands.cc:489).
|
|
247
|
+
*/
|
|
248
|
+
declare function processTabNavigationPathPruned(tab: Pick<SessionTab, 'navigations' | 'currentNavigationIndex'>, index: number, count: number): void;
|
|
249
|
+
/**
|
|
250
|
+
* Replays a command log into restorable windows. Port of
|
|
251
|
+
* RestoreSessionFromCommands (session_service_commands.cc:1398):
|
|
252
|
+
*
|
|
253
|
+
* 1. CreateTabsAndWindows (cc:521) — apply each command to lazily-created
|
|
254
|
+
* tab/window/group entries, stopping at the first malformed command.
|
|
255
|
+
* 2. AddTabsToWindows (cc:404) — attach tabs to their windows, dropping
|
|
256
|
+
* tabs that never got a window; remap each tab's selected-navigation
|
|
257
|
+
* *index value* to a position in its navigations array.
|
|
258
|
+
* 3. SortTabsBasedOnVisualOrderAndClear (cc:372) — order tabs by visual
|
|
259
|
+
* index and drop windows with no tabs.
|
|
260
|
+
* 4. UpdateSelectedTabIndex (cc:265) — remap each window's selected-tab
|
|
261
|
+
* *visual index* to a position in its tabs array.
|
|
262
|
+
*
|
|
263
|
+
* Deviation from Chrome: tabs without navigation entries are kept when they
|
|
264
|
+
* carry a data payload — this library's data-only persistence mode has no
|
|
265
|
+
* navigation list, but the tab is still fully restorable from `data`.
|
|
266
|
+
*/
|
|
267
|
+
declare function restoreSessionFromCommands(commands: readonly SessionCommand[]): SessionSnapshot;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Storage backend interface. Ported from
|
|
271
|
+
* chromium-reference/components/sessions/core/command_storage_backend.h.
|
|
272
|
+
*
|
|
273
|
+
* Chrome's backend owns timestamped SNSS files under Sessions/ and tracks
|
|
274
|
+
* which one is the "last session" (the previous run) versus the "current
|
|
275
|
+
* session" (this run). This port reduces that to two slots — `current` and
|
|
276
|
+
* `last` — over any storage primitive. Implementations may be synchronous
|
|
277
|
+
* (web storage) or asynchronous (IndexedDB, files); CommandStorageManager
|
|
278
|
+
* awaits either.
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
/** Mirrors CommandStorageBackend::ReadCommandsResult (h:81). */
|
|
282
|
+
interface ReadCommandsResult {
|
|
283
|
+
commands: SessionCommand[];
|
|
284
|
+
/**
|
|
285
|
+
* True when the stored data was missing pieces, unparsable, or otherwise
|
|
286
|
+
* suspect. Whatever could be read is still in `commands`.
|
|
287
|
+
*/
|
|
288
|
+
errorReading: boolean;
|
|
289
|
+
}
|
|
290
|
+
interface CommandStorageBackend {
|
|
291
|
+
/**
|
|
292
|
+
* Identifies this storage area for cross-realm singleton coordination —
|
|
293
|
+
* the analog of Chrome naming its ProcessSingleton after the user data
|
|
294
|
+
* directory (process_singleton.h:45). Backends that can be reached from
|
|
295
|
+
* several realms at once (web storage) must provide it; backends that
|
|
296
|
+
* cannot (in-memory) leave it undefined and the service acts as sole
|
|
297
|
+
* owner.
|
|
298
|
+
*/
|
|
299
|
+
readonly profileLockName?: string;
|
|
300
|
+
/**
|
|
301
|
+
* Persists commands to the current session. With `truncate` the current
|
|
302
|
+
* session is replaced wholesale (the pending commands are a complete
|
|
303
|
+
* snapshot); otherwise they are appended. Mirrors
|
|
304
|
+
* CommandStorageBackend::AppendCommands (h:120).
|
|
305
|
+
*/
|
|
306
|
+
appendCommands(commands: readonly SessionCommand[], truncate: boolean): void | Promise<void>;
|
|
307
|
+
/** Reads the previous session's log. Mirrors GetLastSessionCommands. */
|
|
308
|
+
readLastSessionCommands(): ReadCommandsResult | Promise<ReadCommandsResult>;
|
|
309
|
+
/**
|
|
310
|
+
* Promotes the current session to "last" and starts an empty current
|
|
311
|
+
* session. When no current session exists (the previous run died before
|
|
312
|
+
* its first save), the existing last session is left untouched so it can
|
|
313
|
+
* still be restored. Mirrors MoveCurrentSessionToLastSession (h:131).
|
|
314
|
+
*/
|
|
315
|
+
moveCurrentSessionToLastSession(): void | Promise<void>;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export { processTabNavigationPathPruned as A, restoreSessionFromCommands as B, type CommandStorageBackend as C, DEFAULT_WINDOW_ID as D, type ReadCommandsResult as R, type SessionCommand as S, type SessionTab as a, type SessionWindow as b, type SessionWindowId as c, type SessionSnapshot as d, type SerializedNavigationEntry as e, SessionCommandId as f, type SessionTabGroup as g, createAddTabExtraDataCommand as h, createAddWindowExtraDataCommand as i, createLastActiveTimeCommand as j, createPinnedStateCommand as k, createSetActiveWindowCommand as l, createSetSelectedNavigationIndexCommand as m, createSetSelectedTabInWindowCommand as n, createSetTabDataCommand as o, createSetTabIndexInWindowCommand as p, createSetTabWindowCommand as q, createTabClosedCommand as r, createTabGroupCommand as s, createTabGroupMetadataUpdateCommand as t, createTabNavigationPathPrunedCommand as u, createUpdateTabNavigationCommand as v, createWindowClosedCommand as w, currentNavigationEntry as x, findClosestNavigationWithIndex as y, isClosingCommand as z };
|
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
import { d as TabId, T as TabGroupId, a as TabGroupVisualData } from './types-CYa7ouKw.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Session snapshot types. Ported from
|
|
5
|
+
* chromium-reference/components/sessions/core/session_types.h and
|
|
6
|
+
* serialized_navigation_entry.h.
|
|
7
|
+
*
|
|
8
|
+
* These are the plain-data structures produced by replaying a command log
|
|
9
|
+
* (restoreSessionFromCommands) and consumed by session restore. Chrome's
|
|
10
|
+
* SessionTab carries WebContents-specific state (user agent overrides,
|
|
11
|
+
* extension app ids, session storage ids); this port carries the library's
|
|
12
|
+
* generic `data` payload instead, plus the same extra-data escape hatch.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Identifies a window (one TabStripModel) within a session. Chrome uses
|
|
17
|
+
* monotonic int32 SessionIDs (session_id.h); this port uses caller-supplied
|
|
18
|
+
* strings so ids stay stable across process restarts.
|
|
19
|
+
*/
|
|
20
|
+
type SessionWindowId = string;
|
|
21
|
+
declare const DEFAULT_WINDOW_ID: SessionWindowId;
|
|
22
|
+
/**
|
|
23
|
+
* One entry in a tab's navigation history. Trimmed from
|
|
24
|
+
* SerializedNavigationEntry (serialized_navigation_entry.h:88): we keep the
|
|
25
|
+
* fields a headless tab strip can act on. `state` is the analog of Chrome's
|
|
26
|
+
* encoded_page_state — an opaque app-defined blob (scroll position, form
|
|
27
|
+
* state, …) that must be JSON-serializable.
|
|
28
|
+
*/
|
|
29
|
+
interface SerializedNavigationEntry {
|
|
30
|
+
/**
|
|
31
|
+
* Position in the tab's navigation list. Like Chrome's
|
|
32
|
+
* SerializedNavigationEntry::index_, values may have gaps after pruning;
|
|
33
|
+
* order is what matters.
|
|
34
|
+
*/
|
|
35
|
+
index: number;
|
|
36
|
+
url: string;
|
|
37
|
+
title?: string;
|
|
38
|
+
/** Opaque app state for this entry (encoded_page_state analog). */
|
|
39
|
+
state?: unknown;
|
|
40
|
+
/** Wall-clock ms when the entry was created/updated. */
|
|
41
|
+
timestamp?: number;
|
|
42
|
+
}
|
|
43
|
+
/** Mirrors SessionTab (session_types.h:34), adapted to this library. */
|
|
44
|
+
interface SessionTab {
|
|
45
|
+
tabId: TabId;
|
|
46
|
+
windowId: SessionWindowId;
|
|
47
|
+
/**
|
|
48
|
+
* Visual position in the window. Mirrors tab_visual_index. May contain
|
|
49
|
+
* gaps (closed tabs leave holes); restore sorts by it.
|
|
50
|
+
*/
|
|
51
|
+
visualIndex: number;
|
|
52
|
+
pinned: boolean;
|
|
53
|
+
groupId: TabGroupId | null;
|
|
54
|
+
/**
|
|
55
|
+
* Serialized tab data payload (the result of serializeTabData). This is
|
|
56
|
+
* where your url lives if you don't use navigation tracking. Analog of
|
|
57
|
+
* kCommandSetTabData's key/value map, generalized to one JSON value.
|
|
58
|
+
*/
|
|
59
|
+
data: unknown;
|
|
60
|
+
/** Navigation history, sorted ascending by entry index. */
|
|
61
|
+
navigations: SerializedNavigationEntry[];
|
|
62
|
+
/**
|
|
63
|
+
* While rebuilding this is a navigation *index value*; after
|
|
64
|
+
* restoreSessionFromCommands completes it has been remapped to a position
|
|
65
|
+
* in `navigations` (AddTabsToWindows, session_service_commands.cc:404), or
|
|
66
|
+
* -1 when there are no navigations.
|
|
67
|
+
*/
|
|
68
|
+
currentNavigationIndex: number;
|
|
69
|
+
/** Wall-clock ms the tab was last active, if recorded. */
|
|
70
|
+
lastActiveTime?: number;
|
|
71
|
+
/** App-defined string map (kCommandAddTabExtraData). */
|
|
72
|
+
extraData: Record<string, string>;
|
|
73
|
+
}
|
|
74
|
+
/** Mirrors SessionTabGroup (session_types.h:103). */
|
|
75
|
+
interface SessionTabGroup {
|
|
76
|
+
groupId: TabGroupId;
|
|
77
|
+
visualData: TabGroupVisualData;
|
|
78
|
+
}
|
|
79
|
+
/** Mirrors SessionWindow (session_types.h:120), minus desktop geometry. */
|
|
80
|
+
interface SessionWindow {
|
|
81
|
+
windowId: SessionWindowId;
|
|
82
|
+
/**
|
|
83
|
+
* While rebuilding this is the selected tab's *visual index*; after
|
|
84
|
+
* restoreSessionFromCommands completes it has been remapped to a position
|
|
85
|
+
* in `tabs` (UpdateSelectedTabIndex, session_service_commands.cc:265).
|
|
86
|
+
*/
|
|
87
|
+
selectedTabIndex: number;
|
|
88
|
+
/** Tabs sorted by visual order (SortTabsBasedOnVisualOrderAndClear). */
|
|
89
|
+
tabs: SessionTab[];
|
|
90
|
+
/** Groups referenced by this window's tabs. */
|
|
91
|
+
tabGroups: SessionTabGroup[];
|
|
92
|
+
/** App-defined string map (kCommandAddWindowExtraData). */
|
|
93
|
+
extraData: Record<string, string>;
|
|
94
|
+
}
|
|
95
|
+
/** The result of reading back a persisted session. */
|
|
96
|
+
interface SessionSnapshot {
|
|
97
|
+
/** Windows with at least one restorable tab, in stable windowId order. */
|
|
98
|
+
windows: SessionWindow[];
|
|
99
|
+
activeWindowId: SessionWindowId | null;
|
|
100
|
+
/**
|
|
101
|
+
* True when the log was truncated, corrupted, or contained an unknown
|
|
102
|
+
* command. Mirrors ReadCommandsResult::error_reading — whatever was
|
|
103
|
+
* readable is still returned (the rebuild is fault-tolerant).
|
|
104
|
+
*/
|
|
105
|
+
errorReading: boolean;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* The selected navigation entry of a restored tab, or null when the tab was
|
|
109
|
+
* persisted without navigation tracking. Convenience over
|
|
110
|
+
* normalized_navigation_index() (session_types.h:62).
|
|
111
|
+
*/
|
|
112
|
+
declare function currentNavigationEntry(tab: SessionTab): SerializedNavigationEntry | null;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Session commands: the persisted mutation log and its rebuild algorithm.
|
|
116
|
+
* Ported from chromium-reference/components/sessions/core/session_service_commands.cc.
|
|
117
|
+
*
|
|
118
|
+
* Chrome appends fixed-size binary payloads (pickles) to an SNSS file; this
|
|
119
|
+
* port keeps the same command ids and semantics but encodes each command as a
|
|
120
|
+
* JSON-serializable object. Restoring a session means replaying the log into
|
|
121
|
+
* SessionTab/SessionWindow structures (RestoreSessionFromCommands, cc:1398).
|
|
122
|
+
*/
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Command ids, numbered as in session_service_commands.cc:58-106. Ids that
|
|
126
|
+
* only make sense for a real browser (window bounds, user agent overrides,
|
|
127
|
+
* extension app ids, session storage, split tabs) are not ported; their
|
|
128
|
+
* numbers stay reserved so logs remain comparable to Chrome's.
|
|
129
|
+
*/
|
|
130
|
+
declare const SessionCommandId: {
|
|
131
|
+
readonly SET_TAB_WINDOW: 0;
|
|
132
|
+
readonly SET_TAB_INDEX_IN_WINDOW: 2;
|
|
133
|
+
readonly UPDATE_TAB_NAVIGATION: 6;
|
|
134
|
+
readonly SET_SELECTED_NAVIGATION_INDEX: 7;
|
|
135
|
+
readonly SET_SELECTED_TAB_IN_INDEX: 8;
|
|
136
|
+
readonly SET_PINNED_STATE: 12;
|
|
137
|
+
readonly TAB_CLOSED: 16;
|
|
138
|
+
readonly WINDOW_CLOSED: 17;
|
|
139
|
+
readonly SET_ACTIVE_WINDOW: 20;
|
|
140
|
+
readonly LAST_ACTIVE_TIME: 21;
|
|
141
|
+
readonly TAB_NAVIGATION_PATH_PRUNED: 24;
|
|
142
|
+
readonly SET_TAB_GROUP: 25;
|
|
143
|
+
readonly SET_TAB_GROUP_METADATA2: 27;
|
|
144
|
+
readonly SET_TAB_DATA: 30;
|
|
145
|
+
readonly ADD_TAB_EXTRA_DATA: 33;
|
|
146
|
+
readonly ADD_WINDOW_EXTRA_DATA: 34;
|
|
147
|
+
};
|
|
148
|
+
type SessionCommand = {
|
|
149
|
+
id: 0;
|
|
150
|
+
windowId: SessionWindowId;
|
|
151
|
+
tabId: TabId;
|
|
152
|
+
} | {
|
|
153
|
+
id: 2;
|
|
154
|
+
tabId: TabId;
|
|
155
|
+
index: number;
|
|
156
|
+
} | {
|
|
157
|
+
id: 6;
|
|
158
|
+
tabId: TabId;
|
|
159
|
+
navigation: SerializedNavigationEntry;
|
|
160
|
+
} | {
|
|
161
|
+
id: 7;
|
|
162
|
+
tabId: TabId;
|
|
163
|
+
index: number;
|
|
164
|
+
} | {
|
|
165
|
+
id: 8;
|
|
166
|
+
windowId: SessionWindowId;
|
|
167
|
+
index: number;
|
|
168
|
+
} | {
|
|
169
|
+
id: 12;
|
|
170
|
+
tabId: TabId;
|
|
171
|
+
pinned: boolean;
|
|
172
|
+
} | {
|
|
173
|
+
id: 16;
|
|
174
|
+
tabId: TabId;
|
|
175
|
+
closeTime: number;
|
|
176
|
+
} | {
|
|
177
|
+
id: 17;
|
|
178
|
+
windowId: SessionWindowId;
|
|
179
|
+
closeTime: number;
|
|
180
|
+
} | {
|
|
181
|
+
id: 20;
|
|
182
|
+
windowId: SessionWindowId;
|
|
183
|
+
} | {
|
|
184
|
+
id: 21;
|
|
185
|
+
tabId: TabId;
|
|
186
|
+
lastActiveTime: number;
|
|
187
|
+
} | {
|
|
188
|
+
id: 24;
|
|
189
|
+
tabId: TabId;
|
|
190
|
+
index: number;
|
|
191
|
+
count: number;
|
|
192
|
+
} | {
|
|
193
|
+
id: 25;
|
|
194
|
+
tabId: TabId;
|
|
195
|
+
groupId: TabGroupId | null;
|
|
196
|
+
} | {
|
|
197
|
+
id: 27;
|
|
198
|
+
groupId: TabGroupId;
|
|
199
|
+
visualData: TabGroupVisualData;
|
|
200
|
+
} | {
|
|
201
|
+
id: 30;
|
|
202
|
+
tabId: TabId;
|
|
203
|
+
data: unknown;
|
|
204
|
+
} | {
|
|
205
|
+
id: 33;
|
|
206
|
+
tabId: TabId;
|
|
207
|
+
key: string;
|
|
208
|
+
value: string;
|
|
209
|
+
} | {
|
|
210
|
+
id: 34;
|
|
211
|
+
windowId: SessionWindowId;
|
|
212
|
+
key: string;
|
|
213
|
+
value: string;
|
|
214
|
+
};
|
|
215
|
+
declare function createSetTabWindowCommand(windowId: SessionWindowId, tabId: TabId): SessionCommand;
|
|
216
|
+
declare function createSetTabIndexInWindowCommand(tabId: TabId, index: number): SessionCommand;
|
|
217
|
+
declare function createUpdateTabNavigationCommand(tabId: TabId, navigation: SerializedNavigationEntry): SessionCommand;
|
|
218
|
+
declare function createSetSelectedNavigationIndexCommand(tabId: TabId, index: number): SessionCommand;
|
|
219
|
+
declare function createSetSelectedTabInWindowCommand(windowId: SessionWindowId, index: number): SessionCommand;
|
|
220
|
+
declare function createPinnedStateCommand(tabId: TabId, pinned: boolean): SessionCommand;
|
|
221
|
+
declare function createTabClosedCommand(tabId: TabId, closeTime?: number): SessionCommand;
|
|
222
|
+
declare function createWindowClosedCommand(windowId: SessionWindowId, closeTime?: number): SessionCommand;
|
|
223
|
+
declare function createSetActiveWindowCommand(windowId: SessionWindowId): SessionCommand;
|
|
224
|
+
declare function createLastActiveTimeCommand(tabId: TabId, lastActiveTime: number): SessionCommand;
|
|
225
|
+
declare function createTabNavigationPathPrunedCommand(tabId: TabId, index: number, count: number): SessionCommand;
|
|
226
|
+
declare function createTabGroupCommand(tabId: TabId, groupId: TabGroupId | null): SessionCommand;
|
|
227
|
+
declare function createTabGroupMetadataUpdateCommand(groupId: TabGroupId, visualData: TabGroupVisualData): SessionCommand;
|
|
228
|
+
declare function createSetTabDataCommand(tabId: TabId, data: unknown): SessionCommand;
|
|
229
|
+
declare function createAddTabExtraDataCommand(tabId: TabId, key: string, value: string): SessionCommand;
|
|
230
|
+
declare function createAddWindowExtraDataCommand(windowId: SessionWindowId, key: string, value: string): SessionCommand;
|
|
231
|
+
/**
|
|
232
|
+
* True for commands recording a close. Closing commands never trigger a
|
|
233
|
+
* rebuild — resetting right after a close could lose the state we want to
|
|
234
|
+
* restore. Mirrors IsClosingCommand (session_service_commands.cc:1374).
|
|
235
|
+
*/
|
|
236
|
+
declare function isClosingCommand(command: SessionCommand): boolean;
|
|
237
|
+
/**
|
|
238
|
+
* Returns the position of the first navigation whose index is >= `index`,
|
|
239
|
+
* or navigations.length. Navigations are sorted ascending by index.
|
|
240
|
+
* Mirrors FindClosestNavigationWithIndex (session_service_commands.cc:339).
|
|
241
|
+
*/
|
|
242
|
+
declare function findClosestNavigationWithIndex(navigations: readonly SerializedNavigationEntry[], index: number): number;
|
|
243
|
+
/**
|
|
244
|
+
* Removes `count` navigation entries starting at index value `index`,
|
|
245
|
+
* fixing up the selected index and renumbering survivors. Mirrors
|
|
246
|
+
* ProcessTabNavigationPathPrunedCommand (session_service_commands.cc:489).
|
|
247
|
+
*/
|
|
248
|
+
declare function processTabNavigationPathPruned(tab: Pick<SessionTab, 'navigations' | 'currentNavigationIndex'>, index: number, count: number): void;
|
|
249
|
+
/**
|
|
250
|
+
* Replays a command log into restorable windows. Port of
|
|
251
|
+
* RestoreSessionFromCommands (session_service_commands.cc:1398):
|
|
252
|
+
*
|
|
253
|
+
* 1. CreateTabsAndWindows (cc:521) — apply each command to lazily-created
|
|
254
|
+
* tab/window/group entries, stopping at the first malformed command.
|
|
255
|
+
* 2. AddTabsToWindows (cc:404) — attach tabs to their windows, dropping
|
|
256
|
+
* tabs that never got a window; remap each tab's selected-navigation
|
|
257
|
+
* *index value* to a position in its navigations array.
|
|
258
|
+
* 3. SortTabsBasedOnVisualOrderAndClear (cc:372) — order tabs by visual
|
|
259
|
+
* index and drop windows with no tabs.
|
|
260
|
+
* 4. UpdateSelectedTabIndex (cc:265) — remap each window's selected-tab
|
|
261
|
+
* *visual index* to a position in its tabs array.
|
|
262
|
+
*
|
|
263
|
+
* Deviation from Chrome: tabs without navigation entries are kept when they
|
|
264
|
+
* carry a data payload — this library's data-only persistence mode has no
|
|
265
|
+
* navigation list, but the tab is still fully restorable from `data`.
|
|
266
|
+
*/
|
|
267
|
+
declare function restoreSessionFromCommands(commands: readonly SessionCommand[]): SessionSnapshot;
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* Storage backend interface. Ported from
|
|
271
|
+
* chromium-reference/components/sessions/core/command_storage_backend.h.
|
|
272
|
+
*
|
|
273
|
+
* Chrome's backend owns timestamped SNSS files under Sessions/ and tracks
|
|
274
|
+
* which one is the "last session" (the previous run) versus the "current
|
|
275
|
+
* session" (this run). This port reduces that to two slots — `current` and
|
|
276
|
+
* `last` — over any storage primitive. Implementations may be synchronous
|
|
277
|
+
* (web storage) or asynchronous (IndexedDB, files); CommandStorageManager
|
|
278
|
+
* awaits either.
|
|
279
|
+
*/
|
|
280
|
+
|
|
281
|
+
/** Mirrors CommandStorageBackend::ReadCommandsResult (h:81). */
|
|
282
|
+
interface ReadCommandsResult {
|
|
283
|
+
commands: SessionCommand[];
|
|
284
|
+
/**
|
|
285
|
+
* True when the stored data was missing pieces, unparsable, or otherwise
|
|
286
|
+
* suspect. Whatever could be read is still in `commands`.
|
|
287
|
+
*/
|
|
288
|
+
errorReading: boolean;
|
|
289
|
+
}
|
|
290
|
+
interface CommandStorageBackend {
|
|
291
|
+
/**
|
|
292
|
+
* Identifies this storage area for cross-realm singleton coordination —
|
|
293
|
+
* the analog of Chrome naming its ProcessSingleton after the user data
|
|
294
|
+
* directory (process_singleton.h:45). Backends that can be reached from
|
|
295
|
+
* several realms at once (web storage) must provide it; backends that
|
|
296
|
+
* cannot (in-memory) leave it undefined and the service acts as sole
|
|
297
|
+
* owner.
|
|
298
|
+
*/
|
|
299
|
+
readonly profileLockName?: string;
|
|
300
|
+
/**
|
|
301
|
+
* Persists commands to the current session. With `truncate` the current
|
|
302
|
+
* session is replaced wholesale (the pending commands are a complete
|
|
303
|
+
* snapshot); otherwise they are appended. Mirrors
|
|
304
|
+
* CommandStorageBackend::AppendCommands (h:120).
|
|
305
|
+
*/
|
|
306
|
+
appendCommands(commands: readonly SessionCommand[], truncate: boolean): void | Promise<void>;
|
|
307
|
+
/** Reads the previous session's log. Mirrors GetLastSessionCommands. */
|
|
308
|
+
readLastSessionCommands(): ReadCommandsResult | Promise<ReadCommandsResult>;
|
|
309
|
+
/**
|
|
310
|
+
* Promotes the current session to "last" and starts an empty current
|
|
311
|
+
* session. When no current session exists (the previous run died before
|
|
312
|
+
* its first save), the existing last session is left untouched so it can
|
|
313
|
+
* still be restored. Mirrors MoveCurrentSessionToLastSession (h:131).
|
|
314
|
+
*/
|
|
315
|
+
moveCurrentSessionToLastSession(): void | Promise<void>;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export { processTabNavigationPathPruned as A, restoreSessionFromCommands as B, type CommandStorageBackend as C, DEFAULT_WINDOW_ID as D, type ReadCommandsResult as R, type SessionCommand as S, type SessionTab as a, type SessionWindow as b, type SessionWindowId as c, type SessionSnapshot as d, type SerializedNavigationEntry as e, SessionCommandId as f, type SessionTabGroup as g, createAddTabExtraDataCommand as h, createAddWindowExtraDataCommand as i, createLastActiveTimeCommand as j, createPinnedStateCommand as k, createSetActiveWindowCommand as l, createSetSelectedNavigationIndexCommand as m, createSetSelectedTabInWindowCommand as n, createSetTabDataCommand as o, createSetTabIndexInWindowCommand as p, createSetTabWindowCommand as q, createTabClosedCommand as r, createTabGroupCommand as s, createTabGroupMetadataUpdateCommand as t, createTabNavigationPathPrunedCommand as u, createUpdateTabNavigationCommand as v, createWindowClosedCommand as w, currentNavigationEntry as x, findClosestNavigationWithIndex as y, isClosingCommand as z };
|