
























@@ -13,6 +13,15 @@ type TrackedSessionBrowserTab = {
1313lastUsedAt: number;
1414};
151516+type SessionBrowserTabIdentityParams = {
17+sessionKey?: string;
18+targetId?: string;
19+baseUrl?: string;
20+profile?: string;
21+};
22+23+type TrackedSessionBrowserTabIdentity = Omit<TrackedSessionBrowserTab, "trackedAt" | "lastUsedAt">;
24+1625const trackedTabsBySession = new Map<string, Map<string, TrackedSessionBrowserTab>>();
17261827function normalizeSessionKey(raw: string): string {
@@ -39,12 +48,9 @@ function toTrackedTabId(params: { targetId: string; baseUrl?: string; profile?:
3948return `${params.targetId}\u0000${params.baseUrl ?? ""}\u0000${params.profile ?? ""}`;
4049}
415042-function resolveTrackedTabIdentity(params: {
43-sessionKey?: string;
44-targetId?: string;
45-baseUrl?: string;
46-profile?: string;
47-}): Omit<TrackedSessionBrowserTab, "trackedAt" | "lastUsedAt"> | undefined {
51+function resolveTrackedTabIdentity(
52+params: SessionBrowserTabIdentityParams,
53+): TrackedSessionBrowserTabIdentity | undefined {
4854const sessionKeyRaw = params.sessionKey?.trim();
4955const targetIdRaw = params.targetId?.trim();
5056if (!sessionKeyRaw || !targetIdRaw) {
@@ -58,6 +64,23 @@ function resolveTrackedTabIdentity(params: {
5864};
5965}
606667+function trackedTabsForIdentity(
68+identity: TrackedSessionBrowserTabIdentity,
69+): Map<string, TrackedSessionBrowserTab> | undefined {
70+return trackedTabsBySession.get(identity.sessionKey);
71+}
72+73+function deleteTrackedTab(identity: TrackedSessionBrowserTabIdentity): void {
74+const trackedForSession = trackedTabsForIdentity(identity);
75+if (!trackedForSession) {
76+return;
77+}
78+trackedForSession.delete(toTrackedTabId(identity));
79+if (trackedForSession.size === 0) {
80+trackedTabsBySession.delete(identity.sessionKey);
81+}
82+}
83+6184function isIgnorableCloseError(err: unknown): boolean {
6285const message = normalizeLowercaseStringOrEmpty(String(err));
6386return (
@@ -68,12 +91,7 @@ function isIgnorableCloseError(err: unknown): boolean {
6891);
6992}
709371-export function trackSessionBrowserTab(params: {
72-sessionKey?: string;
73-targetId?: string;
74-baseUrl?: string;
75-profile?: string;
76-}): void {
94+export function trackSessionBrowserTab(params: SessionBrowserTabIdentityParams): void {
7795const identity = resolveTrackedTabIdentity(params);
7896if (!identity) {
7997return;
@@ -97,18 +115,14 @@ export function trackSessionBrowserTab(params: {
97115});
98116}
99117100-export function touchSessionBrowserTab(params: {
101-sessionKey?: string;
102-targetId?: string;
103-baseUrl?: string;
104-profile?: string;
105-now?: number;
106-}): void {
118+export function touchSessionBrowserTab(
119+params: SessionBrowserTabIdentityParams & { now?: number },
120+): void {
107121const identity = resolveTrackedTabIdentity(params);
108122if (!identity) {
109123return;
110124}
111-const trackedForSession = trackedTabsBySession.get(identity.sessionKey);
125+const trackedForSession = trackedTabsForIdentity(identity);
112126if (!trackedForSession) {
113127return;
114128}
@@ -123,25 +137,12 @@ export function touchSessionBrowserTab(params: {
123137});
124138}
125139126-export function untrackSessionBrowserTab(params: {
127-sessionKey?: string;
128-targetId?: string;
129-baseUrl?: string;
130-profile?: string;
131-}): void {
140+export function untrackSessionBrowserTab(params: SessionBrowserTabIdentityParams): void {
132141const identity = resolveTrackedTabIdentity(params);
133142if (!identity) {
134143return;
135144}
136-const trackedForSession = trackedTabsBySession.get(identity.sessionKey);
137-if (!trackedForSession) {
138-return;
139-}
140-const trackedId = toTrackedTabId(identity);
141-trackedForSession.delete(trackedId);
142-if (trackedForSession.size === 0) {
143-trackedTabsBySession.delete(identity.sessionKey);
144-}
145+deleteTrackedTab(identity);
145146}
146147147148function takeTrackedTabsForSessionKeys(
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。