@xbrowser/cli 1.18.1 → 1.18.2

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.
@@ -20,7 +20,7 @@ import {
20
20
  saveSessionDiskMeta,
21
21
  setActivePage,
22
22
  touchSession
23
- } from "./chunk-MMZCBUD3.js";
23
+ } from "./chunk-NA7IP6PO.js";
24
24
  import "./chunk-DVKIL7H6.js";
25
25
  import "./chunk-3FWLW7FS.js";
26
26
  import "./chunk-3KZ34AUC.js";
@@ -20,7 +20,7 @@ import {
20
20
  saveSessionDiskMeta,
21
21
  setActivePage,
22
22
  touchSession
23
- } from "./chunk-OU335JBI.js";
23
+ } from "./chunk-7SDM4EA4.js";
24
24
  import "./chunk-3KZ34AUC.js";
25
25
  import "./chunk-GDKLH7ZY.js";
26
26
  import "./chunk-KFQGP6VL.js";
@@ -20,7 +20,7 @@ import {
20
20
  saveSessionDiskMeta,
21
21
  setActivePage,
22
22
  touchSession
23
- } from "./chunk-EI2XZIDF.js";
23
+ } from "./chunk-MTNVT2T7.js";
24
24
  import "./chunk-LL37GYPP.js";
25
25
  import "./chunk-3KZ34AUC.js";
26
26
  import "./chunk-GDKLH7ZY.js";
@@ -5912,11 +5912,37 @@ async function createSession(name, url, options) {
5912
5912
  }
5913
5913
  context = contexts[0] || await b.newContext();
5914
5914
  let targetPage = null;
