browserclaw 0.11.4 → 0.11.5
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/index.cjs +31 -18
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +25 -1
- package/dist/index.d.ts +25 -1
- package/dist/index.js +31 -20
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1894,6 +1894,7 @@ function ensurePageState(page) {
|
|
|
1894
1894
|
page.on("dialog", (dialog) => {
|
|
1895
1895
|
if (state.armIdDialog > 0) return;
|
|
1896
1896
|
if (state.dialogHandler) {
|
|
1897
|
+
const handler = state.dialogHandler;
|
|
1897
1898
|
let handled = false;
|
|
1898
1899
|
const event = {
|
|
1899
1900
|
type: dialog.type(),
|
|
@@ -1908,7 +1909,7 @@ function ensurePageState(page) {
|
|
|
1908
1909
|
return dialog.dismiss();
|
|
1909
1910
|
}
|
|
1910
1911
|
};
|
|
1911
|
-
Promise.resolve(
|
|
1912
|
+
Promise.resolve().then(() => handler(event)).then(() => {
|
|
1912
1913
|
if (!handled) {
|
|
1913
1914
|
dialog.dismiss().catch((err) => {
|
|
1914
1915
|
console.warn(
|
|
@@ -2116,7 +2117,9 @@ async function fetchJsonForCdp(url, timeoutMs) {
|
|
|
2116
2117
|
const res = await fetch(url, { signal: ctrl.signal });
|
|
2117
2118
|
if (!res.ok) return null;
|
|
2118
2119
|
return await res.json();
|
|
2119
|
-
} catch {
|
|
2120
|
+
} catch (err) {
|
|
2121
|
+
if (process.env.DEBUG !== void 0 && process.env.DEBUG !== "")
|
|
2122
|
+
console.warn(`[browserclaw] fetchJsonForCdp ${url} failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
2120
2123
|
return null;
|
|
2121
2124
|
} finally {
|
|
2122
2125
|
clearTimeout(t);
|
|
@@ -2324,7 +2327,10 @@ async function disconnectBrowser() {
|
|
|
2324
2327
|
for (const p of connectingByCdpUrl.values()) {
|
|
2325
2328
|
try {
|
|
2326
2329
|
await p;
|
|
2327
|
-
} catch {
|
|
2330
|
+
} catch (err) {
|
|
2331
|
+
console.warn(
|
|
2332
|
+
`[browserclaw] disconnectBrowser: pending connect failed: ${err instanceof Error ? err.message : String(err)}`
|
|
2333
|
+
);
|
|
2328
2334
|
}
|
|
2329
2335
|
}
|
|
2330
2336
|
}
|
|
@@ -2450,12 +2456,17 @@ var forceDisconnectPlaywrightForTarget = forceDisconnectPlaywrightConnection;
|
|
|
2450
2456
|
function getAllPages(browser) {
|
|
2451
2457
|
return browser.contexts().flatMap((c) => c.pages());
|
|
2452
2458
|
}
|
|
2459
|
+
var pageTargetIdCache = /* @__PURE__ */ new WeakMap();
|
|
2453
2460
|
async function pageTargetId(page) {
|
|
2461
|
+
const cached = pageTargetIdCache.get(page);
|
|
2462
|
+
if (cached !== void 0) return cached;
|
|
2454
2463
|
const session = await page.context().newCDPSession(page);
|
|
2455
2464
|
try {
|
|
2456
2465
|
const info = await session.send("Target.getTargetInfo");
|
|
2457
2466
|
const targetInfo = info.targetInfo;
|
|
2458
|
-
|
|
2467
|
+
const id = (targetInfo?.targetId ?? "").trim() || null;
|
|
2468
|
+
if (id !== null) pageTargetIdCache.set(page, id);
|
|
2469
|
+
return id;
|
|
2459
2470
|
} finally {
|
|
2460
2471
|
await session.detach().catch(() => {
|
|
2461
2472
|
});
|
|
@@ -2485,17 +2496,19 @@ async function findPageByTargetIdViaTargetList(pages, targetId, cdpUrl) {
|
|
|
2485
2496
|
}
|
|
2486
2497
|
async function findPageByTargetId(browser, targetId, cdpUrl) {
|
|
2487
2498
|
const pages = getAllPages(browser);
|
|
2488
|
-
|
|
2489
|
-
|
|
2490
|
-
|
|
2491
|
-
|
|
2492
|
-
|
|
2493
|
-
|
|
2494
|
-
|
|
2495
|
-
|
|
2496
|
-
}
|
|
2497
|
-
|
|
2498
|
-
}
|
|
2499
|
+
const results = await Promise.all(
|
|
2500
|
+
pages.map(async (page) => {
|
|
2501
|
+
try {
|
|
2502
|
+
const tid = await pageTargetId(page);
|
|
2503
|
+
return { page, tid };
|
|
2504
|
+
} catch {
|
|
2505
|
+
return { page, tid: null };
|
|
2506
|
+
}
|
|
2507
|
+
})
|
|
2508
|
+
);
|
|
2509
|
+
const resolvedViaCdp = results.some(({ tid }) => tid !== null);
|
|
2510
|
+
const matched = results.find(({ tid }) => tid !== null && tid !== "" && tid === targetId);
|
|
2511
|
+
if (matched) return matched.page;
|
|
2499
2512
|
if (cdpUrl !== void 0 && cdpUrl !== "") {
|
|
2500
2513
|
try {
|
|
2501
2514
|
return await findPageByTargetIdViaTargetList(pages, targetId, cdpUrl);
|
|
@@ -2551,9 +2564,7 @@ async function getPageForTargetId(opts) {
|
|
|
2551
2564
|
);
|
|
2552
2565
|
}
|
|
2553
2566
|
if (isBlockedPageRef(opts.cdpUrl, found)) throw new BlockedBrowserTargetError();
|
|
2554
|
-
|
|
2555
|
-
if (foundTargetId !== null && foundTargetId !== "" && isBlockedTarget(opts.cdpUrl, foundTargetId))
|
|
2556
|
-
throw new BlockedBrowserTargetError();
|
|
2567
|
+
if (isBlockedTarget(opts.cdpUrl, opts.targetId)) throw new BlockedBrowserTargetError();
|
|
2557
2568
|
return found;
|
|
2558
2569
|
}
|
|
2559
2570
|
async function resolvePageByTargetIdOrThrow(opts) {
|
|
@@ -6557,6 +6568,7 @@ var BrowserClaw = class _BrowserClaw {
|
|
|
6557
6568
|
}
|
|
6558
6569
|
};
|
|
6559
6570
|
|
|
6571
|
+
exports.BlockedBrowserTargetError = BlockedBrowserTargetError;
|
|
6560
6572
|
exports.BrowserClaw = BrowserClaw;
|
|
6561
6573
|
exports.BrowserTabNotFoundError = BrowserTabNotFoundError;
|
|
6562
6574
|
exports.CrawlPage = CrawlPage;
|
|
@@ -6587,6 +6599,7 @@ exports.resolveBoundedDelayMs = resolveBoundedDelayMs;
|
|
|
6587
6599
|
exports.resolveInteractionTimeoutMs = resolveInteractionTimeoutMs;
|
|
6588
6600
|
exports.resolvePageByTargetIdOrThrow = resolvePageByTargetIdOrThrow;
|
|
6589
6601
|
exports.resolvePinnedHostnameWithPolicy = resolvePinnedHostnameWithPolicy;
|
|
6602
|
+
exports.resolveStrictExistingPathsWithinRoot = resolveStrictExistingPathsWithinRoot;
|
|
6590
6603
|
exports.resolveStrictExistingUploadPaths = resolveStrictExistingUploadPaths;
|
|
6591
6604
|
exports.sanitizeUntrustedFileName = sanitizeUntrustedFileName;
|
|
6592
6605
|
exports.setDialogHandler = setDialogHandler;
|