Skip to content

Commit 0f9f6d0

Browse files
authored
Merge pull request #107 from esokullu/codex/use-pending-active-cloud-tab
Reuse pending startup tab for cloud runs
2 parents 8b60873 + 89b0d3f commit 0f9f6d0

2 files changed

Lines changed: 10 additions & 3 deletions

File tree

src/chrome/src/cloud-runs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ function cloudSnapshot(run, { includeUpdates = true } = {}) {
5252
function isUsableCloudTab(tab) {
5353
if (tab?.id == null) return false;
5454
try {
55-
const url = new URL(tab.url || '');
55+
// Chrome can leave an unpacked-extension startup tab's `url` empty while
56+
// exposing the loaded page through `pendingUrl`, even with status=complete.
57+
const url = new URL(tab.url || tab.pendingUrl || '');
5658
return ['http:', 'https:', 'file:'].includes(url.protocol) || url.href === 'about:blank';
5759
} catch {
5860
return false;

test/run.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4108,7 +4108,8 @@ test('done_json validates Chrome and Firefox cloud results with one repair attem
41084108

41094109
test('cloud run controller uses the visible tab and persists terminal status', async () => {
41104110
const session = {};
4111-
const tab = { id: 17, url: 'https://webbrain.one/', active: true, windowId: 3 };
4111+
const tab = { id: 17, url: '', pendingUrl: 'https://webbrain.one/', active: true, windowId: 3 };
4112+
let createdTabs = 0;
41124113
let finishRun;
41134114
let processArgs = null;
41144115
const agent = {
@@ -4124,7 +4125,10 @@ test('cloud run controller uses the visible tab and persists terminal status', a
41244125
query: async query => query.active ? [tab] : [tab],
41254126
get: async () => tab,
41264127
update: async () => tab,
4127-
create: async () => ({ id: 18, url: 'about:blank', active: true }),
4128+
create: async () => {
4129+
createdTabs += 1;
4130+
return { id: 18, url: 'about:blank', active: true };
4131+
},
41284132
},
41294133
windows: { update: async () => ({}) },
41304134
storage: {
@@ -4146,6 +4150,7 @@ test('cloud run controller uses the visible tab and persists terminal status', a
41464150
const started = await controller.startRun({ task: 'Open Google' });
41474151
assert.equal(started.status, 'running');
41484152
assert.equal(started.tabId, 17);
4153+
assert.equal(createdTabs, 0, 'a loaded pendingUrl tab should be reused instead of opening about:blank');
41494154
assert.equal(processArgs[3], 'act');
41504155
assert.deepEqual(processArgs[4], []);
41514156
assert.equal(processArgs[5].cloudRun, true);

0 commit comments

Comments
 (0)