@flrande/bak-extension 0.3.4 → 0.3.5
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/dist/.bak-e2e-build-stamp +1 -1
- package/dist/background.global.js +37 -7
- package/package.json +2 -2
- package/src/background.ts +47 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
2026-03-
|
|
1
|
+
2026-03-09T10:54:43.175Z
|
|
@@ -980,6 +980,32 @@
|
|
|
980
980
|
}
|
|
981
981
|
throw new Error(`tab url timeout: ${tabId} -> ${expectedUrl}`);
|
|
982
982
|
}
|
|
983
|
+
async function finalizeOpenedWorkspaceTab(opened, expectedUrl) {
|
|
984
|
+
if (expectedUrl && expectedUrl !== "about:blank") {
|
|
985
|
+
await waitForTabUrl(opened.tab.id, expectedUrl).catch(() => void 0);
|
|
986
|
+
}
|
|
987
|
+
let refreshedTab = opened.tab;
|
|
988
|
+
try {
|
|
989
|
+
const rawTab = await chrome.tabs.get(opened.tab.id);
|
|
990
|
+
const pendingUrl = "pendingUrl" in rawTab && typeof rawTab.pendingUrl === "string" ? rawTab.pendingUrl : "";
|
|
991
|
+
const currentUrl = rawTab.url ?? "";
|
|
992
|
+
const effectiveUrl = currentUrl && currentUrl !== "about:blank" ? currentUrl : pendingUrl && pendingUrl !== "about:blank" ? pendingUrl : currentUrl || pendingUrl || opened.tab.url;
|
|
993
|
+
refreshedTab = {
|
|
994
|
+
...toTabInfo(rawTab),
|
|
995
|
+
url: effectiveUrl
|
|
996
|
+
};
|
|
997
|
+
} catch {
|
|
998
|
+
refreshedTab = await workspaceBrowser.getTab(opened.tab.id) ?? opened.tab;
|
|
999
|
+
}
|
|
1000
|
+
const refreshedWorkspace = await workspaceManager.getWorkspaceInfo(opened.workspace.id) ?? {
|
|
1001
|
+
...opened.workspace,
|
|
1002
|
+
tabs: opened.workspace.tabs.map((tab) => tab.id === refreshedTab.id ? refreshedTab : tab)
|
|
1003
|
+
};
|
|
1004
|
+
return {
|
|
1005
|
+
workspace: refreshedWorkspace,
|
|
1006
|
+
tab: refreshedTab
|
|
1007
|
+
};
|
|
1008
|
+
}
|
|
983
1009
|
async function withTab(target = {}, options = {}) {
|
|
984
1010
|
const requireSupportedAutomationUrl = options.requireSupportedAutomationUrl !== false;
|
|
985
1011
|
const validate = (tab2) => {
|
|
@@ -1179,19 +1205,21 @@
|
|
|
1179
1205
|
}
|
|
1180
1206
|
case "tabs.new": {
|
|
1181
1207
|
if (typeof params.workspaceId === "string" || params.windowId === void 0) {
|
|
1208
|
+
const expectedUrl = params.url ?? "about:blank";
|
|
1182
1209
|
const opened = await preserveHumanFocus(true, async () => {
|
|
1183
1210
|
return await workspaceManager.openTab({
|
|
1184
1211
|
workspaceId: typeof params.workspaceId === "string" ? params.workspaceId : DEFAULT_WORKSPACE_ID,
|
|
1185
|
-
url:
|
|
1212
|
+
url: expectedUrl,
|
|
1186
1213
|
active: params.active === true,
|
|
1187
1214
|
focus: false
|
|
1188
1215
|
});
|
|
1189
1216
|
});
|
|
1217
|
+
const stabilized = await finalizeOpenedWorkspaceTab(opened, expectedUrl);
|
|
1190
1218
|
return {
|
|
1191
|
-
tabId:
|
|
1192
|
-
windowId:
|
|
1193
|
-
groupId:
|
|
1194
|
-
workspaceId:
|
|
1219
|
+
tabId: stabilized.tab.id,
|
|
1220
|
+
windowId: stabilized.tab.windowId,
|
|
1221
|
+
groupId: stabilized.workspace.groupId,
|
|
1222
|
+
workspaceId: stabilized.workspace.id
|
|
1195
1223
|
};
|
|
1196
1224
|
}
|
|
1197
1225
|
const tab = await chrome.tabs.create({
|
|
@@ -1232,14 +1260,16 @@
|
|
|
1232
1260
|
};
|
|
1233
1261
|
}
|
|
1234
1262
|
case "workspace.openTab": {
|
|
1235
|
-
|
|
1263
|
+
const expectedUrl = typeof params.url === "string" ? params.url : void 0;
|
|
1264
|
+
const opened = await preserveHumanFocus(params.focus !== true, async () => {
|
|
1236
1265
|
return await workspaceManager.openTab({
|
|
1237
1266
|
workspaceId: typeof params.workspaceId === "string" ? params.workspaceId : void 0,
|
|
1238
|
-
url:
|
|
1267
|
+
url: expectedUrl,
|
|
1239
1268
|
active: params.active === true,
|
|
1240
1269
|
focus: params.focus === true
|
|
1241
1270
|
});
|
|
1242
1271
|
});
|
|
1272
|
+
return await finalizeOpenedWorkspaceTab(opened, expectedUrl);
|
|
1243
1273
|
}
|
|
1244
1274
|
case "workspace.listTabs": {
|
|
1245
1275
|
return await workspaceManager.listTabs(typeof params.workspaceId === "string" ? params.workspaceId : void 0);
|
package/package.json
CHANGED
package/src/background.ts
CHANGED
|
@@ -390,6 +390,42 @@ async function waitForTabUrl(tabId: number, expectedUrl: string, timeoutMs = 10_
|
|
|
390
390
|
throw new Error(`tab url timeout: ${tabId} -> ${expectedUrl}`);
|
|
391
391
|
}
|
|
392
392
|
|
|
393
|
+
async function finalizeOpenedWorkspaceTab(
|
|
394
|
+
opened: Awaited<ReturnType<WorkspaceManager['openTab']>>,
|
|
395
|
+
expectedUrl?: string
|
|
396
|
+
): Promise<Awaited<ReturnType<WorkspaceManager['openTab']>>> {
|
|
397
|
+
if (expectedUrl && expectedUrl !== 'about:blank') {
|
|
398
|
+
await waitForTabUrl(opened.tab.id, expectedUrl).catch(() => undefined);
|
|
399
|
+
}
|
|
400
|
+
let refreshedTab = opened.tab;
|
|
401
|
+
try {
|
|
402
|
+
const rawTab = await chrome.tabs.get(opened.tab.id);
|
|
403
|
+
const pendingUrl = 'pendingUrl' in rawTab && typeof rawTab.pendingUrl === 'string' ? rawTab.pendingUrl : '';
|
|
404
|
+
const currentUrl = rawTab.url ?? '';
|
|
405
|
+
const effectiveUrl =
|
|
406
|
+
currentUrl && currentUrl !== 'about:blank'
|
|
407
|
+
? currentUrl
|
|
408
|
+
: pendingUrl && pendingUrl !== 'about:blank'
|
|
409
|
+
? pendingUrl
|
|
410
|
+
: currentUrl || pendingUrl || opened.tab.url;
|
|
411
|
+
refreshedTab = {
|
|
412
|
+
...toTabInfo(rawTab),
|
|
413
|
+
url: effectiveUrl
|
|
414
|
+
};
|
|
415
|
+
} catch {
|
|
416
|
+
refreshedTab = (await workspaceBrowser.getTab(opened.tab.id)) ?? opened.tab;
|
|
417
|
+
}
|
|
418
|
+
const refreshedWorkspace = (await workspaceManager.getWorkspaceInfo(opened.workspace.id)) ?? {
|
|
419
|
+
...opened.workspace,
|
|
420
|
+
tabs: opened.workspace.tabs.map((tab) => (tab.id === refreshedTab.id ? refreshedTab : tab))
|
|
421
|
+
};
|
|
422
|
+
|
|
423
|
+
return {
|
|
424
|
+
workspace: refreshedWorkspace,
|
|
425
|
+
tab: refreshedTab
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
393
429
|
interface WithTabOptions {
|
|
394
430
|
requireSupportedAutomationUrl?: boolean;
|
|
395
431
|
}
|
|
@@ -634,19 +670,21 @@ async function handleRequest(request: CliRequest): Promise<unknown> {
|
|
|
634
670
|
}
|
|
635
671
|
case 'tabs.new': {
|
|
636
672
|
if (typeof params.workspaceId === 'string' || params.windowId === undefined) {
|
|
673
|
+
const expectedUrl = (params.url as string | undefined) ?? 'about:blank';
|
|
637
674
|
const opened = await preserveHumanFocus(true, async () => {
|
|
638
675
|
return await workspaceManager.openTab({
|
|
639
676
|
workspaceId: typeof params.workspaceId === 'string' ? params.workspaceId : DEFAULT_WORKSPACE_ID,
|
|
640
|
-
url:
|
|
677
|
+
url: expectedUrl,
|
|
641
678
|
active: params.active === true,
|
|
642
679
|
focus: false
|
|
643
680
|
});
|
|
644
681
|
});
|
|
682
|
+
const stabilized = await finalizeOpenedWorkspaceTab(opened, expectedUrl);
|
|
645
683
|
return {
|
|
646
|
-
tabId:
|
|
647
|
-
windowId:
|
|
648
|
-
groupId:
|
|
649
|
-
workspaceId:
|
|
684
|
+
tabId: stabilized.tab.id,
|
|
685
|
+
windowId: stabilized.tab.windowId,
|
|
686
|
+
groupId: stabilized.workspace.groupId,
|
|
687
|
+
workspaceId: stabilized.workspace.id
|
|
650
688
|
};
|
|
651
689
|
}
|
|
652
690
|
const tab = await chrome.tabs.create({
|
|
@@ -687,14 +725,16 @@ async function handleRequest(request: CliRequest): Promise<unknown> {
|
|
|
687
725
|
};
|
|
688
726
|
}
|
|
689
727
|
case 'workspace.openTab': {
|
|
690
|
-
|
|
728
|
+
const expectedUrl = typeof params.url === 'string' ? params.url : undefined;
|
|
729
|
+
const opened = await preserveHumanFocus(params.focus !== true, async () => {
|
|
691
730
|
return await workspaceManager.openTab({
|
|
692
731
|
workspaceId: typeof params.workspaceId === 'string' ? params.workspaceId : undefined,
|
|
693
|
-
url:
|
|
732
|
+
url: expectedUrl,
|
|
694
733
|
active: params.active === true,
|
|
695
734
|
focus: params.focus === true
|
|
696
735
|
});
|
|
697
736
|
});
|
|
737
|
+
return await finalizeOpenedWorkspaceTab(opened, expectedUrl);
|
|
698
738
|
}
|
|
699
739
|
case 'workspace.listTabs': {
|
|
700
740
|
return await workspaceManager.listTabs(typeof params.workspaceId === 'string' ? params.workspaceId : undefined);
|