browserclaw 0.9.3 → 0.9.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 +61 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +28 -1
- package/dist/index.d.ts +28 -1
- package/dist/index.js +61 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -48,9 +48,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
48
48
|
mod
|
|
49
49
|
));
|
|
50
50
|
|
|
51
|
-
//
|
|
51
|
+
// node_modules/ipaddr.js/lib/ipaddr.js
|
|
52
52
|
var require_ipaddr = __commonJS({
|
|
53
|
-
"
|
|
53
|
+
"node_modules/ipaddr.js/lib/ipaddr.js"(exports$1, module) {
|
|
54
54
|
(function(root) {
|
|
55
55
|
const ipv4Part = "(0?\\d+|0x[a-f0-9]+)";
|
|
56
56
|
const ipv4Regexes = {
|
|
@@ -1388,6 +1388,7 @@ async function launchChrome(opts = {}) {
|
|
|
1388
1388
|
const spawnChrome = () => {
|
|
1389
1389
|
const args = [
|
|
1390
1390
|
`--remote-debugging-port=${String(cdpPort)}`,
|
|
1391
|
+
"--remote-debugging-address=127.0.0.1",
|
|
1391
1392
|
`--user-data-dir=${userDataDir}`,
|
|
1392
1393
|
"--no-first-run",
|
|
1393
1394
|
"--no-default-browser-check",
|
|
@@ -1726,7 +1727,13 @@ function appendCdpPath2(cdpUrl, cdpPath) {
|
|
|
1726
1727
|
}
|
|
1727
1728
|
}
|
|
1728
1729
|
async function withPlaywrightPageCdpSession(page, fn) {
|
|
1729
|
-
const
|
|
1730
|
+
const CDP_SESSION_TIMEOUT_MS = 1e4;
|
|
1731
|
+
const session = await Promise.race([
|
|
1732
|
+
page.context().newCDPSession(page),
|
|
1733
|
+
new Promise(
|
|
1734
|
+
(_, reject) => setTimeout(() => reject(new Error("newCDPSession timed out after 10s")), CDP_SESSION_TIMEOUT_MS)
|
|
1735
|
+
)
|
|
1736
|
+
]);
|
|
1730
1737
|
try {
|
|
1731
1738
|
return await fn(session);
|
|
1732
1739
|
} finally {
|
|
@@ -3078,6 +3085,25 @@ async function mouseClickViaPlaywright(opts) {
|
|
|
3078
3085
|
delay: opts.delayMs
|
|
3079
3086
|
});
|
|
3080
3087
|
}
|
|
3088
|
+
var MAX_HOLD_MS = 3e4;
|
|
3089
|
+
async function pressAndHoldViaCdp(opts) {
|
|
3090
|
+
const holdMs = resolveBoundedDelayMs(opts.holdMs ?? 1e3, "holdMs", MAX_HOLD_MS);
|
|
3091
|
+
const page = await getPageForTargetId({ cdpUrl: opts.cdpUrl, targetId: opts.targetId });
|
|
3092
|
+
ensurePageState(page);
|
|
3093
|
+
const pos = { x: opts.x, y: opts.y };
|
|
3094
|
+
const btn = { button: "left", clickCount: 1 };
|
|
3095
|
+
await withPageScopedCdpClient({
|
|
3096
|
+
cdpUrl: opts.cdpUrl,
|
|
3097
|
+
page,
|
|
3098
|
+
targetId: opts.targetId,
|
|
3099
|
+
fn: async (send) => {
|
|
3100
|
+
await send("Input.dispatchMouseEvent", { type: "mouseMoved", ...pos });
|
|
3101
|
+
await send("Input.dispatchMouseEvent", { type: "mousePressed", ...pos, ...btn });
|
|
3102
|
+
await new Promise((r) => setTimeout(r, holdMs));
|
|
3103
|
+
await send("Input.dispatchMouseEvent", { type: "mouseReleased", ...pos, ...btn });
|
|
3104
|
+
}
|
|
3105
|
+
});
|
|
3106
|
+
}
|
|
3081
3107
|
async function clickByTextViaPlaywright(opts) {
|
|
3082
3108
|
const page = await getRestoredPageForTarget(opts);
|
|
3083
3109
|
const timeout = resolveInteractionTimeoutMs(opts.timeoutMs);
|
|
@@ -3448,7 +3474,12 @@ async function closePageViaPlaywright(opts) {
|
|
|
3448
3474
|
await page.close();
|
|
3449
3475
|
}
|
|
3450
3476
|
async function closePageByTargetIdViaPlaywright(opts) {
|
|
3451
|
-
|
|
3477
|
+
try {
|
|
3478
|
+
await (await resolvePageByTargetIdOrThrow(opts)).close();
|
|
3479
|
+
} catch (err) {
|
|
3480
|
+
if (err instanceof BrowserTabNotFoundError) return;
|
|
3481
|
+
throw err;
|
|
3482
|
+
}
|
|
3452
3483
|
}
|
|
3453
3484
|
async function focusPageByTargetIdViaPlaywright(opts) {
|
|
3454
3485
|
const page = await resolvePageByTargetIdOrThrow(opts);
|
|
@@ -4926,6 +4957,31 @@ var CrawlPage = class {
|
|
|
4926
4957
|
delayMs: opts?.delayMs
|
|
4927
4958
|
});
|
|
4928
4959
|
}
|
|
4960
|
+
/**
|
|
4961
|
+
* Press and hold at page coordinates using raw CDP events.
|
|
4962
|
+
*
|
|
4963
|
+
* Bypasses Playwright's automation layer by dispatching CDP
|
|
4964
|
+
* `Input.dispatchMouseEvent` directly — useful for anti-bot challenges
|
|
4965
|
+
* that detect automated clicks.
|
|
4966
|
+
*
|
|
4967
|
+
* @param x - X coordinate in CSS pixels
|
|
4968
|
+
* @param y - Y coordinate in CSS pixels
|
|
4969
|
+
* @param opts - Options (holdMs: hold duration, default 1000, max 30000)
|
|
4970
|
+
*
|
|
4971
|
+
* @example
|
|
4972
|
+
* ```ts
|
|
4973
|
+
* await page.pressAndHold(400, 300, { holdMs: 5000 });
|
|
4974
|
+
* ```
|
|
4975
|
+
*/
|
|
4976
|
+
async pressAndHold(x, y, opts) {
|
|
4977
|
+
return pressAndHoldViaCdp({
|
|
4978
|
+
cdpUrl: this.cdpUrl,
|
|
4979
|
+
targetId: this.targetId,
|
|
4980
|
+
x,
|
|
4981
|
+
y,
|
|
4982
|
+
holdMs: opts?.holdMs
|
|
4983
|
+
});
|
|
4984
|
+
}
|
|
4929
4985
|
/**
|
|
4930
4986
|
* Click an element by its visible text content (no snapshot/ref needed).
|
|
4931
4987
|
*
|
|
@@ -6087,6 +6143,7 @@ exports.isChromeCdpReady = isChromeCdpReady;
|
|
|
6087
6143
|
exports.isChromeReachable = isChromeReachable;
|
|
6088
6144
|
exports.normalizeCdpHttpBaseForJsonEndpoints = normalizeCdpHttpBaseForJsonEndpoints;
|
|
6089
6145
|
exports.parseRoleRef = parseRoleRef;
|
|
6146
|
+
exports.pressAndHoldViaCdp = pressAndHoldViaCdp;
|
|
6090
6147
|
exports.requireRef = requireRef;
|
|
6091
6148
|
exports.requireRefOrSelector = requireRefOrSelector;
|
|
6092
6149
|
exports.requiresInspectableBrowserNavigationRedirects = requiresInspectableBrowserNavigationRedirects;
|