browserpilot-cdp 1.2.1 → 1.2.3

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.js CHANGED
@@ -5,11 +5,12 @@ import os from "node:os";
5
5
  import path from "node:path";
6
6
 
7
7
  // ../protocol/dist/constants.js
8
- var BROWSERPILOT_VERSION = "1.2.1";
8
+ var BROWSERPILOT_VERSION = "1.2.3";
9
9
  var DEFAULT_DAEMON_HOST = "127.0.0.1";
10
10
  var DEFAULT_DAEMON_PORT = 19888;
11
11
  var NATIVE_HOST_NAME = "com.browserpilot.bridge";
12
12
  var NATIVE_MESSAGE_MAX_BYTES = 1024 * 1024;
13
+ var NATIVE_INCOMING_MAX_BYTES = 64 * 1024 * 1024;
13
14
  var DEFAULT_CDP_TIMEOUT_MS = 15e3;
14
15
  var MAX_CONSOLE_BUFFER = 5e3;
15
16
  var MAX_NETWORK_BUFFER = 2e3;
@@ -806,16 +807,19 @@ async function waitForPageLoad(session, options = {}) {
806
807
  await sleep(Math.min(minWaitMs, timeoutMs));
807
808
  }
808
809
  while (Date.now() - start < timeoutMs) {
810
+ let href = "";
809
811
  try {
810
812
  const res = await session.send("Runtime.evaluate", {
811
- expression: "document.readyState",
813
+ expression: "({ readyState: document.readyState, href: location.href })",
812
814
  returnByValue: true
813
815
  });
814
- readyState = res.result?.value ?? "loading";
816
+ readyState = res.result?.value?.readyState ?? "loading";
817
+ href = res.result?.value?.href ?? "";
815
818
  } catch {
816
819
  readyState = "loading";
817
820
  }
818
- if ((readyState === "complete" || readyState === "interactive") && inflight.size === 0) {
821
+ const stillOnBlank = Boolean(options.ignoreAboutBlank) && (!href || href === "about:blank");
822
+ if (!stillOnBlank && (readyState === "complete" || readyState === "interactive") && inflight.size === 0) {
819
823
  if (idleSince === null)
820
824
  idleSince = Date.now();
821
825
  if (Date.now() - idleSince >= idleMs || readyState === "complete") {
@@ -1094,7 +1098,16 @@ function filterSnapshotLines(fullText, search, maxMatches = 25) {
1094
1098
  const allLines = fullText.split("\n");
1095
1099
  const header = allLines[0]?.startsWith("URL:") ? allLines[0] : "";
1096
1100
  const body = header ? allLines.slice(1) : allLines;
1097
- const regex = search instanceof RegExp ? search : new RegExp(escapeRegex(search), "i");
1101
+ let regex;
1102
+ if (search instanceof RegExp) {
1103
+ regex = search;
1104
+ } else {
1105
+ try {
1106
+ regex = new RegExp(search, "i");
1107
+ } catch {
1108
+ regex = new RegExp(escapeRegex(search), "i");
1109
+ }
1110
+ }
1098
1111
  const matchedIndices = /* @__PURE__ */ new Set();
1099
1112
  let count = 0;
1100
1113
  for (let i = 0; i < body.length; i++) {
@@ -2464,6 +2477,7 @@ var ROLE_COLORS = {
2464
2477
  };
2465
2478
  async function captureLabeledScreenshot(page, options = {}) {
2466
2479
  const maxLabels = options.maxLabels ?? 120;
2480
+ await page.session.enableDomain("DOM");
2467
2481
  const snapshot = await page.snapshotEngine.capture(page.session, { showDiffSinceLastCall: false });
2468
2482
  const viewport = await page.evaluate("({ width: window.innerWidth, height: window.innerHeight })");
2469
2483
  const labels = [];
@@ -2993,9 +3007,12 @@ var StylesInspector = class {
2993
3007
  const extractDecls = (props) => {
2994
3008
  if (!props)
2995
3009
  return [];
3010
+ const hasAuthoredRanges = props.some((p) => Boolean(p.range || p.text));
2996
3011
  const out = [];
2997
3012
  for (const p of props) {
2998
- if (p.disabled || !p.name || p.name.startsWith("-webkit-") || !p.value)
3013
+ if (p.disabled || p.implicit || !p.name || p.name.startsWith("-webkit-") || !p.value)
3014
+ continue;
3015
+ if (hasAuthoredRanges && !p.range && !p.text)
2999
3016
  continue;
3000
3017
  const overridden = seenProps.has(p.name);
3001
3018
  seenProps.add(p.name);
@@ -5761,7 +5778,7 @@ async function executeTool(ctx, name, args = {}) {
5761
5778
  });
5762
5779
  if (sessionId) manager.getOrCreateSession(sessionId).activeTabId = tab.tabId;
5763
5780
  if (/^https?:\/\//i.test(targetUrl)) {
5764
- await waitForPageLoad(tab.session, { timeoutMs: 6e3, idleMs: 200 }).catch(() => {
5781
+ await waitForPageLoad(tab.session, { timeoutMs: 1e4, idleMs: 250, ignoreAboutBlank: true }).catch(() => {
5765
5782
  });
5766
5783
  }
5767
5784
  const meta = await tab.page.getUrlAndTitle().catch(() => ({ url: targetUrl, title: "" }));