@jackwener/opencli 1.2.2 → 1.2.4
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.
|
@@ -228,7 +228,7 @@ async function getAutomationWindow(workspace) {
|
|
|
228
228
|
}
|
|
229
229
|
}
|
|
230
230
|
const win = await chrome.windows.create({
|
|
231
|
-
url: "
|
|
231
|
+
url: "data:text/html,<html></html>",
|
|
232
232
|
focused: false,
|
|
233
233
|
width: 1280,
|
|
234
234
|
height: 900,
|
|
@@ -309,6 +309,7 @@ async function resolveTabId(tabId, workspace) {
|
|
|
309
309
|
if (tabId !== void 0) {
|
|
310
310
|
try {
|
|
311
311
|
const tab = await chrome.tabs.get(tabId);
|
|
312
|
+
console.log(`[opencli] resolveTabId: explicit tabId=${tabId}, url=${tab.url}`);
|
|
312
313
|
if (isDebuggableUrl(tab.url)) return tabId;
|
|
313
314
|
console.warn(`[opencli] Tab ${tabId} URL is not debuggable (${tab.url}), re-resolving`);
|
|
314
315
|
} catch {
|
|
@@ -318,14 +319,28 @@ async function resolveTabId(tabId, workspace) {
|
|
|
318
319
|
const windowId = await getAutomationWindow(workspace);
|
|
319
320
|
const tabs = await chrome.tabs.query({ windowId });
|
|
320
321
|
const debuggableTab = tabs.find((t) => t.id && isDebuggableUrl(t.url));
|
|
321
|
-
if (debuggableTab?.id)
|
|
322
|
+
if (debuggableTab?.id) {
|
|
323
|
+
console.log(`[opencli] resolveTabId: found debuggable tab ${debuggableTab.id} (${debuggableTab.url})`);
|
|
324
|
+
return debuggableTab.id;
|
|
325
|
+
}
|
|
326
|
+
console.warn(`[opencli] resolveTabId: no debuggable tabs found, tabs: ${tabs.map((t) => `${t.id}=${t.url}`).join(", ")}`);
|
|
322
327
|
const reuseTab = tabs.find((t) => t.id);
|
|
323
328
|
if (reuseTab?.id) {
|
|
324
|
-
await chrome.tabs.update(reuseTab.id, { url: "
|
|
325
|
-
await new Promise((resolve) => setTimeout(resolve,
|
|
326
|
-
|
|
329
|
+
await chrome.tabs.update(reuseTab.id, { url: "data:text/html,<html></html>" });
|
|
330
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
331
|
+
try {
|
|
332
|
+
const updated = await chrome.tabs.get(reuseTab.id);
|
|
333
|
+
if (isDebuggableUrl(updated.url)) return reuseTab.id;
|
|
334
|
+
console.warn(`[opencli] about:blank was intercepted (${updated.url}), trying data: URI`);
|
|
335
|
+
await chrome.tabs.update(reuseTab.id, { url: "data:text/html,<html></html>" });
|
|
336
|
+
await new Promise((resolve) => setTimeout(resolve, 300));
|
|
337
|
+
const updated2 = await chrome.tabs.get(reuseTab.id);
|
|
338
|
+
if (isDebuggableUrl(updated2.url)) return reuseTab.id;
|
|
339
|
+
console.warn(`[opencli] data: URI also intercepted, creating fresh tab`);
|
|
340
|
+
} catch {
|
|
341
|
+
}
|
|
327
342
|
}
|
|
328
|
-
const newTab = await chrome.tabs.create({ windowId, url: "
|
|
343
|
+
const newTab = await chrome.tabs.create({ windowId, url: "data:text/html,<html></html>", active: true });
|
|
329
344
|
if (!newTab.id) throw new Error("Failed to create tab in automation window");
|
|
330
345
|
return newTab.id;
|
|
331
346
|
}
|
|
@@ -413,7 +428,7 @@ async function handleTabs(cmd, workspace) {
|
|
|
413
428
|
}
|
|
414
429
|
case "new": {
|
|
415
430
|
const windowId = await getAutomationWindow(workspace);
|
|
416
|
-
const tab = await chrome.tabs.create({ windowId, url: cmd.url ?? "
|
|
431
|
+
const tab = await chrome.tabs.create({ windowId, url: cmd.url ?? "data:text/html,<html></html>", active: true });
|
|
417
432
|
return { id: cmd.id, ok: true, data: { tabId: tab.id, url: tab.url } };
|
|
418
433
|
}
|
|
419
434
|
case "close": {
|
package/extension/manifest.json
CHANGED
package/extension/package.json
CHANGED
|
@@ -135,9 +135,10 @@ async function getAutomationWindow(workspace: string): Promise<number> {
|
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
|
|
138
|
-
// Create a new window with
|
|
138
|
+
// Create a new window with a data: URI that New Tab Override extensions cannot intercept.
|
|
139
|
+
// Using about:blank would be hijacked by extensions like "New Tab Override".
|
|
139
140
|
const win = await chrome.windows.create({
|
|
140
|
-
url: '
|
|
141
|
+
url: 'data:text/html,<html></html>',
|
|
141
142
|
focused: false,
|
|
142
143
|
width: 1280,
|
|
143
144
|
height: 900,
|
|
@@ -244,6 +245,7 @@ async function resolveTabId(tabId: number | undefined, workspace: string): Promi
|
|
|
244
245
|
if (tabId !== undefined) {
|
|
245
246
|
try {
|
|
246
247
|
const tab = await chrome.tabs.get(tabId);
|
|
248
|
+
console.log(`[opencli] resolveTabId: explicit tabId=${tabId}, url=${tab.url}`);
|
|
247
249
|
if (isDebuggableUrl(tab.url)) return tabId;
|
|
248
250
|
// Tab exists but URL is not debuggable — fall through to auto-resolve
|
|
249
251
|
console.warn(`[opencli] Tab ${tabId} URL is not debuggable (${tab.url}), re-resolving`);
|
|
@@ -259,7 +261,11 @@ async function resolveTabId(tabId: number | undefined, workspace: string): Promi
|
|
|
259
261
|
// Prefer an existing debuggable tab (about:blank, http://, https://, etc.)
|
|
260
262
|
const tabs = await chrome.tabs.query({ windowId });
|
|
261
263
|
const debuggableTab = tabs.find(t => t.id && isDebuggableUrl(t.url));
|
|
262
|
-
if (debuggableTab?.id)
|
|
264
|
+
if (debuggableTab?.id) {
|
|
265
|
+
console.log(`[opencli] resolveTabId: found debuggable tab ${debuggableTab.id} (${debuggableTab.url})`);
|
|
266
|
+
return debuggableTab.id;
|
|
267
|
+
}
|
|
268
|
+
console.warn(`[opencli] resolveTabId: no debuggable tabs found, tabs: ${tabs.map(t => `${t.id}=${t.url}`).join(', ')}`);
|
|
263
269
|
|
|
264
270
|
// No debuggable tab found — this typically happens when a "New Tab Override"
|
|
265
271
|
// extension replaces about:blank with a chrome-extension:// page.
|
|
@@ -267,14 +273,28 @@ async function resolveTabId(tabId: number | undefined, workspace: string): Promi
|
|
|
267
273
|
// accumulating orphan tabs if chrome.tabs.create is also intercepted).
|
|
268
274
|
const reuseTab = tabs.find(t => t.id);
|
|
269
275
|
if (reuseTab?.id) {
|
|
270
|
-
await chrome.tabs.update(reuseTab.id, { url: '
|
|
271
|
-
// Wait
|
|
272
|
-
await new Promise(resolve => setTimeout(resolve,
|
|
273
|
-
|
|
276
|
+
await chrome.tabs.update(reuseTab.id, { url: 'data:text/html,<html></html>' });
|
|
277
|
+
// Wait for the navigation to take effect
|
|
278
|
+
await new Promise(resolve => setTimeout(resolve, 300));
|
|
279
|
+
// Verify the URL is actually debuggable (New Tab Override may have intercepted)
|
|
280
|
+
try {
|
|
281
|
+
const updated = await chrome.tabs.get(reuseTab.id);
|
|
282
|
+
if (isDebuggableUrl(updated.url)) return reuseTab.id;
|
|
283
|
+
// New Tab Override intercepted about:blank — try data: URI instead
|
|
284
|
+
console.warn(`[opencli] about:blank was intercepted (${updated.url}), trying data: URI`);
|
|
285
|
+
await chrome.tabs.update(reuseTab.id, { url: 'data:text/html,<html></html>' });
|
|
286
|
+
await new Promise(resolve => setTimeout(resolve, 300));
|
|
287
|
+
const updated2 = await chrome.tabs.get(reuseTab.id);
|
|
288
|
+
if (isDebuggableUrl(updated2.url)) return reuseTab.id;
|
|
289
|
+
// data: URI also intercepted — create a brand new tab
|
|
290
|
+
console.warn(`[opencli] data: URI also intercepted, creating fresh tab`);
|
|
291
|
+
} catch {
|
|
292
|
+
// Tab was closed during navigation
|
|
293
|
+
}
|
|
274
294
|
}
|
|
275
295
|
|
|
276
|
-
// Window has no tabs
|
|
277
|
-
const newTab = await chrome.tabs.create({ windowId, url: '
|
|
296
|
+
// Window has no debuggable tabs — create one
|
|
297
|
+
const newTab = await chrome.tabs.create({ windowId, url: 'data:text/html,<html></html>', active: true });
|
|
278
298
|
if (!newTab.id) throw new Error('Failed to create tab in automation window');
|
|
279
299
|
return newTab.id;
|
|
280
300
|
}
|
|
@@ -383,7 +403,7 @@ async function handleTabs(cmd: Command, workspace: string): Promise<Result> {
|
|
|
383
403
|
}
|
|
384
404
|
case 'new': {
|
|
385
405
|
const windowId = await getAutomationWindow(workspace);
|
|
386
|
-
const tab = await chrome.tabs.create({ windowId, url: cmd.url ?? '
|
|
406
|
+
const tab = await chrome.tabs.create({ windowId, url: cmd.url ?? 'data:text/html,<html></html>', active: true });
|
|
387
407
|
return { id: cmd.id, ok: true, data: { tabId: tab.id, url: tab.url } };
|
|
388
408
|
}
|
|
389
409
|
case 'close': {
|