@xbrowser/cli 1.33.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-3LBSVDSS.js → browser-KY7AIRAB.js} +3 -2
- package/dist/{browser-23BMBCH2.js → browser-MLKP72XP.js} +3 -3
- package/dist/{browser-D7RFPTD4.js → browser-RZ7DPBI3.js} +3 -3
- package/dist/cdp-driver-CCG3OJUQ.js +49 -0
- package/dist/{cdp-driver-B5KVVI4O.js → cdp-driver-HBMCD7NU.js} +2 -2
- package/dist/{cdp-driver-GE6Y6LPI.js → cdp-driver-MJD7YIQI.js} +2 -2
- package/dist/{cdp-driver-6G77XM4H.js → cdp-driver-YJU4GRSV.js} +203 -95
- package/dist/chunk-3SZTCI33.js +147 -0
- package/dist/{chunk-OVAUGFM6.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-YX5KVWGX.js → chunk-6DS3T6UK.js} +203 -95
- package/dist/{chunk-DDHHVII7.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-5MYC6LVL.js → chunk-GYGVHWG3.js} +279 -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-ACPMC47K.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-AKT3WLZM.js → chunk-Y2GRCINH.js} +1004 -183
- package/dist/{chunk-H25ECCYJ.js → chunk-ZCZELQCS.js} +203 -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-5JHB4TML.js → server-HUSX7EFE.js} +5 -4
- package/dist/{server-6CTC3RHV.js → server-KSP5H4HD.js} +5 -3
- package/dist/{session-replayer-IGRRA2QC.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";
|
|
@@ -1782,6 +1782,13 @@ function setupPageEvents(options) {
|
|
|
1782
1782
|
options.emit("framenavigated", options.mainFrame());
|
|
1783
1783
|
})
|
|
1784
1784
|
);
|
|
1785
|
+
options.addSubscription(
|
|
1786
|
+
options.conn.subscribe("Page.navigatedWithinDocument", options.sessionId, (params) => {
|
|
1787
|
+
const p = params;
|
|
1788
|
+
const url = p?.url ?? p?.frame?.url;
|
|
1789
|
+
if (url) options.setUrl(url);
|
|
1790
|
+
})
|
|
1791
|
+
);
|
|
1785
1792
|
options.addSubscription(
|
|
1786
1793
|
options.conn.subscribe("Page.loadEventFired", options.sessionId, () => {
|
|
1787
1794
|
options.markLoadFired();
|
|
@@ -2090,6 +2097,15 @@ var NavigationService = class {
|
|
|
2090
2097
|
if (result.errorText) {
|
|
2091
2098
|
throw new Error(`Navigation failed: ${result.errorText}`);
|
|
2092
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
|
+
}
|
|
2093
2109
|
if (waitUntil === "commit") {
|
|
2094
2110
|
this.options.setUrl(url);
|
|
2095
2111
|
return {
|
|
@@ -2112,42 +2128,41 @@ var NavigationService = class {
|
|
|
2112
2128
|
};
|
|
2113
2129
|
}
|
|
2114
2130
|
async goBack(opts = {}) {
|
|
2115
|
-
|
|
2116
|
-
const navHistory = await this.options.conn.send("Page.getNavigationHistory", void 0, this.options.sessionId);
|
|
2117
|
-
if (navHistory.currentIndex > 0) {
|
|
2118
|
-
const prevUrl = navHistory.entries[navHistory.currentIndex - 1]?.url;
|
|
2119
|
-
if (prevUrl && prevUrl !== "about:blank") {
|
|
2120
|
-
await this.options.conn.send("Page.navigate", { url: prevUrl }, this.options.sessionId);
|
|
2121
|
-
await this.options.waitForLoadState(opts.waitUntil ?? "domcontentloaded", opts.timeout ?? 1e4).catch(() => {
|
|
2122
|
-
});
|
|
2123
|
-
this.options.setUrl(prevUrl);
|
|
2124
|
-
return;
|
|
2125
|
-
}
|
|
2126
|
-
}
|
|
2127
|
-
} catch {
|
|
2128
|
-
}
|
|
2129
|
-
await this.options.evaluate("() => history.back()");
|
|
2130
|
-
await this.options.waitForTimeout(3e3);
|
|
2131
|
-
this.options.setUrl(await this.options.evaluate("location.href").catch(() => this.options.currentUrl()));
|
|
2131
|
+
await this.traverseHistory(-1, opts);
|
|
2132
2132
|
}
|
|
2133
2133
|
async goForward(opts = {}) {
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
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
|
+
}
|
|
2143
2160
|
return;
|
|
2144
2161
|
}
|
|
2145
2162
|
}
|
|
2146
|
-
|
|
2147
|
-
}
|
|
2148
|
-
|
|
2149
|
-
await this.options.waitForTimeout(3e3);
|
|
2150
|
-
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`);
|
|
2151
2166
|
}
|
|
2152
2167
|
async reload(opts = {}) {
|
|
2153
2168
|
this.options.state.loadFired = false;
|
|
@@ -2830,7 +2845,6 @@ var XBPageImpl = class _XBPageImpl {
|
|
|
2830
2845
|
setUrl: (url) => {
|
|
2831
2846
|
this._url = url;
|
|
2832
2847
|
},
|
|
2833
|
-
currentUrl: () => this.url(),
|
|
2834
2848
|
waitForLoadState: (state, timeout) => this.waitForLoadState(state, timeout),
|
|
2835
2849
|
waitForTimeout: (ms) => this.waitForTimeout(ms),
|
|
2836
2850
|
evaluate: (script) => this.evaluate(script)
|
|
@@ -3679,7 +3693,23 @@ var XBContextImpl = class {
|
|
|
3679
3693
|
_emitter = new EventEmitter2();
|
|
3680
3694
|
_browser;
|
|
3681
3695
|
contextId;
|
|
3682
|
-
|
|
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();
|
|
3683
3713
|
closed = false;
|
|
3684
3714
|
options;
|
|
3685
3715
|
targetAttachedHandler = null;
|
|
@@ -3706,28 +3736,30 @@ var XBContextImpl = class {
|
|
|
3706
3736
|
async newPage() {
|
|
3707
3737
|
if (this.closed) throw new Error("Context is closed");
|
|
3708
3738
|
const { targetId } = await this._browser._createTarget(this.contextId);
|
|
3709
|
-
|
|
3710
|
-
|
|
3711
|
-
|
|
3712
|
-
|
|
3713
|
-
|
|
3714
|
-
|
|
3715
|
-
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
|
|
3720
|
-
|
|
3721
|
-
|
|
3722
|
-
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
|
+
}
|
|
3723
3752
|
}
|
|
3724
|
-
|
|
3725
|
-
|
|
3753
|
+
const page = await pending;
|
|
3754
|
+
if (explicitSessionId && page.sessionId !== explicitSessionId) {
|
|
3755
|
+
this._browser._detachFromTarget(explicitSessionId).catch(() => {
|
|
3756
|
+
});
|
|
3726
3757
|
}
|
|
3758
|
+
await this._applyNewPageOptions(page);
|
|
3727
3759
|
return page;
|
|
3728
3760
|
}
|
|
3729
3761
|
pages() {
|
|
3730
|
-
return [...this._pages];
|
|
3762
|
+
return [...this._pages.values()];
|
|
3731
3763
|
}
|
|
3732
3764
|
browser() {
|
|
3733
3765
|
return this._browser;
|
|
@@ -3735,11 +3767,12 @@ var XBContextImpl = class {
|
|
|
3735
3767
|
async close() {
|
|
3736
3768
|
if (this.closed) return;
|
|
3737
3769
|
this.closed = true;
|
|
3738
|
-
for (const page of this._pages) {
|
|
3770
|
+
for (const page of this._pages.values()) {
|
|
3739
3771
|
await page.close().catch(() => {
|
|
3740
3772
|
});
|
|
3741
3773
|
}
|
|
3742
|
-
this._pages
|
|
3774
|
+
this._pages.clear();
|
|
3775
|
+
this._pendingRegistrations.clear();
|
|
3743
3776
|
if (this.targetAttachedHandler) {
|
|
3744
3777
|
this.conn.off("Target.attachedToTarget", this.targetAttachedHandler);
|
|
3745
3778
|
this.targetAttachedHandler = null;
|
|
@@ -3760,14 +3793,23 @@ var XBContextImpl = class {
|
|
|
3760
3793
|
}
|
|
3761
3794
|
async addInitScript(script) {
|
|
3762
3795
|
this._initScripts.push(script);
|
|
3763
|
-
for (const page of this._pages) {
|
|
3796
|
+
for (const page of this._pages.values()) {
|
|
3764
3797
|
await page.addInitScript(script);
|
|
3765
3798
|
}
|
|
3766
3799
|
}
|
|
3767
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
|
+
}
|
|
3768
3809
|
async cookies(urls) {
|
|
3769
3810
|
const urlList = typeof urls === "string" ? [urls] : urls;
|
|
3770
|
-
const
|
|
3811
|
+
const bcId = this.storageContextId;
|
|
3812
|
+
const params = bcId ? { ...urlList ? { urls: urlList } : {}, browserContextId: bcId } : urlList ? { urls: urlList } : void 0;
|
|
3771
3813
|
try {
|
|
3772
3814
|
const result = await this.conn.send("Storage.getCookies", params);
|
|
3773
3815
|
return result.cookies;
|
|
@@ -3791,15 +3833,18 @@ var XBContextImpl = class {
|
|
|
3791
3833
|
secure: c.secure,
|
|
3792
3834
|
sameSite: c.sameSite
|
|
3793
3835
|
}));
|
|
3836
|
+
const bcId = this.storageContextId;
|
|
3837
|
+
const params = bcId ? { cookies: cdpCookies, browserContextId: bcId } : { cookies: cdpCookies };
|
|
3794
3838
|
try {
|
|
3795
|
-
await this.conn.send("Storage.setCookies",
|
|
3839
|
+
await this.conn.send("Storage.setCookies", params);
|
|
3796
3840
|
} catch {
|
|
3797
3841
|
await this.conn.send("Network.setCookies", { cookies: cdpCookies });
|
|
3798
3842
|
}
|
|
3799
3843
|
}
|
|
3800
3844
|
async clearCookies() {
|
|
3845
|
+
const bcId = this.storageContextId;
|
|
3801
3846
|
try {
|
|
3802
|
-
await this.conn.send("Storage.clearCookies");
|
|
3847
|
+
await this.conn.send("Storage.clearCookies", bcId ? { browserContextId: bcId } : void 0);
|
|
3803
3848
|
} catch {
|
|
3804
3849
|
await this.conn.send("Network.clearBrowserCookies");
|
|
3805
3850
|
}
|
|
@@ -3811,18 +3856,92 @@ var XBContextImpl = class {
|
|
|
3811
3856
|
this._emitter.off(event, handler);
|
|
3812
3857
|
}
|
|
3813
3858
|
/**
|
|
3814
|
-
*
|
|
3815
|
-
*
|
|
3816
|
-
* pages from the user's
|
|
3817
|
-
* 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() 可用。
|
|
3818
3867
|
*/
|
|
3819
|
-
|
|
3820
|
-
|
|
3821
|
-
|
|
3822
|
-
|
|
3823
|
-
|
|
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
|
+
}
|
|
3824
3897
|
}
|
|
3825
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
|
+
}
|
|
3826
3945
|
/** Forward page-level events (request, response, etc.) to context listeners */
|
|
3827
3946
|
forwardPageEvents(page) {
|
|
3828
3947
|
const forward = (event) => {
|
|
@@ -3838,30 +3957,25 @@ var XBContextImpl = class {
|
|
|
3838
3957
|
setupAutoAttach() {
|
|
3839
3958
|
this.targetAttachedHandler = (paramsRaw) => {
|
|
3840
3959
|
const params = paramsRaw;
|
|
3841
|
-
if (this.contextId !== "default" && params.targetInfo.browserContextId !== this.contextId) return;
|
|
3842
3960
|
if (params.targetInfo.type !== "page") return;
|
|
3843
|
-
const
|
|
3844
|
-
|
|
3845
|
-
|
|
3846
|
-
if (
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
params.sessionId,
|
|
3850
|
-
params.targetInfo.targetId,
|
|
3851
|
-
this,
|
|
3852
|
-
this._browser
|
|
3853
|
-
);
|
|
3961
|
+
const bcId = params.targetInfo.browserContextId;
|
|
3962
|
+
if (this.contextId === "default") {
|
|
3963
|
+
if (bcId) return;
|
|
3964
|
+
} else if (bcId !== this.contextId) {
|
|
3965
|
+
return;
|
|
3966
|
+
}
|
|
3854
3967
|
this.conn.send("Runtime.runIfWaitingForDebugger", void 0, params.sessionId).catch(() => {
|
|
3855
3968
|
});
|
|
3856
|
-
|
|
3857
|
-
|
|
3858
|
-
|
|
3859
|
-
|
|
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
|
+
() => {
|
|
3860
3977
|
}
|
|
3861
|
-
|
|
3862
|
-
this.forwardPageEvents(page);
|
|
3863
|
-
this._emitter.emit("page", page);
|
|
3864
|
-
});
|
|
3978
|
+
);
|
|
3865
3979
|
};
|
|
3866
3980
|
this.conn.on("Target.attachedToTarget", this.targetAttachedHandler);
|
|
3867
3981
|
}
|
|
@@ -3932,7 +4046,7 @@ var XBBrowserImpl = class {
|
|
|
3932
4046
|
this._exitHandler = null;
|
|
3933
4047
|
}
|
|
3934
4048
|
if (this.childProcess) {
|
|
3935
|
-
const { killChrome: killChrome2 } = await import("./launcher-
|
|
4049
|
+
const { killChrome: killChrome2 } = await import("./launcher-QBAZ6F5L.js");
|
|
3936
4050
|
await killChrome2(this.childProcess, this.tmpDir);
|
|
3937
4051
|
}
|
|
3938
4052
|
await this.conn.close();
|
|
@@ -4112,7 +4226,7 @@ var XBBrowserImpl = class {
|
|
|
4112
4226
|
if (pageTargets.length === 0 && httpFallbackUrl) {
|
|
4113
4227
|
console.log(`[discoverContexts] Target.getTargets returned ${targetInfos.length} targets (0 page type). Falling back to HTTP /json/list at ${httpFallbackUrl}`);
|
|
4114
4228
|
try {
|
|
4115
|
-
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-
|
|
4229
|
+
const { getCDPTargets: getCDPTargets2 } = await import("./launcher-QBAZ6F5L.js");
|
|
4116
4230
|
const httpPages = await getCDPTargets2(httpFallbackUrl);
|
|
4117
4231
|
console.log(`[discoverContexts] HTTP /json/list returned ${httpPages.length} pages`);
|
|
4118
4232
|
for (const p of httpPages) {
|
|
@@ -4144,13 +4258,7 @@ var XBBrowserImpl = class {
|
|
|
4144
4258
|
if (this._contexts.has(ctxId)) continue;
|
|
4145
4259
|
const context = new XBContextImpl(this.conn, ctxId, this, {});
|
|
4146
4260
|
for (const p of pages) {
|
|
4147
|
-
|
|
4148
|
-
const sessionId = await this._attachToTarget(p.targetId);
|
|
4149
|
-
const page = new XBPageImpl(this.conn, sessionId, p.targetId, context, this);
|
|
4150
|
-
await page._init();
|
|
4151
|
-
context._addDiscoveredPage(page);
|
|
4152
|
-
} catch {
|
|
4153
|
-
}
|
|
4261
|
+
await context._attachExistingPage(p.targetId).catch(() => null);
|
|
4154
4262
|
}
|
|
4155
4263
|
this._contexts.set(ctxId, { contextId: ctxId, context });
|
|
4156
4264
|
}
|