chore: lint
This commit is contained in:
@@ -469,11 +469,13 @@ class BeelineBridge:
|
||||
parsed = json.loads(payload)
|
||||
except Exception:
|
||||
parsed = {"_raw": payload}
|
||||
write_log({
|
||||
"type": "viewport_event",
|
||||
"tab_id": tab_id,
|
||||
**parsed,
|
||||
})
|
||||
write_log(
|
||||
{
|
||||
"type": "viewport_event",
|
||||
"tab_id": tab_id,
|
||||
**parsed,
|
||||
}
|
||||
)
|
||||
return
|
||||
|
||||
# Attach-time canary → attach_canary (proves extension
|
||||
@@ -483,11 +485,13 @@ class BeelineBridge:
|
||||
parsed = json.loads(payload)
|
||||
except Exception:
|
||||
parsed = {"_raw": payload}
|
||||
write_log({
|
||||
"type": "attach_canary",
|
||||
"tab_id": tab_id,
|
||||
**parsed,
|
||||
})
|
||||
write_log(
|
||||
{
|
||||
"type": "attach_canary",
|
||||
"tab_id": tab_id,
|
||||
**parsed,
|
||||
}
|
||||
)
|
||||
return
|
||||
|
||||
# Everything else — keep a compact row so we can tell
|
||||
@@ -503,24 +507,28 @@ class BeelineBridge:
|
||||
compact.append(v[:120])
|
||||
elif v is not None:
|
||||
compact.append(str(v)[:120])
|
||||
write_log({
|
||||
"type": "cdp_event",
|
||||
"tab_id": tab_id,
|
||||
"method": method,
|
||||
"level": params.get("type"),
|
||||
"args": compact,
|
||||
})
|
||||
write_log(
|
||||
{
|
||||
"type": "cdp_event",
|
||||
"tab_id": tab_id,
|
||||
"method": method,
|
||||
"level": params.get("type"),
|
||||
"args": compact,
|
||||
}
|
||||
)
|
||||
return
|
||||
|
||||
# Other forwarded events (Page.lifecycleEvent, frameResized,
|
||||
# frameNavigated, Target.targetInfoChanged) are rare and high
|
||||
# signal — keep the full param dict but truncate strings.
|
||||
write_log({
|
||||
"type": "cdp_event",
|
||||
"tab_id": tab_id,
|
||||
"method": method,
|
||||
"params": params,
|
||||
})
|
||||
write_log(
|
||||
{
|
||||
"type": "cdp_event",
|
||||
"tab_id": tab_id,
|
||||
"method": method,
|
||||
"params": params,
|
||||
}
|
||||
)
|
||||
|
||||
# Main-frame navigation wipes the previous document's scripts.
|
||||
# Our [hive_vp] probe's event listeners die with it. Reinstall
|
||||
@@ -541,6 +549,7 @@ class BeelineBridge:
|
||||
if method == "Page.frameResized" and tab_id is not None:
|
||||
try:
|
||||
from .tools.inspection import _viewport_sizes
|
||||
|
||||
_viewport_sizes.pop(tab_id, None)
|
||||
except Exception:
|
||||
pass
|
||||
@@ -550,6 +559,7 @@ class BeelineBridge:
|
||||
current document of ``tab_id``. Called from sync context
|
||||
inside ``_handle_cdp_event``, so we create a task on the
|
||||
running loop. Failures are silent."""
|
||||
|
||||
async def _do() -> None:
|
||||
try:
|
||||
# The new document's global scope doesn't have
|
||||
@@ -566,6 +576,7 @@ class BeelineBridge:
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
try:
|
||||
asyncio.get_event_loop().create_task(_do())
|
||||
except RuntimeError:
|
||||
@@ -868,8 +879,7 @@ class BeelineBridge:
|
||||
{
|
||||
"expression": (
|
||||
"console.info('[hive_attach_canary]', "
|
||||
"JSON.stringify({tabId: "
|
||||
+ str(tab_id) + ", ts: Date.now()}))"
|
||||
"JSON.stringify({tabId: " + str(tab_id) + ", ts: Date.now()}))"
|
||||
),
|
||||
"returnByValue": True,
|
||||
"awaitPromise": False,
|
||||
@@ -1379,9 +1389,7 @@ class BeelineBridge:
|
||||
# `(function(){ return (...)(x,y) })()` and the value
|
||||
# actually comes back — without it the wrapper drops
|
||||
# the result on the floor (returns undefined).
|
||||
probe_result = await self.evaluate(
|
||||
tab_id, f"return ({_HIT_ELEMENT_JS})({x}, {y})"
|
||||
)
|
||||
probe_result = await self.evaluate(tab_id, f"return ({_HIT_ELEMENT_JS})({x}, {y})")
|
||||
hit_probe = (probe_result or {}).get("result")
|
||||
except Exception:
|
||||
hit_probe = None
|
||||
@@ -1410,16 +1418,19 @@ class BeelineBridge:
|
||||
if hit_probe is not None:
|
||||
try:
|
||||
from .telemetry import write_log
|
||||
write_log({
|
||||
"type": "click_hit_probe",
|
||||
"tab_id": tab_id,
|
||||
"intended": {"x": x, "y": y},
|
||||
"viewport": hit_probe.get("viewport"),
|
||||
"hit": hit_probe.get("hit"),
|
||||
"stack": hit_probe.get("stack"),
|
||||
"sweep": hit_probe.get("sweep"),
|
||||
"offsetInRect": hit_probe.get("offsetInRect"),
|
||||
})
|
||||
|
||||
write_log(
|
||||
{
|
||||
"type": "click_hit_probe",
|
||||
"tab_id": tab_id,
|
||||
"intended": {"x": x, "y": y},
|
||||
"viewport": hit_probe.get("viewport"),
|
||||
"hit": hit_probe.get("hit"),
|
||||
"stack": hit_probe.get("stack"),
|
||||
"sweep": hit_probe.get("sweep"),
|
||||
"offsetInRect": hit_probe.get("offsetInRect"),
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
return resp
|
||||
|
||||
@@ -240,23 +240,22 @@ async def _ensure_viewport_size(tab_id: int, _caller: str = "unknown") -> tuple[
|
||||
|
||||
try:
|
||||
from ..telemetry import write_log
|
||||
write_log({
|
||||
"type": "viewport_sample",
|
||||
"tab_id": tab_id,
|
||||
"caller": _caller,
|
||||
"live_w": cw,
|
||||
"live_h": ch,
|
||||
"cached_w": cached_before[0] if cached_before else None,
|
||||
"cached_h": cached_before[1] if cached_before else None,
|
||||
"deltaH_vs_cache": (
|
||||
(ch - cached_before[1])
|
||||
if (cached_before and ch > 0)
|
||||
else None
|
||||
),
|
||||
"returned_w": result_cw,
|
||||
"returned_h": result_ch,
|
||||
"evaluate_error": evaluate_error,
|
||||
})
|
||||
|
||||
write_log(
|
||||
{
|
||||
"type": "viewport_sample",
|
||||
"tab_id": tab_id,
|
||||
"caller": _caller,
|
||||
"live_w": cw,
|
||||
"live_h": ch,
|
||||
"cached_w": cached_before[0] if cached_before else None,
|
||||
"cached_h": cached_before[1] if cached_before else None,
|
||||
"deltaH_vs_cache": ((ch - cached_before[1]) if (cached_before and ch > 0) else None),
|
||||
"returned_w": result_cw,
|
||||
"returned_h": result_ch,
|
||||
"evaluate_error": evaluate_error,
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
@@ -362,31 +361,32 @@ def register_inspection_tools(mcp: FastMCP) -> None:
|
||||
# physical_scale is derived from pngWidth.
|
||||
try:
|
||||
from ..telemetry import write_log
|
||||
|
||||
expected_w = css_width * dpr
|
||||
expected_h = css_height_raw * dpr
|
||||
write_log({
|
||||
"type": "screenshot_geometry",
|
||||
"tab_id": target_tab,
|
||||
"url": screenshot_result.get("url", ""),
|
||||
"pngWidth": png_w,
|
||||
"pngHeight": png_h,
|
||||
"cssWidth": css_width,
|
||||
"cssHeight": css_height_raw,
|
||||
"dpr": dpr,
|
||||
"expectedPngWidth": expected_w,
|
||||
"expectedPngHeight": expected_h,
|
||||
"deltaPngWidthPx": png_w - expected_w,
|
||||
"deltaPngHeightPx": png_h - expected_h,
|
||||
# If the PNG is taller than cssHeight×dpr (e.g. a
|
||||
# devtools-attached banner adds rows above the page
|
||||
# in the capture), clicks land BELOW intended at
|
||||
# the top of the page and converge to 0 error at
|
||||
# the bottom. Reverse signs if PNG is shorter.
|
||||
# Worst-case error in CSS px at fy=0:
|
||||
"yErrorAtTopCssPx": (
|
||||
(png_h - expected_h) / dpr if dpr else 0
|
||||
),
|
||||
})
|
||||
write_log(
|
||||
{
|
||||
"type": "screenshot_geometry",
|
||||
"tab_id": target_tab,
|
||||
"url": screenshot_result.get("url", ""),
|
||||
"pngWidth": png_w,
|
||||
"pngHeight": png_h,
|
||||
"cssWidth": css_width,
|
||||
"cssHeight": css_height_raw,
|
||||
"dpr": dpr,
|
||||
"expectedPngWidth": expected_w,
|
||||
"expectedPngHeight": expected_h,
|
||||
"deltaPngWidthPx": png_w - expected_w,
|
||||
"deltaPngHeightPx": png_h - expected_h,
|
||||
# If the PNG is taller than cssHeight×dpr (e.g. a
|
||||
# devtools-attached banner adds rows above the page
|
||||
# in the capture), clicks land BELOW intended at
|
||||
# the top of the page and converge to 0 error at
|
||||
# the bottom. Reverse signs if PNG is shorter.
|
||||
# Worst-case error in CSS px at fy=0:
|
||||
"yErrorAtTopCssPx": ((png_h - expected_h) / dpr if dpr else 0),
|
||||
}
|
||||
)
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
@@ -64,11 +64,7 @@ async def _build_visual_response(result: dict, bridge, target_tab: int | None) -
|
||||
shot = await bridge.screenshot(target_tab, full_page=False)
|
||||
if not shot.get("ok"):
|
||||
return [text_block]
|
||||
highlights = (
|
||||
[_interaction_highlights[target_tab]]
|
||||
if target_tab in _interaction_highlights
|
||||
else None
|
||||
)
|
||||
highlights = [_interaction_highlights[target_tab]] if target_tab in _interaction_highlights else None
|
||||
data, _ = await asyncio.to_thread(
|
||||
_resize_and_annotate,
|
||||
shot["data"],
|
||||
|
||||
Reference in New Issue
Block a user