Lightpanda: the headless browser designed for AI and automation
fix(input): honor mousedown preventDefault and correct mouse-focus rules
Ramiro_quai5e43683a6e09
diff --git a/src/browser/actions.zig b/src/browser/actions.zigindex 19a51d70f..40d66d523 100644--- a/src/browser/actions.zig+++ b/src/browser/actions.zig@@ -46,7 +46,7 @@ fn dispatch(el: *Element, event: *Event, comptime typ: []const u8, frame: *Frame};}-// Dispatches a trusted pointer event and reports whether it was cancelled.+/// Dispatches a trusted pointer event and reports whether it was cancelled.fn dispatchPointer(el: *Element, comptime typ: []const u8, buttons: u16, detail: u32, frame: *Frame) !bool {const event: *PointerEvent = try .initTrusted(typ, .{.bubbles = true,@@ -70,7 +70,7 @@ fn dispatchPointer(el: *Element, comptime typ: []const u8, buttons: u16, detail:return base_event.getDefaultPrevented();}-fn dispatchMouse(el: *Element, comptime typ: []const u8, buttons: u16, frame: *Frame) !void {+fn dispatchMouse(el: *Element, comptime typ: []const u8, buttons: u16, frame: *Frame) !bool {const event: *MouseEvent = try .initTrusted(comptime .wrap(typ), .{.bubbles = true,.cancelable = true,@@ -78,7 +78,13 @@ fn dispatchMouse(el: *Element, comptime typ: []const u8, buttons: u16, frame: *F.buttons = buttons,.detail = 1,}, frame);- try dispatch(el, event.asEvent(), typ, frame);++ const base_event = event.asEvent();+ base_event.acquireRef();+ defer base_event.releaseRef(frame._page);++ try dispatch(el, base_event, typ, frame);+ return base_event.getDefaultPrevented();}/// A full trusted primary-button click sequence, as a real user click would@@ -97,15 +103,17 @@ pub fn click(node: *DOMNode, frame: *Frame) !void {// still fires.const suppress_mouse = try dispatchPointer(el, "pointerdown", 1, 0, frame);if (!suppress_mouse) {- try dispatchMouse(el, "mousedown", 1, frame);- Frame.user_input.focusForMouseDown(frame, el) catch |err| {- lp.log.warn(.app, "click mousedown focus", .{ .err = err });- };+ const suppress_focus = try dispatchMouse(el, "mousedown", 1, frame);+ if (!suppress_focus) {+ Frame.user_input.focusForMouseDown(frame, el) catch |err| {+ lp.log.warn(.app, "click mousedown focus", .{ .err = err });+ };+ }}_ = try dispatchPointer(el, "pointerup", 0, 0, frame);if (!suppress_mouse) {- try dispatchMouse(el, "mouseup", 0, frame);+ _ = try dispatchMouse(el, "mouseup", 0, frame);}_ = try dispatchPointer(el, "click", 0, 1, frame);diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zigindex 2bffc7347..6a3121b5f 100644--- a/src/browser/frame/user_input.zig+++ b/src/browser/frame/user_input.zig@@ -180,10 +180,11 @@ fn dispatchBoundaryEvent(frame: *Frame, target: *Element, comptime mouse_typ: []};}-// Dispatch a single trusted mouse event of the given type on `target`, carrying-// the pressed button and pointer position. `detail` is the click count (used for-// click/dblclick); 0 for events where it does not apply.-fn dispatchMouseEventOn(frame: *Frame, target: *Element, comptime typ: []const u8, x: f64, y: f64, button: i32, detail: u32) !void {+/// Dispatch a single trusted mouse event of the given type on `target`, carrying+/// the pressed button and pointer position. `detail` is the click count (used for+/// click/dblclick); 0 for events where it does not apply. Reports whether the+/// event was cancelled via preventDefault().+fn dispatchMouseEventOn(frame: *Frame, target: *Element, comptime typ: []const u8, x: f64, y: f64, button: i32, detail: u32) !bool {const event: *MouseEvent = try .initTrusted(comptime .wrap(typ), .{.bubbles = true,.cancelable = true,@@ -193,7 +194,13 @@ fn dispatchMouseEventOn(frame: *Frame, target: *Element, comptime typ: []const u.button = button,.detail = detail,}, frame);- try frame._event_manager.dispatch(target.asEventTarget(), event.asEvent());++ const base_event = event.asEvent();+ base_event.acquireRef();+ defer base_event.releaseRef(frame._page);++ try frame._event_manager.dispatch(target.asEventTarget(), base_event);+ return base_event.getDefaultPrevented();}pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32) !void {@@ -208,8 +215,10 @@ pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32) !void {.type = frame._type,});}- try dispatchMouseEventOn(frame, target, "mousedown", x, y, button, 0);- try focusForMouseDown(frame, target);+ const suppressed = try dispatchMouseEventOn(frame, target, "mousedown", x, y, button, 0);+ if (!suppressed) {+ try focusForMouseDown(frame, target);+ }}pub fn triggerMouseMove(frame: *Frame, x: f64, y: f64) !void {@@ -251,19 +260,19 @@ pub fn triggerMouseRelease(frame: *Frame, x: f64, y: f64, button: i32, click_couconst detail: u32 = if (click_count > 0) @intCast(click_count) else 1;- try dispatchMouseEventOn(frame, target, "mouseup", x, y, button, detail);+ _ = try dispatchMouseEventOn(frame, target, "mouseup", x, y, button, detail);// After mouseup, the activation event depends on the button.switch (button) {mouse_button.main => {- try dispatchMouseEventOn(frame, target, "click", x, y, button, detail);+ _ = try dispatchMouseEventOn(frame, target, "click", x, y, button, detail);// A second click in quick succession also fires dblclick.if (click_count == 2) {- try dispatchMouseEventOn(frame, target, "dblclick", x, y, button, detail);+ _ = try dispatchMouseEventOn(frame, target, "dblclick", x, y, button, detail);}},- mouse_button.auxiliary => try dispatchMouseEventOn(frame, target, "auxclick", x, y, button, detail),- mouse_button.secondary => try dispatchMouseEventOn(frame, target, "contextmenu", x, y, button, detail),+ mouse_button.auxiliary => _ = try dispatchMouseEventOn(frame, target, "auxclick", x, y, button, detail),+ mouse_button.secondary => _ = try dispatchMouseEventOn(frame, target, "contextmenu", x, y, button, detail),else => {},}}@@ -353,8 +362,8 @@ fn isEditingHost(node: *Node) bool {return std.ascii.eqlIgnoreCase(value, "false") == false;}-// Find the outermost element of the contiguous editable chain containing the-// target.+/// Find the outermost element of the contiguous editable chain containing the+/// target.fn outermostEditingHost(target: *Element) ?*Element {var node: ?*Node = target.asNode();var editable: ?*Node = null;@@ -374,31 +383,42 @@ fn outermostEditingHost(target: *Element) ?*Element {return host.is(Element);}-/// `null` means the element is not mouse-focusable. Unlike sequential focus,-/// any explicit tabindex value, including a negative one, is mouse-focusable.-fn mouseFocusTabIndex(el: *Element) ?i32 {- if (el.isDisabled()) return null;- if (el.is(Element.Html) == null) return null;+/// Unlike sequential focus, any explicit, parseable tabindex value, including+/// a negative one, is mouse-focusable — on any element, not just HTML ones, so+/// this is checked before the HTML-only guard below. An unparsable tabindex is+/// treated as if the attribute were absent (HTML §6.6.3), so native+/// focusability still applies — mirrors HtmlElement.getTabIndex's+/// parse-failure fallthrough.+fn isMouseFocusable(el: *Element) bool {+ if (el.isDisabled()) return false;if (el.getAttributeSafe(comptime .wrap("tabindex"))) |attr| {- return Element.Html.parseInteger(attr) orelse 0;+ if (Element.Html.parseInteger(attr)) |_| {+ return true;+ }+ }++ if (el.is(Element.Html) == null) {+ // Mirrors hasClickActivationBehavior: an SVG link is focusable by the+ // same href it activates on.+ if (el.is(Element.Svg.Graphics.A) != null) {+ return svgAnchorHref(el) != null;+ }+ return false;}- const native = switch (el.getTag()) {+ return switch (el.getTag()) {.button, .select, .textarea, .iframe => true,.input => el.as(Element.Html.Input)._input_type != .hidden,.anchor, .area => el.getAttributeSafe(comptime .wrap("href")) != null,else => false,};- return if (native) 0 else null;-}--fn isMouseFocusable(el: *Element) bool {- return mouseFocusTabIndex(el) != null;}/// Mousedown default action: focus the editing host if the click is inside-/// one, otherwise the nearest mouse-focusable element (self or ancestor).+/// one, otherwise the nearest mouse-focusable element (self or ancestor). If+/// no ancestor is mouse-focusable, blur whatever was previously focused —+/// a mousedown outside any focusable element moves focus to the body.pub fn focusForMouseDown(frame: *Frame, target: *Element) !void {if (outermostEditingHost(target)) |host| {try host.focus(frame);@@ -413,6 +433,11 @@ pub fn focusForMouseDown(frame: *Frame, target: *Element) !void {return;}}++ const doc = target.asNode().ownerDocument(frame) orelse frame.document;+ if (doc._active_element) |active| {+ try active.blur(frame);+ }}// Per the DOM dispatch algorithm, a click's activation target is the eventdiff --git a/src/browser/tests/mcp_actions.html b/src/browser/tests/mcp_actions.htmlindex 377d39395..2bab8999f 100644--- a/src/browser/tests/mcp_actions.html+++ b/src/browser/tests/mcp_actions.html@@ -22,7 +22,7 @@<button id="btnPreventDefault">Prevent Default</button><button id="btnDisabled" disabled>Disabled</button><div id="focusTarget" tabindex="0" onclick="window.focusTargetFocused = document.activeElement === this;">Focus me</div>- <div id="plain" onclick="window.focusAfterPlain = document.activeElement.id;">Not focusable</div>+ <div id="plain" onclick="window.plainBlurred = document.activeElement === document.body;">Not focusable</div><script>window.seq = [];const btn = document.getElementById('btn');@@ -39,8 +39,11 @@btnPreventDefault.addEventListener(t, function(e) { window.seqPrevented.push(e.type); });}- window.disabledMousedowned = false;- document.getElementById('btnDisabled').addEventListener('mousedown', function() { window.disabledMousedowned = true; });+ window.disabledEvents = [];+ const btnDisabled = document.getElementById('btnDisabled');+ for (const t of ['pointerdown', 'mousedown', 'pointerup', 'mouseup', 'click']) {+ btnDisabled.addEventListener(t, function(e) { window.disabledEvents.push(e.type); });+ }document.getElementById('chk').addEventListener('click', function() { window.chkClicked = true; });document.getElementById('chk').addEventListener('change', function() { window.chkChanged = true; });diff --git a/src/browser/webapi/WebDriver.zig b/src/browser/webapi/WebDriver.zigindex 6ddcb3aed..5f7d2ae3e 100644--- a/src/browser/webapi/WebDriver.zig+++ b/src/browser/webapi/WebDriver.zig@@ -74,10 +74,10 @@ pub fn click(_: *const WebDriver, element: *Element, frame: *Frame) !void {}dispatchPointer(element, "pointerdown", 0, 1, frame);- dispatchMouse(element, "mousedown", 0, 1, 1, frame);+ _ = dispatchMouse(element, "mousedown", 0, 1, 1, frame);dispatchPointer(element, "pointerup", 0, 0, frame);- dispatchMouse(element, "mouseup", 0, 0, 1, frame);- dispatchMouse(element, "click", 0, 0, 1, frame);+ _ = dispatchMouse(element, "mouseup", 0, 0, 1, frame);+ _ = dispatchMouse(element, "click", 0, 0, 1, frame);}const WebDriverCookie = struct {@@ -281,7 +281,7 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {.with_pointer = true,});dispatchPointer(el, "pointermove", 0, pressed_mask, frame);- dispatchMouse(el, "mousemove", 0, pressed_mask, 0, frame);+ _ = dispatchMouse(el, "mousemove", 0, pressed_mask, 0, frame);}} else if (action_type.eql(comptime .wrap("pointerDown"))) {const el = target orelse continue;@@ -298,10 +298,12 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {if (is_touch) {dispatchTouch(el, "touchstart", frame);} else {- dispatchMouse(el, "mousedown", button, buttonsMask(button), click_count, frame);- Frame.user_input.focusForMouseDown(frame, el) catch |err| {- log.warn(.app, "webdriver mousedown focus", .{ .err = err });- };+ const suppressed = dispatchMouse(el, "mousedown", button, buttonsMask(button), click_count, frame);+ if (!suppressed) {+ Frame.user_input.focusForMouseDown(frame, el) catch |err| {+ log.warn(.app, "webdriver mousedown focus", .{ .err = err });+ };+ }}} else if (action_type.eql(comptime .wrap("pointerUp"))) {const el = target orelse continue;@@ -312,20 +314,20 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {if (is_touch) {dispatchTouch(el, "touchend", frame);} else {- dispatchMouse(el, "mouseup", button, 0, click_count, frame);+ _ = dispatchMouse(el, "mouseup", button, 0, click_count, frame);const click_target = commonClickTarget(down_target orelse el, el);last_click_button = button;last_click_target = click_target;if (button == 0) {- dispatchMouse(click_target, "click", button, 0, click_count, frame);+ _ = dispatchMouse(click_target, "click", button, 0, click_count, frame);if (click_count % 2 == 0) {- dispatchMouse(click_target, "dblclick", button, 0, click_count, frame);+ _ = dispatchMouse(click_target, "dblclick", button, 0, click_count, frame);}} else {if (button == 2) {- dispatchMouse(click_target, "contextmenu", button, 0, click_count, frame);+ _ = dispatchMouse(click_target, "contextmenu", button, 0, click_count, frame);}- dispatchMouse(click_target, "auxclick", button, 0, click_count, frame);+ _ = dispatchMouse(click_target, "auxclick", button, 0, click_count, frame);}}down_target = null;@@ -566,7 +568,7 @@ fn dispatchPointer(el: *Element, comptime typ: []const u8, button: i32, buttons:dispatch(el.asEventTarget(), event.asEvent(), frame, typ);}-fn dispatchMouse(el: *Element, comptime typ: []const u8, button: i32, buttons: u16, detail: u32, frame: *Frame) void {+fn dispatchMouse(el: *Element, comptime typ: []const u8, button: i32, buttons: u16, detail: u32, frame: *Frame) bool {const modifiers = frame._page.input_modifiers;const event = MouseEvent.initTrusted(comptime .wrap(typ), .{.bubbles = true,@@ -581,9 +583,14 @@ fn dispatchMouse(el: *Element, comptime typ: []const u8, button: i32, buttons: u.metaKey = modifiers.meta,}, frame) catch |err| {log.warn(.app, "webdriver mouse event", .{ .err = err, .type = typ });- return;+ return false;};- dispatch(el.asEventTarget(), event.asEvent(), frame, typ);+ const base_event = event.asEvent();+ base_event.acquireRef();+ defer base_event.releaseRef(frame._page);++ dispatch(el.asEventTarget(), base_event, frame, typ);+ return base_event.getDefaultPrevented();}fn dispatchWheel(el: *Element, delta_x: i32, delta_y: i32, frame: *Frame) void {diff --git a/src/mcp/tools.zig b/src/mcp/tools.zigindex 1aea5a621..4ad8c7577 100644--- a/src/mcp/tools.zig+++ b/src/mcp/tools.zig@@ -1206,8 +1206,8 @@ test "MCP - Actions: click, fill, scroll, hover, press, selectOption, setChecked\\ 'pointerup:0:0:mouse:true', 'mouseup:0:0::true', 'click:0:0:mouse:true'\\ ]) &&\\ JSON.stringify(window.seqPrevented) === JSON.stringify(['pointerdown', 'pointerup', 'click']) &&- \\ window.disabledMousedowned === false &&- \\ window.focusTargetFocused === true && window.focusAfterPlain === 'focusTarget' &&+ \\ JSON.stringify(window.disabledEvents) === '[]' &&+ \\ window.focusTargetFocused === true && window.plainBlurred === true &&\\ window.clicked === true && window.inputVal === 'hello' &&\\ window.changed === true && window.selChanged === 'opt2' &&\\ window.scrolled === true &&diff --git a/src/script/Runtime.zig b/src/script/Runtime.zigindex eb91419fe..1836179ea 100644--- a/src/script/Runtime.zig+++ b/src/script/Runtime.zig@@ -1441,7 +1441,13 @@ test "agent script runtime: tool errors throw and stop execution" {);}-test "agent script runtime: selector click preserves pointer mouse semantics" {+// Complements the fixture-driven MCP test in tools.zig: here the nodes are+// created at runtime. Covers the ancestor walk, blur-to-body on a non-focusable+// node, tabindex=-1 still mouse-focusable, an unparsable tabindex on a plain div+// not focusable but on a button falling through to native focusability,+// preventDefault() on mousedown preserving focus, editing hosts winning over+// their contents, and an explicit tabindex on a non-HTML (SVG) element.+test "agent script runtime: mousedown focus follows mouse-focusability rules" {defer testing.test_session.closeAllPages();var registry = CDPNode.Registry.init(testing.allocator);@@ -1453,41 +1459,44 @@ test "agent script runtime: selector click preserves pointer mouse semantics" {try runTestScript(runtime,\\const page = new Page();\\await page.goto("http://localhost:9582/src/browser/tests/mcp_actions.html");- \\page.click("#btn");- \\const full = page.evaluate("JSON.stringify(window.seq)");- \\if (full !== '["pointerdown:0:1:mouse:true","mousedown:0:1::true","pointerup:0:0:mouse:true","mouseup:0:0::true","click:0:0:mouse:true"]') throw new Error("wrong full click sequence: " + full);- \\page.click("#btnPreventDefault");- \\const suppressed = page.evaluate("JSON.stringify(window.seqPrevented)");- \\if (suppressed !== '["pointerdown","pointerup","click"]') throw new Error("wrong suppressed sequence: " + suppressed);- \\page.click("#btnDisabled");- \\if (page.evaluate("String(window.disabledMousedowned)") !== "false") throw new Error("disabled button received mousedown");- \\page.click("#focusTarget");- \\if (page.evaluate("document.activeElement.id") !== "focusTarget") throw new Error("mousedown focus default action was lost");- );-}--// Different workflow from the fixture above: the tabindex node is created at-// runtime, the click lands on a child (ancestor walk), a following click on a-// non-focusable node must not steal focus, and tabindex=-1 is still mouse-focusable.-test "agent script runtime: dynamic tabindex child click focuses ancestor" {- defer testing.test_session.closeAllPages();-- var registry = CDPNode.Registry.init(testing.allocator);- defer registry.deinit();-- const runtime = try Runtime.init(testing.allocator, testing.test_app, testing.test_session, ®istry);- defer runtime.deinit();-- try runTestScript(runtime,- \\const page = new Page();- \\await page.goto("http://localhost:9582/src/browser/tests/mcp_actions.html");- \\page.evaluate("const p=document.createElement('div');p.id='dynFocus';p.setAttribute('tabindex','0');const s=document.createElement('span');s.id='dynChild';s.textContent='x';p.appendChild(s);document.body.appendChild(p);const n=document.createElement('div');n.id='dynNeg';n.setAttribute('tabindex','-1');n.textContent='neg';document.body.appendChild(n)");+ \\page.evaluate("const p=document.createElement('div');p.id='dynFocus';p.setAttribute('tabindex','0');const s=document.createElement('span');s.id='dynChild';s.textContent='x';p.appendChild(s);document.body.appendChild(p);const n=document.createElement('div');n.id='dynNeg';n.setAttribute('tabindex','-1');n.textContent='neg';document.body.appendChild(n);const b=document.createElement('div');b.id='dynBad';b.setAttribute('tabindex','abc');b.textContent='bad';document.body.appendChild(b);const btn=document.createElement('button');btn.id='dynBadBtn';btn.setAttribute('tabindex','abc');btn.textContent='badbtn';btn.addEventListener('mouseup',function(){window.badBtnFocusAtMouseup=document.activeElement.id;});document.body.appendChild(btn)");\\page.click("#dynChild");\\if (page.evaluate("document.activeElement.id") !== "dynFocus") throw new Error("child click did not focus tabindex ancestor: " + page.evaluate("document.activeElement && document.activeElement.id"));\\page.click("#plain");- \\if (page.evaluate("document.activeElement.id") !== "dynFocus") throw new Error("plain click stole focus: " + page.evaluate("document.activeElement && document.activeElement.id"));+ \\if (page.evaluate("String(document.activeElement === document.body)") !== "true") throw new Error("plain click did not blur to body: " + page.evaluate("document.activeElement && document.activeElement.id"));\\page.click("#dynNeg");\\if (page.evaluate("document.activeElement.id") !== "dynNeg") throw new Error("tabindex=-1 was not mouse-focusable: " + page.evaluate("document.activeElement && document.activeElement.id"));+ \\page.click("#dynBad");+ \\if (page.evaluate("String(document.activeElement === document.body)") !== "true") throw new Error("unparsable tabindex was mouse-focusable: " + page.evaluate("document.activeElement && document.activeElement.id"));+ \\page.click("#dynBadBtn");+ \\// Sampled at mouseup, not after the click: a button's click activation+ \\// behavior focuses it unconditionally, which would mask what mousedown did.+ \\if (page.evaluate("window.badBtnFocusAtMouseup") !== "dynBadBtn") throw new Error("unparsable tabindex on a native button lost native mousedown focusability: " + page.evaluate("String(window.badBtnFocusAtMouseup)"));+ \\// Toolbar idiom: preventDefault() on mousedown preserves existing focus+ \\page.evaluate("const t=document.createElement('div');t.id='toolbarBtn';t.addEventListener('mousedown',function(e){e.preventDefault();});document.body.appendChild(t)");+ \\page.click("#inp");+ \\if (page.evaluate("document.activeElement.id") !== "inp") throw new Error("setup failed: activeElement not inp");+ \\page.click("#toolbarBtn");+ \\if (page.evaluate("document.activeElement.id") !== "inp") throw new Error("preventDefault on mousedown did not protect focus (toolbar idiom): " + page.evaluate("document.activeElement && document.activeElement.id"));+ \\// Editing hosts: the click focuses the host, not what is inside it.+ \\// Verified against Chrome 152 with trusted CDP input: a plain span, a+ \\// button, a [tabindex] div and an <a href> inside a contenteditable all+ \\// leave focus on the host, and a nested host resolves to the OUTER one.+ \\page.evaluate("const h=document.createElement('div');h.id='dynHost';h.setAttribute('contenteditable','true');const hs=document.createElement('span');hs.id='dynHostSpan';hs.textContent='hs';h.appendChild(hs);document.body.appendChild(h)");+ \\page.click("#dynHostSpan");+ \\if (page.evaluate("document.activeElement.id") !== "dynHost") throw new Error("span inside contenteditable did not focus host: " + page.evaluate("document.activeElement && document.activeElement.id"));+ \\// Nested contenteditable: the OUTER host wins, not the inner one.+ \\page.evaluate("const out=document.createElement('div');out.id='dynOuter';out.setAttribute('contenteditable','true');const inn=document.createElement('div');inn.id='dynInner';inn.setAttribute('contenteditable','true');const is=document.createElement('span');is.id='dynInnerSpan';is.textContent='is';inn.appendChild(is);out.appendChild(inn);document.body.appendChild(out)");+ \\page.click("#dynInnerSpan");+ \\if (page.evaluate("document.activeElement.id") !== "dynOuter") throw new Error("nested contenteditable did not focus the outer host: " + page.evaluate("document.activeElement && document.activeElement.id"));+ \\// An explicit tabindex is focusable on a non-HTML element too: the+ \\// HTML-only guard must not shadow it, or the new blur fallback would+ \\// drop focus to body on a click Chrome focuses.+ \\page.evaluate("const svg=document.createElementNS('http://www.w3.org/2000/svg','svg');const r=document.createElementNS('http://www.w3.org/2000/svg','rect');r.id='dynSvgRect';r.setAttribute('tabindex','0');r.setAttribute('width','100');r.setAttribute('height','40');svg.appendChild(r);document.body.appendChild(svg)");+ \\page.click("#inp");+ \\if (page.evaluate("document.activeElement.id") !== "inp") throw new Error("setup failed: activeElement not inp");+ \\page.click("#dynSvgRect");+ \\if (page.evaluate("document.activeElement.id") !== "dynSvgRect") throw new Error("svg [tabindex] click did not focus the svg element: " + page.evaluate("document.activeElement && document.activeElement.id")););}