fix(v2): YouTube no longer stops 45 s in, consent and the bot's video keep their tools
From the live conversation on 0.1.40 (2026-11-18): - The bot browser told pages a program drives it (navigator.webdriver), and YouTube stopped every video about 45 s in with "문제가 발생했습니다" (ump.spsrejectfailure, reproduced twice on the game PC). Chrome now starts with --disable-blink-features=AutomationControlled, as the M0 video check already did; the live Chrome test checks webdriver is false. - "네." to "계산기를 실행해도 될까요?" got webSearch and botBrowser from the router, so the consent call was refused and the calculator never started. Waiting tools: pcControl stays on offer while a request asked in the previous reply waits, botBrowser while it holds the asker's page. - "소리 반으로 줄여 줘" for the bot's video worked on the person's own Edge window. botBrowser gets a volume action (media elements and YouTube's player), the page shows its volume, its description names its actions first (the part the planner sees), pcControl's says the bot's browser is not among its windows, and a turn whose plan has no step while a tool holds something for the asker gets the one-step nudge for it. Evals (qwen3.6 on the game PC): volume 0/3 before, 8/8 after; "네." consent 10/10; pcControl 10/10; botBrowser 16/18 (the NewJeans play case fails 0/6 before this change too). Unit: Python 2542 passed, 13 failed (the same 13 as before); app 348 passed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -18,7 +18,7 @@ from ...debug import debug_log
|
||||
|
||||
FENCE_START = "<<<BEGIN UNTRUSTED WEB PAGE>>>"
|
||||
FENCE_END = "<<<END UNTRUSTED WEB PAGE>>>"
|
||||
_ACTIONS = ("open", "read", "click", "type", "back", "play")
|
||||
_ACTIONS = ("open", "read", "click", "type", "back", "play", "volume")
|
||||
PAGE_WAIT_S = 15.0
|
||||
# play: two pages (the results and the video) and the wait for the video to start.
|
||||
PLAY_WAIT_S = 25.0
|
||||
@@ -39,6 +39,7 @@ const controls = () => [...document.querySelectorAll(
|
||||
const media = () => [...document.querySelectorAll('video,audio')].filter(m => m.currentSrc || m.src)
|
||||
.map(m => ({playing: !m.paused && !m.ended, time: m.currentTime,
|
||||
duration: isFinite(m.duration) ? m.duration : null, muted: m.muted || m.volume === 0,
|
||||
volume: Math.round(m.volume * 100),
|
||||
main: m.tagName === 'VIDEO' && m.getBoundingClientRect().width >= innerWidth * 0.5,
|
||||
failed: !!m.error}));
|
||||
const sameTab = () => {
|
||||
@@ -68,6 +69,13 @@ const a = [...document.querySelectorAll('a[href*="/watch?v="]')].find(e => vis(e
|
||||
&& !e.closest('ytd-ad-slot-renderer,ytd-promoted-video-renderer,ytd-in-feed-ad-layout-renderer,[is-ad]'));
|
||||
if (!a) return null; const u = new URL(a.getAttribute('href'), location.href);
|
||||
return u.origin + u.pathname + '?v=' + encodeURIComponent(u.searchParams.get('v')); })()"""
|
||||
# The sound of the page set to a level (0 to 1): every sound and video, and a player that keeps its
|
||||
# own volume (YouTube's sets it again on its next video) told too; above 0 it is unmuted.
|
||||
_VOLUME = r"""
|
||||
((l) => { const p = document.getElementById('movie_player');
|
||||
if (p && p.setVolume) { p.setVolume(Math.round(l * 100)); if (l > 0 && p.unMute) p.unMute(); }
|
||||
const m = [...document.querySelectorAll('video,audio')].filter(x => x.currentSrc || x.src);
|
||||
m.forEach(x => { x.volume = l; x.muted = l === 0; }); return m.length; })(%s)"""
|
||||
_CLICK = "(() => {" + _HELPERS + r"""
|
||||
return ((t) => { const m = /^\s*\[(\d+)\]\s*$/.exec(t); let el = null;
|
||||
if (m) el = (window.__jvItems || [])[Number(m[1]) - 1];
|
||||
@@ -261,6 +269,12 @@ class BrowserSession:
|
||||
raise BrowserError("no video came up for those words")
|
||||
time.sleep(0.25)
|
||||
|
||||
def volume(self, level: int) -> Dict[str, Any]:
|
||||
if not self._eval(_VOLUME % json.dumps(level / 100)):
|
||||
raise BrowserError("no sound or video on this page")
|
||||
time.sleep(min(0.2, max(0.0, self.deadline - time.monotonic())))
|
||||
return self.read()
|
||||
|
||||
def _press_play(self) -> None:
|
||||
"""On a page just reached whose main player did not start: look again and press play."""
|
||||
try:
|
||||
@@ -295,7 +309,7 @@ MAX_TABS = 5
|
||||
_lock = threading.Lock()
|
||||
# Navigations that are safe to send again on a fresh connection; a click, typing or back may have
|
||||
# taken effect before the connection broke, so they are never repeated.
|
||||
_REPEATABLE = ("open", "read", "play")
|
||||
_REPEATABLE = ("open", "read", "play", "volume")
|
||||
|
||||
|
||||
def _action(raw: Any) -> str:
|
||||
@@ -348,7 +362,8 @@ def _media(page: Dict[str, Any]) -> str:
|
||||
d = m.get("duration")
|
||||
parts.append(("playing" if m.get("playing") else "paused") + " " + _clock(m.get("time"))
|
||||
+ (f" of {_clock(d)}" if isinstance(d, (int, float)) and d > 0 else "")
|
||||
+ (" (muted)" if m.get("muted") else ""))
|
||||
+ (" (muted)" if m.get("muted") else
|
||||
f", volume {m['volume']}%" if isinstance(m.get("volume"), int) else ""))
|
||||
return f"Media: {'; '.join(parts)}\n" if parts else ""
|
||||
|
||||
|
||||
@@ -378,10 +393,12 @@ class BotBrowserTool(Tool):
|
||||
@property
|
||||
def description(self) -> str:
|
||||
return (
|
||||
"Open and use a website in Jarvis's own web browser: search on a site, click, type into "
|
||||
"a box, read the page. "
|
||||
"Jarvis's own browser: action='open' a site, 'read', 'click', 'type', 'play' a video, "
|
||||
"'volume' with level 0-100. "
|
||||
"Actions: open an address, read the current page, click a link or button by its label, "
|
||||
"type into a search box or field (optionally pressing Enter), go back, or play. To play a "
|
||||
"type into a search box or field (optionally pressing Enter), go back, play, or set the "
|
||||
"volume of the sound or video on the page (the page shows its volume now, so for "
|
||||
"\"half\" give half of that). To play a "
|
||||
"song or video, call play once with the words as query, exactly as the user said them and "
|
||||
"in their language (never translated): it searches YouTube, opens the first video and "
|
||||
"starts it, and the page that comes back says whether it truly plays. To search on a "
|
||||
@@ -400,7 +417,7 @@ class BotBrowserTool(Tool):
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"action": {"type": "string", "enum": list(_ACTIONS),
|
||||
"description": "open, read, click, type, back or play"},
|
||||
"description": "open, read, click, type, back, play or volume"},
|
||||
"url": {"type": "string", "description": "for open: the web address"},
|
||||
"query": {"type": "string", "description": "for open: words to search for on that site, as "
|
||||
"plain text (never percent-encoded); they go into the address's empty search "
|
||||
@@ -410,6 +427,7 @@ class BotBrowserTool(Tool):
|
||||
"text": {"type": "string", "description": "for type: what to type"},
|
||||
"field": {"type": "string", "description": "for type: the field's label or placeholder (optional)"},
|
||||
"submit": {"type": "boolean", "description": "for type: press Enter after typing (true to run a search)"},
|
||||
"level": {"type": "number", "description": "for volume: 0 (silent) to 100 (full)"},
|
||||
},
|
||||
"required": ["action"],
|
||||
}
|
||||
@@ -460,6 +478,12 @@ class BotBrowserTool(Tool):
|
||||
call = lambda s: s.type(text, args.get("field") or None, bool(args.get("submit")))
|
||||
elif action == "back":
|
||||
call = lambda s: s.back()
|
||||
elif action == "volume":
|
||||
m = re.search(r"\d+(?:\.\d+)?", str(args.get("level") if args.get("level") is not None else ""))
|
||||
if not m:
|
||||
return _fail("volume needs a level from 0 to 100")
|
||||
level = min(100, round(float(m.group())))
|
||||
call = lambda s: s.volume(level)
|
||||
else:
|
||||
call = lambda s: s.read()
|
||||
who = str(getattr(context, "user_id", "") or "")
|
||||
@@ -492,6 +516,13 @@ class BotBrowserTool(Tool):
|
||||
return ToolExecutionResult(success=True, reply_text=_render(page))
|
||||
|
||||
|
||||
def has_page(who: str) -> bool:
|
||||
"""Whether the bot browser holds a page it opened for this person (the reply engine keeps the
|
||||
tool on offer then, reply.spec.md "Waiting tools"). Read without the lock: an action of
|
||||
another person may hold it for its whole wait."""
|
||||
return bool(who) and who in _sessions
|
||||
|
||||
|
||||
def _keep(who: str, session: Any) -> None:
|
||||
"""Keep a person's session as the most recent; close the oldest beyond MAX_TABS."""
|
||||
_sessions[who] = session
|
||||
|
||||
Reference in New Issue
Block a user