5915
- if (targetHostname) {
5915
+ const ownedUrls = /* @__PURE__ */ new Set();
5916
+ for (const ssn of sessions.list()) {
5917
+ try {
5918
+ const u = ssn.page?.url();
5919
+ if (u && u !== "about:blank") ownedUrls.add(u);
5920
+ } catch {
5921
+ }
5922
+ }
5923
+ if (url) {
5924
+ for (const ctx of contexts) {
5925
+ for (const p of ctx.pages()) {
5926
+ try {
5927
+ const pUrl = await resolvePageUrl(p);
5928
+ if (ownedUrls.has(pUrl)) continue;
5929
+ if (pUrl === url) {
5930
+ targetPage = p;
5931
+ break;
5932
+ }
5933
+ } catch {
5934
+ }
5935
+ }
5936
+ if (targetPage) break;
5937
+ }
5938
+ }
5939
+ if (!targetPage && targetHostname) {
5916
5940
  for (const ctx of contexts) {
5917
5941
  const pages = ctx.pages();
5918
5942
  for (const p of pages) {
5919
- const pUrl = await resolvePageUrl(p);
5943
+ const pUrl0 = await resolvePageUrl(p);
5944
+ if (ownedUrls.has(pUrl0)) continue;
5945
+ const pUrl = pUrl0;
5920
5946
  if (isRealPageUrl(pUrl) && pUrl.includes(targetHostname)) {
5921
5947
  targetPage = p;
5922
5948
  break;
@@ -5929,7 +5955,9 @@ async function createSession(name, url, options) {
5929
5955
  for (const ctx of contexts) {
5930
5956
  const pages = ctx.pages();
5931
5957
  for (const p of pages) {
5932
- const pUrl = await resolvePageUrl(p);
5958
+ const pUrl0 = await resolvePageUrl(p);
5959
+ if (ownedUrls.has(pUrl0)) continue;
5960
+ const pUrl = pUrl0;
5933
5961
  if (isRealPageUrl(pUrl)) {
5934
5962
  targetPage = p;
5935
5963
  break;
@@ -5940,13 +5968,36 @@ async function createSession(name, url, options) {
5940
5968
  }
5941
5969
  if (!targetPage && options?.cdpEndpoint) {
5942
5970
  const targets = await getCDPTargets2(options.cdpEndpoint);
5971
+ const ownedUrlsT = /* @__PURE__ */ new Set();
5972
+ for (const ssn of sessions.list()) {
5973
+ try {
5974
+ const u = ssn.page?.url();
5975
+ if (u && u !== "about:blank") ownedUrlsT.add(u);
5976
+ } catch {
5977
+ }
5978
+ }
5943
5979
  const matchTarget = targets.find(
5944
- (t) => t.url && t.url !== "about:blank" && !t.url.startsWith("chrome://") && !t.url.startsWith("chrome-untrusted://") && !t.url.startsWith("chrome-error://") && (url ? t.url.includes(new URL(url).hostname) : true)
5980
+ (t) => t.url && t.url !== "about:blank" && !t.url.startsWith("chrome://") && !t.url.startsWith("chrome-untrusted://") && !t.url.startsWith("chrome-error://") && !ownedUrlsT.has(t.url) && (url ? t.url === url || t.url.includes(new URL(url).hostname) : true)
5945
5981
  );
5946
5982
  if (matchTarget && matchTarget.url) {
5983
+ const ownedUrls2 = /* @__PURE__ */ new Set();
5984
+ for (const ssn of sessions.list()) {
5985
+ try {
5986
+ const u = ssn.page?.url();
5987
+ if (u && u !== "about:blank") ownedUrls2.add(u);
5988
+ } catch {
5989
+ }
5990
+ }
5991
+ const isOwned = (p) => {
5992
+ try {
5993
+ return ownedUrls2.has(p.url());
5994
+ } catch {
5995
+ return false;
5996
+ }
5997
+ };
5947
5998
  const existing2 = context.pages().find((p) => {
5948
5999
  try {
5949
- return p.url() === matchTarget.url;
6000
+ return p.url() === matchTarget.url && !isOwned(p);
5950
6001
  } catch {
5951
6002
  return false;
5952
6003
  }
@@ -5964,7 +6015,10 @@ async function createSession(name, url, options) {
5964
6015
  const pages = context.pages();
5965
6016
  if (pages.length > 1) {
5966
6017
  try {
6018
+ const owned = /* @__PURE__ */ new Set();
6019
+ for (const ssn of sessions.list()) owned.add(ssn.page);
5967
6020
  for (const p of pages) {
6021
+ if (owned.has(p)) continue;
5968
6022
  const vis = await p.evaluate("document.visibilityState").catch(() => "hidden");
5969
6023
  if (vis === "visible") {
5970
6024
  targetPage = p;
@@ -607,11 +607,37 @@ async function createSession(name, url, options) {
607
607
  }
608
608
  context = contexts[0] || await b.newContext();
609
609
  let targetPage = null;
610
- if (targetHostname) {
610
+ const ownedUrls = /* @__PURE__ */ new Set();
611
+ for (const ssn of sessions.list()) {
612
+ try {
613
+ const u = ssn.page?.url();
614
+ if (u && u !== "about:blank") ownedUrls.add(u);
615
+ } catch {
616
+ }
617
+ }
618
+ if (url) {
619
+ for (const ctx of contexts) {
620
+ for (const p of ctx.pages()) {
621
+ try {
622
+ const pUrl = await resolvePageUrl(p);
623
+ if (ownedUrls.has(pUrl)) continue;
624
+ if (pUrl === url) {
625
+ targetPage = p;
626
+ break;
627
+ }
628
+ } catch {
629
+ }
630
+ }
631
+ if (targetPage) break;
632
+ }
633
+ }
634
+ if (!targetPage && targetHostname) {
611
635
  for (const ctx of contexts) {
612
636
  const pages = ctx.pages();
613
637
  for (const p of pages) {
614
- const pUrl = await resolvePageUrl(p);
638
+ const pUrl0 = await resolvePageUrl(p);
639
+ if (ownedUrls.has(pUrl0)) continue;
640
+ const pUrl = pUrl0;
615
641
  if (isRealPageUrl(pUrl) && pUrl.includes(targetHostname)) {
616
642
  targetPage = p;
617
643
  break;
@@ -624,7 +650,9 @@ async function createSession(name, url, options) {
624
650
  for (const ctx of contexts) {
625
651
  const pages = ctx.pages();
626
652
  for (const p of pages) {
627
- const pUrl = await resolvePageUrl(p);
653
+ const pUrl0 = await resolvePageUrl(p);
654
+ if (ownedUrls.has(pUrl0)) continue;
655
+ const pUrl = pUrl0;
628
656
  if (isRealPageUrl(pUrl)) {
629
657
  targetPage = p;
630
658
  break;
@@ -635,13 +663,36 @@ async function createSession(name, url, options) {
635
663
  }
636
664
  if (!targetPage && options?.cdpEndpoint) {
637
665
  const targets = await getCDPTargets(options.cdpEndpoint);
666
+ const ownedUrlsT = /* @__PURE__ */ new Set();
667
+ for (const ssn of sessions.list()) {
668
+ try {
669
+ const u = ssn.page?.url();
670
+ if (u && u !== "about:blank") ownedUrlsT.add(u);
671
+ } catch {
672
+ }
673
+ }
638
674
  const matchTarget = targets.find(
639
- (t) => t.url && t.url !== "about:blank" && !t.url.startsWith("chrome://") && !t.url.startsWith("chrome-untrusted://") && !t.url.startsWith("chrome-error://") && (url ? t.url.includes(new URL(url).hostname) : true)
675
+ (t) => t.url && t.url !== "about:blank" && !t.url.startsWith("chrome://") && !t.url.startsWith("chrome-untrusted://") && !t.url.startsWith("chrome-error://") && !ownedUrlsT.has(t.url) && (url ? t.url === url || t.url.includes(new URL(url).hostname) : true)
640
676
  );
641
677
  if (matchTarget && matchTarget.url) {
678
+ const ownedUrls2 = /* @__PURE__ */ new Set();
679
+ for (const ssn of sessions.list()) {
680
+ try {
681
+ const u = ssn.page?.url();
682
+ if (u && u !== "about:blank") ownedUrls2.add(u);
683
+ } catch {
684
+ }
685
+ }
686
+ const isOwned = (p) => {
687
+ try {
688
+ return ownedUrls2.has(p.url());
689
+ } catch {
690
+ return false;
691
+ }
692
+ };
642
693
  const existing2 = context.pages().find((p) => {
643
694
  try {
644
- return p.url() === matchTarget.url;
695
+ return p.url() === matchTarget.url && !isOwned(p);
645
696
  } catch {
646
697
  return false;
647
698
  }
@@ -659,7 +710,10 @@ async function createSession(name, url, options) {
659
710
  const pages = context.pages();
660
711
  if (pages.length > 1) {
661
712
  try {
713
+ const owned = /* @__PURE__ */ new Set();
714
+ for (const ssn of sessions.list()) owned.add(ssn.page);
662
715
  for (const p of pages) {
716
+ if (owned.has(p)) continue;
663
717
  const vis = await p.evaluate("document.visibilityState").catch(() => "hidden");
664
718
  if (vis === "visible") {
665
719
  targetPage = p;
@@ -1034,11 +1034,37 @@ async function createSession(name, url, options) {
1034
1034
  }
1035
1035
  context = contexts[0] || await b.newContext();
1036
1036
  let targetPage = null;
1037
- if (targetHostname) {
1037
+ const ownedUrls = /* @__PURE__ */ new Set();
1038
+ for (const ssn of sessions.list()) {
1039
+ try {
1040
+ const u = ssn.page?.url();
1041
+ if (u && u !== "about:blank") ownedUrls.add(u);
1042
+ } catch {
1043
+ }
1044
+ }
1045
+ if (url) {
1046
+ for (const ctx of contexts) {
1047
+ for (const p of ctx.pages()) {
1048
+ try {
1049
+ const pUrl = await resolvePageUrl(p);
1050
+ if (ownedUrls.has(pUrl)) continue;
1051
+ if (pUrl === url) {
1052
+ targetPage = p;
1053
+ break;
1054
+ }
1055
+ } catch {
1056
+ }
1057
+ }
1058
+ if (targetPage) break;
1059
+ }
1060
+ }
1061
+ if (!targetPage && targetHostname) {
1038
1062
  for (const ctx of contexts) {
1039
1063
  const pages = ctx.pages();
1040
1064
  for (const p of pages) {
1041
- const pUrl = await resolvePageUrl(p);
1065
+ const pUrl0 = await resolvePageUrl(p);
1066
+ if (ownedUrls.has(pUrl0)) continue;
1067
+ const pUrl = pUrl0;
1042
1068
  if (isRealPageUrl(pUrl) && pUrl.includes(targetHostname)) {
1043
1069
  targetPage = p;
1044
1070
  break;
@@ -1051,7 +1077,9 @@ async function createSession(name, url, options) {
1051
1077
  for (const ctx of contexts) {
1052
1078
  const pages = ctx.pages();
1053
1079
  for (const p of pages) {
1054
- const pUrl = await resolvePageUrl(p);
1080
+ const pUrl0 = await resolvePageUrl(p);
1081
+ if (ownedUrls.has(pUrl0)) continue;
1082
+ const pUrl = pUrl0;
1055
1083
  if (isRealPageUrl(pUrl)) {
1056
1084
  targetPage = p;
1057
1085
  break;
@@ -1062,13 +1090,36 @@ async function createSession(name, url, options) {
1062
1090
  }
1063
1091
  if (!targetPage && options?.cdpEndpoint) {
1064
1092
  const targets = await getCDPTargets(options.cdpEndpoint);
1093
+ const ownedUrlsT = /* @__PURE__ */ new Set();
1094
+ for (const ssn of sessions.list()) {
1095
+ try {
1096
+ const u = ssn.page?.url();
1097
+ if (u && u !== "about:blank") ownedUrlsT.add(u);
1098
+ } catch {
1099
+ }
1100
+ }
1065
1101
  const matchTarget = targets.find(
1066
- (t) => t.url && t.url !== "about:blank" && !t.url.startsWith("chrome://") && !t.url.startsWith("chrome-untrusted://") && !t.url.startsWith("chrome-error://") && (url ? t.url.includes(new URL(url).hostname) : true)
1102
+ (t) => t.url && t.url !== "about:blank" && !t.url.startsWith("chrome://") && !t.url.startsWith("chrome-untrusted://") && !t.url.startsWith("chrome-error://") && !ownedUrlsT.has(t.url) && (url ? t.url === url || t.url.includes(new URL(url).hostname) : true)
1067
1103
  );
1068
1104
  if (matchTarget && matchTarget.url) {
1105
+ const ownedUrls2 = /* @__PURE__ */ new Set();
1106
+ for (const ssn of sessions.list()) {
1107
+ try {
1108
+ const u = ssn.page?.url();
1109
+ if (u && u !== "about:blank") ownedUrls2.add(u);
1110
+ } catch {
1111
+ }
1112
+ }
1113
+ const isOwned = (p) => {
1114
+ try {
1115
+ return ownedUrls2.has(p.url());
1116
+ } catch {
1117
+ return false;
1118
+ }
1119
+ };
1069
1120
  const existing2 = context.pages().find((p) => {
1070
1121
  try {
1071
- return p.url() === matchTarget.url;
1122
+ return p.url() === matchTarget.url && !isOwned(p);
1072
1123
  } catch {
1073
1124
  return false;
1074
1125
  }
@@ -1086,7 +1137,10 @@ async function createSession(name, url, options) {
1086
1137
  const pages = context.pages();
1087
1138
  if (pages.length > 1) {
1088
1139
  try {
1140
+ const owned = /* @__PURE__ */ new Set();
1141
+ for (const ssn of sessions.list()) owned.add(ssn.page);
1089
1142
  for (const p of pages) {
1143
+ if (owned.has(p)) continue;
1090
1144
  const vis = await p.evaluate("document.visibilityState").catch(() => "hidden");
1091
1145
  if (vis === "visible") {
1092
1146
  targetPage = p;
package/dist/cli.js CHANGED
@@ -72,7 +72,7 @@ import {
72
72
  setActivePage,
73
73
  sleep,
74
74
  wheelDelta
75
- } from "./chunk-OU335JBI.js";
75
+ } from "./chunk-7SDM4EA4.js";
76
76
  import "./chunk-3KZ34AUC.js";
77
77
  import {
78
78
  errMsg
@@ -7545,7 +7545,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7545
7545
  }
7546
7546
  let targetPageOverride = null;
7547
7547
  if (_target && extraOpts?.cdpEndpoint) {
7548
- const { findTargetPage } = await import("./browser-W3Z4HPJN.js");
7548
+ const { findTargetPage } = await import("./browser-BEERPZPB.js");
7549
7549
  targetPageOverride = await findTargetPage(extraOpts.cdpEndpoint, _target);
7550
7550
  if (!targetPageOverride) {
7551
7551
  return errorResult(`Target "${_target}" not found. Use 'xbrowser targets --cdp ${extraOpts.cdpEndpoint}' to list available pages.`);
@@ -13723,7 +13723,7 @@ Run "xbrowser ${command} ${subCommand} --help" to see available parameters.`
13723
13723
  const targetPage = pages[cmdTabIndex];
13724
13724
  await targetPage.bringToFront().catch(() => {
13725
13725
  });
13726
- const { setActivePage: setActivePage2 } = await import("./browser-W3Z4HPJN.js");
13726
+ const { setActivePage: setActivePage2 } = await import("./browser-BEERPZPB.js");
13727
13727
  setActivePage2(session, targetPage);
13728
13728
  }
13729
13729
  }
@@ -13999,7 +13999,7 @@ async function main() {
13999
13999
  const command = process.argv[2];
14000
14000
  const isLongRunning = command === "preview" || command === "serve";
14001
14001
  if (!isLongRunning) {
14002
- const { ensureProcessCanExit } = await import("./browser-W3Z4HPJN.js");
14002
+ const { ensureProcessCanExit } = await import("./browser-BEERPZPB.js");
14003
14003
  await ensureProcessCanExit().catch(() => {
14004
14004
  });
14005
14005
  process.exit(process.exitCode || exitCode);
@@ -34,7 +34,7 @@ import {
34
34
  resolveLaunchOpts,
35
35
  saveSessionDiskMeta,
36
36
  setActivePage
37
- } from "./chunk-MMZCBUD3.js";
37
+ } from "./chunk-NA7IP6PO.js";
38
38
  import {
39
39
  createRuleEngine,
40
40
  rand,
@@ -7063,7 +7063,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7063
7063
  }
7064
7064
  let targetPageOverride = null;
7065
7065
  if (_target && extraOpts?.cdpEndpoint) {
7066
- const { findTargetPage } = await import("./browser-UPKOT3V6.js");
7066
+ const { findTargetPage } = await import("./browser-AEQS6325.js");
7067
7067
  targetPageOverride = await findTargetPage(extraOpts.cdpEndpoint, _target);
7068
7068
  if (!targetPageOverride) {
7069
7069
  return errorResult(`Target "${_target}" not found. Use 'xbrowser targets --cdp ${extraOpts.cdpEndpoint}' to list available pages.`);
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ import {
18
18
  resolveLaunchOpts,
19
19
  saveSessionDiskMeta,
20
20
  setActivePage
21
- } from "./chunk-EI2XZIDF.js";
21
+ } from "./chunk-MTNVT2T7.js";
22
22
  import {
23
23
  detectAntiBot,
24
24
  formatDetectionMessage
@@ -7896,7 +7896,7 @@ async function executeCommand(commandName, params, sessionName = "default", extr
7896
7896
  }
7897
7897
  let targetPageOverride = null;
7898
7898
  if (_target && extraOpts?.cdpEndpoint) {
7899
- const { findTargetPage } = await import("./browser-SYE57VHU.js");
7899
+ const { findTargetPage } = await import("./browser-TFFGGXOA.js");
7900
7900
  targetPageOverride = await findTargetPage(extraOpts.cdpEndpoint, _target);
7901
7901
  if (!targetPageOverride) {
7902
7902
  return errorResult(`Target "${_target}" not found. Use 'xbrowser targets --cdp ${extraOpts.cdpEndpoint}' to list available pages.`);
@@ -14112,7 +14112,7 @@ Run "xbrowser ${command} ${subCommand} --help" to see available parameters.`
14112
14112
  const targetPage = pages[cmdTabIndex];
14113
14113
  await targetPage.bringToFront().catch(() => {
14114
14114
  });
14115
- const { setActivePage: setActivePage2 } = await import("./browser-SYE57VHU.js");
14115
+ const { setActivePage: setActivePage2 } = await import("./browser-TFFGGXOA.js");
14116
14116
  setActivePage2(session, targetPage);
14117
14117
  }
14118
14118
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xbrowser/cli",
3
- "version": "1.18.1",
3
+ "version": "1.18.2",
4
4
  "description": "Browser automation CLI for web scraping, headless browsing, SEO analysis, and AI agent workflows. A command-line alternative to Playwright, Puppeteer, and Selenium.",
5
5
  "type": "module",
6
6
  "bin": {