@xbrowser/cli 1.34.0 → 1.35.0
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/{browser-GXL6V2JW.js → browser-KY7AIRAB.js} +3 -2
- package/dist/{browser-ZWEJ663M.js → browser-MLKP72XP.js} +3 -3
- package/dist/{browser-X7LO42UI.js → browser-RZ7DPBI3.js} +3 -3
- package/dist/cdp-driver-CCG3OJUQ.js +49 -0
- package/dist/{cdp-driver-GCFEMRFJ.js → cdp-driver-HBMCD7NU.js} +2 -2
- package/dist/{cdp-driver-QOUSRPR2.js → cdp-driver-MJD7YIQI.js} +2 -2
- package/dist/{cdp-driver-4MNHDU2J.js → cdp-driver-YJU4GRSV.js} +196 -95
- package/dist/chunk-3SZTCI33.js +147 -0
- package/dist/{chunk-DZ6XEPAH.js → chunk-43U5VDLB.js} +8 -2
- package/dist/chunk-53VZHESL.js +150 -0
- package/dist/{chunk-NAIHOVDZ.js → chunk-63526WET.js} +2 -8
- package/dist/{chunk-YIL44YDX.js → chunk-6DS3T6UK.js} +196 -95
- package/dist/{chunk-N7DFS4V7.js → chunk-BLCBCESM.js} +8 -2
- package/dist/{chunk-SH6OTPXN.js → chunk-C5ZPXPD7.js} +31 -7
- package/dist/chunk-EGOWDZXP.js +149 -0
- package/dist/chunk-GNLZWHSP.js +1380 -0
- package/dist/{chunk-3E6VVMK2.js → chunk-GYGVHWG3.js} +272 -1460
- package/dist/{chunk-2KPI5GKP.js → chunk-IYCB2KJL.js} +2 -8
- package/dist/chunk-JYYKMSFH.js +39 -0
- package/dist/{chunk-TBJUSUKF.js → chunk-NBT2CE3H.js} +140 -96
- package/dist/{chunk-J4NOL5XX.js → chunk-QRFM4NOV.js} +1025 -202
- package/dist/chunk-RGL2YTWQ.js +64 -0
- package/dist/{chunk-BND5O5KC.js → chunk-SQLICOPZ.js} +177 -240
- package/dist/{chunk-O5PASNI7.js → chunk-UUW5EGES.js} +139 -237
- package/dist/{chunk-43TEMG4U.js → chunk-WGS3Y6ZV.js} +3 -1
- package/dist/{chunk-R57Z5KZX.js → chunk-Y2GRCINH.js} +1004 -183
- package/dist/{chunk-R7AG7ONI.js → chunk-ZCZELQCS.js} +196 -95
- package/dist/cli.js +2237 -278
- package/dist/{daemon-client-7D6EZNOE.js → daemon-client-OXKRGLPQ.js} +32 -8
- package/dist/{daemon-client-HEGAXWGK.js → daemon-client-Z3NKNZRL.js} +5 -1
- package/dist/daemon-main.js +2214 -159
- package/dist/human-interaction-BGAZC3JR.js +12 -0
- package/dist/human-interaction-TPKPEE7A.js +11 -0
- package/dist/human-interaction-ZSD3IX6Q.js +12 -0
- package/dist/index.d.ts +225 -94
- package/dist/index.js +2880 -267
- package/dist/{launcher-TOLF23ET.js → launcher-AUJK5QQM.js} +1 -1
- package/dist/{launcher-ZYB32LSZ.js → launcher-QBAZ6F5L.js} +1 -1
- package/dist/mistake-ledger-2B4N54CO.js +29 -0
- package/dist/{recovery-ORHJSBDN.js → recovery-5AGY7CV3.js} +4 -5
- package/dist/{recovery-JFGV3DBX.js → recovery-7NRRHLS4.js} +4 -4
- package/dist/{recovery-XDKN63O5.js → recovery-TIBRFGRP.js} +4 -4
- package/dist/run-routes-SJKVZ34L.js +26 -0
- package/dist/run-routes-TFNV5BBR.js +24 -0
- package/dist/{server-5U56MQD2.js → server-HUSX7EFE.js} +5 -4
- package/dist/{server-R4OYD7ZC.js → server-KSP5H4HD.js} +5 -3
- package/dist/{session-replayer-GHEFFNGV.js → session-replayer-4TCLQI76.js} +1 -1
- package/dist/viewer-routes-YOS5GTCV.js +11 -0
- package/package.json +1 -1
- package/dist/chunk-QCV2PI7U.js +0 -184
- package/dist/human-interaction-ISMMOJOK.js +0 -8
- package/dist/human-interaction-STTZZZ5N.js +0 -8
- package/dist/human-interaction-UXFYV7DU.js +0 -8
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
import {
|
|
14
14
|
connectToCDP,
|
|
15
15
|
launchChrome
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-IYCB2KJL.js";
|
|
17
17
|
import {
|
|
18
18
|
errMsg
|
|
19
19
|
} from "./chunk-GDKLH7ZY.js";
|
|
@@ -2097,6 +2097,15 @@ var NavigationService = class {
|
|
|
2097
2097
|
if (result.errorText) {
|
|
2098
2098
|
throw new Error(`Navigation failed: ${result.errorText}`);
|
|
2099
2099
|
}
|
|
2100
|
+
if (!result.loaderId) {
|
|
2101
|
+
this.options.setUrl(url);
|
|
2102
|
+
return {
|
|
2103
|
+
status: () => 200,
|
|
2104
|
+
ok: () => true,
|
|
2105
|
+
url: () => url,
|
|
2106
|
+
headers: () => ({})
|
|
2107
|
+
};
|
|
2108
|
+
}
|
|
2100
2109
|
if (waitUntil === "commit") {
|
|
2101
2110
|
this.options.setUrl(url);
|
|
2102
2111
|
return {
|
|
@@ -2119,42 +2128,41 @@ var NavigationService = class {
|
|
|
2119
2128
|
};
|
|
2120
2129
|
}
|
|
2121
2130
|
async goBack(opts = {}) {
|
|
2122
|
-
|
|
2123
|
-
const navHistory = await this.options.conn.send("Page.getNavigationHistory", void 0, this.options.sessionId);
|
|
2124
|
-
if (navHistory.currentIndex > 0) {
|
|
2125
|
-
const prevUrl = navHistory.entries[navHistory.currentIndex - 1]?.url;
|
|
2126
|
-
if (prevUrl && prevUrl !== "about:blank") {
|
|
2127
|
-
await this.options.conn.send("Page.navigate", { url: prevUrl }, this.options.sessionId);
|
|
2128
|
-
await this.options.waitForLoadState(opts.waitUntil ?? "domcontentloaded", opts.timeout ?? 1e4).catch(() => {
|
|
2129
|
-
});
|
|
2130
|
-
this.options.setUrl(prevUrl);
|
|
2131
|
-
return;
|
|
2132
|
-
}
|
|
2133
|
-
}
|
|
2134
|
-
} catch {
|
|
2135
|
-
}
|
|
2136
|
-
await this.options.evaluate("() => history.back()");
|
|
2137
|
-
await this.options.waitForTimeout(3e3);
|
|
2138
|
-
this.options.setUrl(await this.options.evaluate("location.href").catch(() => this.options.currentUrl()));
|
|
2131
|
+
await this.traverseHistory(-1, opts);
|
|
2139
2132
|
}
|
|
2140
2133
|
async goForward(opts = {}) {
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2147
|
-
|
|
2148
|
-
|
|
2149
|
-
|
|
2134
|
+
await this.traverseHistory(1, opts);
|
|
2135
|
+
}
|
|
2136
|
+
async traverseHistory(offset, { timeout = 1e4, waitUntil = "domcontentloaded" }) {
|
|
2137
|
+
if (this.options.isClosed()) throw new Error("Page is closed");
|
|
2138
|
+
const { conn, sessionId } = this.options;
|
|
2139
|
+
const getHistory = () => conn.send(
|
|
2140
|
+
"Page.getNavigationHistory",
|
|
2141
|
+
void 0,
|
|
2142
|
+
sessionId
|
|
2143
|
+
);
|
|
2144
|
+
const history = await getHistory();
|
|
2145
|
+
const entry = history.entries[history.currentIndex + offset];
|
|
2146
|
+
if (!entry) return;
|
|
2147
|
+
await conn.send("Page.navigateToHistoryEntry", { entryId: entry.id }, sessionId);
|
|
2148
|
+
const deadline = Date.now() + timeout;
|
|
2149
|
+
do {
|
|
2150
|
+
const updated = await getHistory();
|
|
2151
|
+
if (updated.entries[updated.currentIndex]?.id === entry.id) {
|
|
2152
|
+
const document = await this.options.evaluate(
|
|
2153
|
+
"({ url: location.href, ready: document.readyState })"
|
|
2154
|
+
).catch(() => null);
|
|
2155
|
+
if (document?.url === updated.entries[updated.currentIndex].url && (waitUntil === "commit" || (waitUntil === "load" ? document.ready === "complete" : document.ready !== "loading"))) {
|
|
2156
|
+
this.options.setUrl(document.url);
|
|
2157
|
+
if (waitUntil === "networkidle") {
|
|
2158
|
+
await this.options.waitForLoadState(waitUntil, Math.max(0, deadline - Date.now()));
|
|
2159
|
+
}
|
|
2150
2160
|
return;
|
|
2151
2161
|
}
|
|
2152
2162
|
}
|
|
2153
|
-
|
|
2154
|
-
}
|
|
2155
|
-
|
|
2156
|
-
await this.options.waitForTimeout(3e3);
|
|
2157
|
-
this.options.setUrl(await this.options.evaluate("location.href").catch(() => this.options.currentUrl()));
|
|
2163
|
+
await this.options.waitForTimeout(50);
|
|
2164
|
+
} while (Date.now() < deadline);
|
|
2165
|
+
throw new Error(`History navigation timed out after ${timeout}ms`);
|
|
2158
2166
|
}
|
|
2159
2167
|
async reload(opts = {}) {
|
|
2160
2168
|
this.options.state.loadFired = false;
|
|
@@ -2837,7 +2845,6 @@ var XBPageImpl = class _XBPageImpl {
|
|
|
2837
2845
|
setUrl: (url) => {
|
|
2838
2846
|
this._url = url;
|
|
2839
2847
|
},
|
|
2840
|
-
currentUrl: () => this.url(),
|
|
2841
2848
|
waitForLoadState: (state, timeout) => this.waitForLoadState(state, timeout),
|
|
2842
2849
|
waitForTimeout: (ms) => this.waitForTimeout(ms),
|
|
2843
2850
|
evaluate: (script) => this.evaluate(script)
|
|
@@ -3686,7 +3693,23 @@ var XBContextImpl = class {
|
|
|
3686
3693
|
_emitter = new EventEmitter2();
|
|
3687
3694
|
_browser;
|
|
3688
3695
|
contextId;
|
|
3689
|
-
|
|
3696
|
+
/**
|
|
3697
|
+
* 单一规范注册表(dup 回归修复):targetId → wrapper。
|
|
3698
|
+
*
|
|
3699
|
+
* 同一 target 的 wrapper 有三条并发创建路径——newPage() 显式创建、
|
|
3700
|
+
* setAutoAttach 对新建 target 的自动附着事件、Target.attachToTarget 的
|
|
3701
|
+
* attachedToTarget 回显事件(CDP 规范:显式 attach 也会发该事件)。旧实现
|
|
3702
|
+
* 用数组在 `await page._init()` 之后去重,事件在 _init 期间到达时全部穿透
|
|
3703
|
+
* ——headless E2E 实测同一 target 出 3 个 wrapper,且随事件顺序抖动。
|
|
3704
|
+
*
|
|
3705
|
+
* 现在所有路径先**同步预约**(`_reserveTarget` + 同步 set 进
|
|
3706
|
+
* `_pendingRegistrations`),再异步初始化;后到者直接 join 同一个注册
|
|
3707
|
+
* Promise 拿同一个 wrapper,事件顺序无关。注册 Promise 覆盖到 init
|
|
3708
|
+
* scripts 应用完成——join 者拿到的必然是完整初始化的 wrapper。
|
|
3709
|
+
*/
|
|
3710
|
+
_pages = /* @__PURE__ */ new Map();
|
|
3711
|
+
/** in-flight 注册(targetId → 注册 Promise),完成后移除并落入 _pages */
|
|
3712
|
+
_pendingRegistrations = /* @__PURE__ */ new Map();
|
|
3690
3713
|
closed = false;
|
|
3691
3714
|
options;
|
|
3692
3715
|
targetAttachedHandler = null;
|
|
@@ -3713,28 +3736,30 @@ var XBContextImpl = class {
|
|
|
3713
3736
|
async newPage() {
|
|
3714
3737
|
if (this.closed) throw new Error("Context is closed");
|
|
3715
3738
|
const { targetId } = await this._browser._createTarget(this.contextId);
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
|
|
3726
|
-
|
|
3727
|
-
|
|
3728
|
-
|
|
3729
|
-
await page._setExtraHTTPHeaders(this.options.extraHTTPHeaders);
|
|
3739
|
+
let pending = this._reserveTarget(targetId);
|
|
3740
|
+
let explicitSessionId;
|
|
3741
|
+
if (!pending) {
|
|
3742
|
+
const sessionId = await this._browser._attachToTarget(targetId);
|
|
3743
|
+
pending = this._reserveTarget(targetId);
|
|
3744
|
+
if (!pending) {
|
|
3745
|
+
const registration = this._registerTarget(targetId, sessionId);
|
|
3746
|
+
this._pendingRegistrations.set(targetId, registration);
|
|
3747
|
+
pending = registration;
|
|
3748
|
+
explicitSessionId = void 0;
|
|
3749
|
+
} else {
|
|
3750
|
+
explicitSessionId = sessionId;
|
|
3751
|
+
}
|
|
3730
3752
|
}
|
|
3731
|
-
|
|
3732
|
-
|
|
3753
|
+
const page = await pending;
|
|
3754
|
+
if (explicitSessionId && page.sessionId !== explicitSessionId) {
|
|
3755
|
+
this._browser._detachFromTarget(explicitSessionId).catch(() => {
|
|
3756
|
+
});
|
|
3733
3757
|
}
|
|
3758
|
+
await this._applyNewPageOptions(page);
|
|
3734
3759
|
return page;
|
|
3735
3760
|
}
|
|
3736
3761
|
pages() {
|
|
3737
|
-
return [...this._pages];
|
|
3762
|
+
return [...this._pages.values()];
|
|
3738
3763
|
}
|
|
3739
3764
|
browser() {
|
|
3740
3765
|
return this._browser;
|
|
@@ -3742,11 +3767,12 @@ var XBContextImpl = class {
|
|
|
3742
3767
|
async close() {
|
|
3743
3768
|
if (this.closed) return;
|
|
3744
3769
|
this.closed = true;
|
|
3745
|
-
for (const page of this._pages) {
|
|
3770
|
+
for (const page of this._pages.values()) {
|
|
3746
3771
|
await page.close().catch(() => {
|
|
3747
3772
|
});
|
|
3748
3773
|
}
|
|
3749
|
-
this._pages
|
|
3774
|
+
this._pages.clear();
|
|
3775
|
+
this._pendingRegistrations.clear();
|
|
3750
3776
|
if (this.targetAttachedHandler) {
|
|
3751
3777
|
this.conn.off("Target.attachedToTarget", this.targetAttachedHandler);
|
|
3752
3778
|
this.targetAttachedHandler = null;
|
|
@@ -3767,14 +3793,23 @@ var XBContextImpl = class {
|
|
|
3767
3793
|
}
|
|
3768
3794
|
async addInitScript(script) {
|
|
3769
3795
|
this._initScripts.push(script);
|
|
3770
|
-
for (const page of this._pages) {
|
|
3796
|
+
for (const page of this._pages.values()) {
|
|
3771
3797
|
await page.addInitScript(script);
|
|
3772
3798
|
}
|
|
3773
3799
|
}
|
|
3774
3800
|
// ── Cookies ─────────────────────────────────────────────────
|
|
3801
|
+
/**
|
|
3802
|
+
* Real CDP browserContextId (from Target.createBrowserContext), or undefined
|
|
3803
|
+
* for the default context (contextId 'default' / '' is not a CDP id — passing
|
|
3804
|
+
* it to Storage.* makes CDP reject the whole call).
|
|
3805
|
+
*/
|
|
3806
|
+
get storageContextId() {
|
|
3807
|
+
return this.contextId && this.contextId !== "default" ? this.contextId : void 0;
|
|
3808
|
+
}
|
|
3775
3809
|
async cookies(urls) {
|
|
3776
3810
|
const urlList = typeof urls === "string" ? [urls] : urls;
|
|
3777
|
-
const
|
|
3811
|
+
const bcId = this.storageContextId;
|
|
3812
|
+
const params = bcId ? { ...urlList ? { urls: urlList } : {}, browserContextId: bcId } : urlList ? { urls: urlList } : void 0;
|
|
3778
3813
|
try {
|
|
3779
3814
|
const result = await this.conn.send("Storage.getCookies", params);
|
|
3780
3815
|
return result.cookies;
|
|
@@ -3798,15 +3833,18 @@ var XBContextImpl = class {
|
|
|
3798
3833
|
secure: c.secure,
|
|
3799
3834
|
sameSite: c.sameSite
|
|
3800
3835
|
}));
|
|
3836
|
+
const bcId = this.storageContextId;
|
|
3837
|
+
const params = bcId ? { cookies: cdpCookies, browserContextId: bcId } : { cookies: cdpCookies };
|
|
3801
3838
|
try {
|
|
3802
|
-
await this.conn.send("Storage.setCookies",
|
|
3839
|
+
await this.conn.send("Storage.setCookies", params);
|
|
3803
3840
|
} catch {
|
|
3804
3841
|
await this.conn.send("Network.setCookies", { cookies: cdpCookies });
|
|
3805
3842
|
}
|
|
3806
3843
|
}
|
|
3807
3844
|
async clearCookies() {
|
|
3845
|
+
const bcId = this.storageContextId;
|
|
3808
3846
|
try {
|
|
3809
|
-
await this.conn.send("Storage.clearCookies");
|
|
3847
|
+
await this.conn.send("Storage.clearCookies", bcId ? { browserContextId: bcId } : void 0);
|
|
3810
3848
|
} catch {
|
|
3811
3849
|
await this.conn.send("Network.clearBrowserCookies");
|
|
3812
3850
|
}
|
|
@@ -3818,18 +3856,92 @@ var XBContextImpl = class {
|
|
|
3818
3856
|
this._emitter.off(event, handler);
|
|
3819
3857
|
}
|
|
3820
3858
|
/**
|
|
3821
|
-
*
|
|
3822
|
-
*
|
|
3823
|
-
* pages from the user's
|
|
3824
|
-
* so they appear in `context.pages()
|
|
3859
|
+
* Attach an existing target (discovered via Target.getTargets / HTTP
|
|
3860
|
+
* /json/list) and register exactly one wrapper for it. Used by
|
|
3861
|
+
* XBBrowserImpl.discoverContexts() to wire up pages from the user's
|
|
3862
|
+
* existing browser session so they appear in `context.pages()`.
|
|
3863
|
+
*
|
|
3864
|
+
* 显式 attach 同样会触发 attachedToTarget 回显事件(auto-attach 也会对
|
|
3865
|
+
* 既有 target 补附着)——全部经注册表预约去重。attach 失败(如 target
|
|
3866
|
+
* 已被其他客户端占用)返回 null:context 仍注册,后续 newPage() 可用。
|
|
3825
3867
|
*/
|
|
3826
|
-
|
|
3827
|
-
|
|
3828
|
-
|
|
3829
|
-
|
|
3830
|
-
|
|
3868
|
+
async _attachExistingPage(targetId) {
|
|
3869
|
+
let pending = this._reserveTarget(targetId);
|
|
3870
|
+
let explicitSessionId;
|
|
3871
|
+
if (!pending) {
|
|
3872
|
+
let sessionId;
|
|
3873
|
+
try {
|
|
3874
|
+
sessionId = await this._browser._attachToTarget(targetId);
|
|
3875
|
+
} catch {
|
|
3876
|
+
return null;
|
|
3877
|
+
}
|
|
3878
|
+
pending = this._reserveTarget(targetId);
|
|
3879
|
+
if (!pending) {
|
|
3880
|
+
const registration = this._registerTarget(targetId, sessionId);
|
|
3881
|
+
this._pendingRegistrations.set(targetId, registration);
|
|
3882
|
+
pending = registration;
|
|
3883
|
+
} else {
|
|
3884
|
+
explicitSessionId = sessionId;
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
try {
|
|
3888
|
+
const page = await pending;
|
|
3889
|
+
if (explicitSessionId && page.sessionId !== explicitSessionId) {
|
|
3890
|
+
this._browser._detachFromTarget(explicitSessionId).catch(() => {
|
|
3891
|
+
});
|
|
3892
|
+
}
|
|
3893
|
+
return page;
|
|
3894
|
+
} catch {
|
|
3895
|
+
return null;
|
|
3896
|
+
}
|
|
3831
3897
|
}
|
|
3832
3898
|
// ── Private ─────────────────────────────────────────────────
|
|
3899
|
+
/**
|
|
3900
|
+
* 同步查询/预约 target:已注册返回其 resolved Promise;in-flight 返回
|
|
3901
|
+
* 注册 Promise(join 同一 wrapper);否则返回 null,调用方须同步发起
|
|
3902
|
+
* 注册并 set 进 `_pendingRegistrations`(在任意 await 之前)。
|
|
3903
|
+
*/
|
|
3904
|
+
_reserveTarget(targetId) {
|
|
3905
|
+
const registered = this._pages.get(targetId);
|
|
3906
|
+
if (registered) return Promise.resolve(registered);
|
|
3907
|
+
return this._pendingRegistrations.get(targetId) ?? null;
|
|
3908
|
+
}
|
|
3909
|
+
/**
|
|
3910
|
+
* 执行注册:创建 wrapper → _init → 应用 init scripts → 入注册表。
|
|
3911
|
+
* Promise 覆盖到 init scripts 应用完成;成功/失败都从 in-flight 表移除
|
|
3912
|
+
* (失败向上抛给所有 join 者,后续可重新预约重试)。
|
|
3913
|
+
*/
|
|
3914
|
+
async _registerTarget(targetId, sessionId) {
|
|
3915
|
+
try {
|
|
3916
|
+
const page = new XBPageImpl(this.conn, sessionId, targetId, this, this._browser);
|
|
3917
|
+
await page._init();
|
|
3918
|
+
for (const script of this._initScripts) {
|
|
3919
|
+
await page.addInitScript(script).catch(() => {
|
|
3920
|
+
});
|
|
3921
|
+
}
|
|
3922
|
+
this._pages.set(targetId, page);
|
|
3923
|
+
page.on("close", () => {
|
|
3924
|
+
if (this._pages.get(targetId) === page) this._pages.delete(targetId);
|
|
3925
|
+
});
|
|
3926
|
+
this.forwardPageEvents(page);
|
|
3927
|
+
return page;
|
|
3928
|
+
} finally {
|
|
3929
|
+
this._pendingRegistrations.delete(targetId);
|
|
3930
|
+
}
|
|
3931
|
+
}
|
|
3932
|
+
/** newPage 的上下文选项(viewport/UA/headers)——自建与 join 路径共用 */
|
|
3933
|
+
async _applyNewPageOptions(page) {
|
|
3934
|
+
if (this.options.viewport) {
|
|
3935
|
+
await page.setViewportSize(this.options.viewport).catch(() => {
|
|
3936
|
+
});
|
|
3937
|
+
}
|
|
3938
|
+
if (this.options.userAgent) {
|
|
3939
|
+
await page._setUserAgent(this.options.userAgent);
|
|
3940
|
+
}
|
|
3941
|
+
if (this.options.extraHTTPHeaders) {
|
|
3942
|
+
await page._setExtraHTTPHeaders(this.options.extraHTTPHeaders);
|
|
3943
|
+
}
|
|
3944
|
+
}
|
|
3833
3945
|
/** Forward page-level events (request, response, etc.) to context listeners */
|
|
3834
3946
|
forwardPageEvents(page) {
|
|
3835
3947
|
const forward = (event) => {
|
|
@@ -3845,30 +3957,25 @@ var XBContextImpl = class {
|
|
|
3845
3957
|
setupAutoAttach() {
|
|
3846
3958
|
this.targetAttachedHandler = (paramsRaw) => {
|
|
3847
3959
|
const params = paramsRaw;
|
|
3848
|
-
if (this.contextId !== "default" && params.targetInfo.browserContextId !== this.contextId) return;
|
|
3849
3960
|
if (params.targetInfo.type !== "page") return;
|
|
3850
|
-
const
|
|
3851
|
-
|
|
3852
|
-
|
|
3853
|
-
if (
|
|
3854
|
-
|
|
3855
|
-
|
|
3856
|
-
params.sessionId,
|
|
3857
|
-
params.targetInfo.targetId,
|
|
3858
|
-
this,
|
|
3859
|
-
this._browser
|
|
3860
|
-
);
|
|
3961
|
+
const bcId = params.targetInfo.browserContextId;
|
|
3962
|
+
if (this.contextId === "default") {
|
|
3963
|
+
if (bcId) return;
|
|
3964
|
+
} else if (bcId !== this.contextId) {
|
|
3965
|
+
return;
|
|
3966
|
+
}
|
|
3861
3967
|
this.conn.send("Runtime.runIfWaitingForDebugger", void 0, params.sessionId).catch(() => {
|
|
3862
3968
|
});
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
|
|
3969
|
+
if (this._reserveTarget(params.targetInfo.targetId)) return;
|
|
3970
|
+
const registration = this._registerTarget(params.targetInfo.targetId, params.sessionId);
|
|
3971
|
+
this._pendingRegistrations.set(params.targetInfo.targetId, registration);
|
|
3972
|
+
registration.then(
|
|
3973
|
+
(page) => {
|
|
3974
|
+
this._emitter.emit("page", page);
|
|
3975
|
+
},
|
|
3976
|
+
() => {
|
|
3867
3977
|
}
|
|
3868
|
-
|
|
3869
|
-
this.forwardPageEvents(page);
|
|
3870
|
-
this._emitter.emit("page", page);
|
|
3871
|
-
});
|
|
3978
|
+
);
|
|
3872
3979
|
};
|
|
3873
3980
|
this.conn.on("Target.attachedToTarget", this.targetAttachedHandler);
|
|
3874
3981
|
}
|
|
@@ -3939,7 +4046,7 @@ var XBBrowserImpl = class {
|
|
|
3939
4046
|
this._exitHandler = null;
|
|
3940
4047
|
}
|
|
3941
4048
|
if (this.childProcess) {
|
|
3942
|
-
const { killChrome: killChrome2 } = await import("./launcher-
|
|
4049
|
+
const { killChrome: killChrome2 } = await import("./launcher-QBAZ6F5L.js");
|
|
3943
4050
|
await killChrome2(this.childProcess, this.tmpDir);
|
|
3944
4051
|
}
|
|
3945
4052
|
await this.conn.close();
|
|
@@ -4119,7 +4226,7 @@ var XBBrowserImpl = class {
|
|
|
4119
4226
|
if (pageTargets.length === 0 && httpFallbackUrl) {
|
|
4120
4227
|
console.log(`[discoverContexts] Target.getTargets returned ${targetInfos.length} targets (0 page type). Falling back to HTTP /json/list at ${httpFallbackUrl}`);
|
|
4121
4228
|
try {
|
|
4122
|
-
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-
|
|
4229
|
+
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-QBAZ6F5L.js");
|
|
4123
4230
|
const httpPages = await getCDPTargets2(httpFallbackUrl);
|
|
4124
4231
|
console.log(`[discoverContexts] HTTP /json/list returned ${httpPages.length} pages`);
|
|
4125
4232
|
for (const p of httpPages) {
|
|
@@ -4151,13 +4258,7 @@ var XBBrowserImpl = class {
|
|
|
4151
4258
|
if (this._contexts.has(ctxId)) continue;
|
|
4152
4259
|
const context = new XBContextImpl(this.conn, ctxId, this, {});
|
|
4153
4260
|
for (const p of pages) {
|
|
4154
|
-
|
|
4155
|
-
const sessionId = await this._attachToTarget(p.targetId);
|
|
4156
|
-
const page = new XBPageImpl(this.conn, sessionId, p.targetId, context, this);
|
|
4157
|
-
await page._init();
|
|
4158
|
-
context._addDiscoveredPage(page);
|
|
4159
|
-
} catch {
|
|
4160
|
-
}
|
|
4261
|
+
await context._attachExistingPage(p.targetId).catch(() => null);
|
|
4161
4262
|
}
|
|
4162
4263
|
this._contexts.set(ctxId, { contextId: ctxId, context });
|
|
4163
4264
|
}
|