Lightpanda: the headless browser designed for AI and automation
click: share press and release sequences and enable pointer events
Adrià Arrufatc50f72314eb0
diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zigindex e56bd0027..4b379dcfd 100644--- a/src/browser/frame/user_input.zig+++ b/src/browser/frame/user_input.zig@@ -180,58 +180,79 @@ fn dispatchBoundaryEvent(frame: *Frame, target: *Element, comptime mouse_typ: []};}-/// Event fields for the trusted mouse/pointer dispatchers, bundled so `button`-/// (which button changed) and `buttons` (the held mask) can't be transposed.-const PointerInput = struct {- x: f64,- y: f64,+pub const Gesture = struct {button: i32 = mouse_button.main,- buttons: u16 = 0,- detail: u32 = 0,+ buttons_down: u16 = 1,+ click_count: u32 = 1,+ coords: ?struct { x: f64, y: f64 } = null,modifiers: Modifiers = .{},+ emit_pointer_events: bool = true,+ emit_mouse_compat: bool = true,+ pressure: f32 = 0.5,+ update_hover: bool = false,+ focus_error: enum { warn, propagate } = .warn,};-/// Dispatch a trusted mouse event; returns whether preventDefault() cancelled it.-fn dispatchMouseEventOn(frame: *Frame, target: *Element, comptime typ: []const u8, in: PointerInput) !bool {- const event: *MouseEvent = try .initTrusted(comptime .wrap(typ), .{+/// Dispatch a trusted pointer event; returns whether preventDefault() cancelled it.+pub fn emitPointer(+ frame: *Frame,+ target: *Element,+ typ: []const u8,+ g: Gesture,+ detail: u32,+ buttons: u16,+) !bool {+ const owner = target.ownerFrame(frame) orelse frame;+ const x = if (g.coords) |c| c.x else 0;+ const y = if (g.coords) |c| c.y else 0;+ const event: *PointerEvent = try .initTrusted(typ, .{.bubbles = true,.cancelable = true,.composed = true,- .clientX = in.x,- .clientY = in.y,- .button = in.button,- .buttons = in.buttons,- .detail = in.detail,- .ctrlKey = in.modifiers.ctrl,- .shiftKey = in.modifiers.shift,- .altKey = in.modifiers.alt,- .metaKey = in.modifiers.meta,- }, frame);- return frame._event_manager.dispatchCancelable(target.asEventTarget(), event.asEvent());+ .clientX = x,+ .clientY = y,+ .button = g.button,+ .buttons = buttons,+ .detail = detail,+ .pointerId = 1,+ .pointerType = "mouse",+ .isPrimary = true,+ .pressure = if (buttons != 0) g.pressure else 0.0,+ .ctrlKey = g.modifiers.ctrl,+ .shiftKey = g.modifiers.shift,+ .altKey = g.modifiers.alt,+ .metaKey = g.modifiers.meta,+ }, owner);+ return owner._event_manager.dispatchCancelable(target.asEventTarget(), event.asEvent());}-/// Dispatch a trusted pointer event (always mouse-sourced: pointerType,-/// pointerId, isPrimary fixed); returns whether preventDefault() cancelled it.-fn dispatchPointerEventOn(frame: *Frame, target: *Element, comptime typ: []const u8, in: PointerInput) !bool {- const event: *PointerEvent = try .initTrusted(typ, .{+/// Dispatch a trusted mouse event; returns whether preventDefault() cancelled it.+pub fn emitMouse(+ frame: *Frame,+ target: *Element,+ comptime typ: []const u8,+ g: Gesture,+ detail: u32,+ buttons: u16,+) !bool {+ const owner = target.ownerFrame(frame) orelse frame;+ const x = if (g.coords) |c| c.x else 0;+ const y = if (g.coords) |c| c.y else 0;+ const event: *MouseEvent = try .initTrusted(comptime .wrap(typ), .{.bubbles = true,.cancelable = true,.composed = true,- .clientX = in.x,- .clientY = in.y,- .button = in.button,- .buttons = in.buttons,- .detail = in.detail,- .pointerId = 1,- .pointerType = "mouse",- .isPrimary = true,- .pressure = if (in.buttons != 0) 0.5 else 0.0,- .ctrlKey = in.modifiers.ctrl,- .shiftKey = in.modifiers.shift,- .altKey = in.modifiers.alt,- .metaKey = in.modifiers.meta,- }, frame);- return frame._event_manager.dispatchCancelable(target.asEventTarget(), event.asEvent());+ .clientX = x,+ .clientY = y,+ .button = g.button,+ .buttons = buttons,+ .detail = detail,+ .ctrlKey = g.modifiers.ctrl,+ .shiftKey = g.modifiers.shift,+ .altKey = g.modifiers.alt,+ .metaKey = g.modifiers.meta,+ }, owner);+ return owner._event_manager.dispatchCancelable(target.asEventTarget(), event.asEvent());}/// MouseEvent/PointerEvent.buttons bitmask for a MouseEvent.button value.@@ -256,6 +277,9 @@ pub const PointerButtons = struct {/// Whether the gesture's opening pointerdown suppressed the compat mouse/// events; held for the whole gesture so each split message reads it here.mousedown_suppressed: bool = false,+ /// Where the last pointerdown landed: the click fires at the nearest+ /// common inclusive ancestor of down and up targets when they differ.+ down_target: ?*Element = null,/// `starts_gesture` is false for a chorded press (another button held).pub fn press(self: *PointerButtons, button: i32) struct { starts_gesture: bool, held: u16 } {@@ -271,7 +295,10 @@ pub const PointerButtons = struct {const was_suppressed = self.mousedown_suppressed;self.held &= ~buttonsBitmask(button);const ends_gesture = self.held == 0;- if (ends_gesture) self.mousedown_suppressed = false;+ if (ends_gesture) {+ self.mousedown_suppressed = false;+ self.down_target = null;+ }return .{ .ends_gesture = ends_gesture, .held = self.held, .was_suppressed = was_suppressed };}@@ -281,36 +308,123 @@ pub const PointerButtons = struct {}};-const PressResult = struct {- /// pointerdown's preventDefault() suppressed the compat mousedown here and- /// the paired mouseup on release.- suppress_mouse: bool,- /// mousedown's focus default action is suppressed (always when- /// suppress_mouse is).- suppress_focus: bool,-};+/// A click whose mousedown and mouseup landed on different elements fires at+/// their nearest common inclusive ancestor element.+pub fn commonClickTarget(down: *Element, up: *Element) *Element {+ if (down == up) {+ return up;+ }+ var current: ?*Node = down.asNode();+ while (current) |node| : (current = node.parentNode()) {+ if (node.contains(up.asNode())) {+ return node.is(Element) orelse break;+ }+ }+ return up;+}++pub fn pressSequence(+ frame: *Frame,+ target: *Element,+ g: Gesture,+ suppressed_out: *bool,+) !void {+ if (target.isDisabled()) {+ suppressed_out.* = true;+ return;+ }-/// pointerdown, then mousedown unless pointerdown was cancelled. `in.detail`-/// applies to mousedown only.-fn dispatchPointerPress(frame: *Frame, target: *Element, in: PointerInput) !PressResult {- var pointer = in;- pointer.detail = 0;- const suppress_mouse = try dispatchPointerEventOn(frame, target, "pointerdown", pointer);- if (suppress_mouse) {- return .{ .suppress_mouse = true, .suppress_focus = true };- }- const suppress_focus = try dispatchMouseEventOn(frame, target, "mousedown", in);- return .{ .suppress_mouse = false, .suppress_focus = suppress_focus };+ if (g.update_hover) {+ updateHoverTarget(frame, target, .{+ .x = if (g.coords) |c| c.x else 0,+ .y = if (g.coords) |c| c.y else 0,+ .buttons = g.buttons_down,+ .modifiers = g.modifiers,+ .with_pointer = true,+ });+ }++ const bit = buttonsBitmask(g.button);+ const starts_gesture = (g.buttons_down & ~bit) == 0;++ var pointer_suppressed = if (starts_gesture) false else suppressed_out.*;+ if (g.emit_pointer_events) {+ if (starts_gesture) {+ pointer_suppressed = try emitPointer(frame, target, "pointerdown", g, 0, g.buttons_down);+ } else {+ _ = try emitPointer(frame, target, "pointermove", g, 0, g.buttons_down);+ }+ }++ suppressed_out.* = pointer_suppressed;+ if (pointer_suppressed) {+ return;+ }++ if (g.emit_mouse_compat) {+ const mouse_suppressed = try emitMouse(frame, target, "mousedown", g, g.click_count, g.buttons_down);+ if (!mouse_suppressed) {+ focusForMouseDown(frame, target) catch |err| switch (g.focus_error) {+ .warn => log.debug(.app, "mousedown focus", .{ .err = err }),+ .propagate => return err,+ };+ }+ }}-/// pointerup, then mouseup unless the gesture's pointerdown was cancelled.-/// `in.detail` applies to mouseup only.-fn dispatchPointerRelease(frame: *Frame, target: *Element, in: PointerInput, suppress_mouse: bool) !void {- var pointer = in;- pointer.detail = 0;- _ = try dispatchPointerEventOn(frame, target, "pointerup", pointer);- if (suppress_mouse == false) {- _ = try dispatchMouseEventOn(frame, target, "mouseup", in);+pub fn releaseSequence(+ frame: *Frame,+ up_target: *Element,+ g: Gesture,+ suppressed: bool,+ click_target: ?*Element,+) !void {+ if (up_target.isDisabled()) {+ return;+ }++ const ends_gesture = (g.buttons_down == 0);++ if (ends_gesture) {+ if (g.emit_pointer_events) {+ _ = try emitPointer(frame, up_target, "pointerup", g, 0, g.buttons_down);+ }+ if (g.emit_mouse_compat and !suppressed) {+ const detail = if (g.click_count > 0) g.click_count else 1;+ _ = try emitMouse(frame, up_target, "mouseup", g, detail, g.buttons_down);+ }+ } else {+ if (g.emit_pointer_events) {+ _ = try emitPointer(frame, up_target, "pointermove", g, 0, g.buttons_down);+ }+ if (g.emit_mouse_compat and !suppressed) {+ const detail = if (g.click_count > 0) g.click_count else 1;+ _ = try emitMouse(frame, up_target, "mouseup", g, detail, g.buttons_down);+ }+ }++ const click_el = click_target orelse up_target;+ if (click_el.isDisabled()) {+ return;+ }++ if (g.emit_mouse_compat) {+ const detail = if (g.click_count > 0) g.click_count else 1;+ switch (g.button) {+ mouse_button.main => {+ _ = try emitPointer(frame, click_el, "click", g, detail, g.buttons_down);+ if (detail % 2 == 0 and detail > 0) {+ _ = try emitMouse(frame, click_el, "dblclick", g, detail, g.buttons_down);+ }+ },+ mouse_button.auxiliary => {+ _ = try emitMouse(frame, click_el, "auxclick", g, detail, g.buttons_down);+ },+ mouse_button.secondary => {+ _ = try emitMouse(frame, click_el, "contextmenu", g, detail, g.buttons_down);+ },+ else => {},+ }}}@@ -318,15 +432,22 @@ fn dispatchPointerRelease(frame: *Frame, target: *Element, in: PointerInput, sup/// off pointerdown/mousedown, not click alone. A focus failure is logged, not/// returned.pub fn triggerClick(frame: *Frame, target: *Element, modifiers: Modifiers) !void {- const press = try dispatchPointerPress(frame, target, .{ .x = 0, .y = 0, .buttons = 1, .detail = 1, .modifiers = modifiers });- if (press.suppress_focus == false) {- focusForMouseDown(frame, target) catch |err| log.debug(.app, "click mousedown focus", .{ .err = err });- }+ const g: Gesture = .{+ .button = mouse_button.main,+ .buttons_down = 1,+ .click_count = 1,+ .modifiers = modifiers,+ .emit_pointer_events = true,+ .emit_mouse_compat = true,+ .update_hover = true,+ .focus_error = .warn,+ };+ var suppressed = false;+ try pressSequence(frame, target, g, &suppressed);- const up: PointerInput = .{ .x = 0, .y = 0, .detail = 1, .modifiers = modifiers };- try dispatchPointerRelease(frame, target, up, press.suppress_mouse);- // click is a PointerEvent, matching HTMLElement.click().- _ = try dispatchPointerEventOn(frame, target, "click", up);+ var up_g = g;+ up_g.buttons_down = 0;+ try releaseSequence(frame, target, up_g, suppressed, target);}pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32, click_count: i32) !void {@@ -347,29 +468,23 @@ pub fn triggerMousePress(frame: *Frame, x: f64, y: f64, button: i32, click_count}const gesture = frame.page.input_pointer.press(button);- // clickCount 0 (omitted) stays 0, not forced to 1: Chrome and Firefox- // both fire mousedown with detail 0 in that case.+ if (gesture.starts_gesture) {+ frame.page.input_pointer.down_target = target;+ }const detail: u32 = if (click_count > 0) @intCast(click_count) else 0;- const in: PointerInput = .{ .x = x, .y = y, .button = button, .buttons = gesture.held, .detail = detail };-+ const g: Gesture = .{+ .button = button,+ .buttons_down = gesture.held,+ .click_count = detail,+ .coords = .{ .x = x, .y = y },+ .emit_pointer_events = true,+ .emit_mouse_compat = true,+ .focus_error = .warn,+ };+ var suppressed = frame.page.input_pointer.mousedown_suppressed;+ try pressSequence(frame, target, g, &suppressed);if (gesture.starts_gesture) {- // Stash the pointerdown outcome before the fallible focus call: the- // release half is a separate message and can't observe it otherwise.- const press = try dispatchPointerPress(frame, target, in);- frame.page.input_pointer.mousedown_suppressed = press.suppress_mouse;- if (press.suppress_focus == false) {- try focusForMouseDown(frame, target);- }- } else {- // A chorded press is a buttons-mask change (pointermove), not a second- // pointerdown: https://www.w3.org/TR/pointerevents3/#chorded-button-interactions- _ = try dispatchPointerEventOn(frame, target, "pointermove", .{ .x = x, .y = y, .button = button, .buttons = gesture.held });- if (frame.page.input_pointer.mousedown_suppressed == false) {- const suppress_focus = try dispatchMouseEventOn(frame, target, "mousedown", in);- if (suppress_focus == false) {- try focusForMouseDown(frame, target);- }- }+ frame.page.input_pointer.mousedown_suppressed = suppressed;}}@@ -400,10 +515,8 @@ pub fn triggerMouseMove(frame: *Frame, x: f64, y: f64) !void {pub fn triggerMouseRelease(frame: *Frame, x: f64, y: f64, button: i32, click_count: i32) !void {// Consume the state before any early return, so a release that misses// every element can't leave it for the next message to misread.+ const down_target = frame.page.input_pointer.down_target;const gesture = frame.page.input_pointer.release(button);- const remaining = gesture.held;- const ends_gesture = gesture.ends_gesture;- const was_suppressed = gesture.was_suppressed;const target = (try frame.window._document.elementFromPoint(x, y, frame)) orelse return;if (comptime lp.IS_DEBUG) {@@ -418,31 +531,17 @@ pub fn triggerMouseRelease(frame: *Frame, x: f64, y: f64, button: i32, click_cou}const detail: u32 = if (click_count > 0) @intCast(click_count) else 1;-- if (ends_gesture) {- try dispatchPointerRelease(frame, target, .{ .x = x, .y = y, .button = button, .detail = detail }, was_suppressed);- } else {- // A chorded release (another button still held) is a buttons-mask- // change, not pointerup.- _ = try dispatchPointerEventOn(frame, target, "pointermove", .{ .x = x, .y = y, .button = button, .buttons = remaining });- if (!was_suppressed) {- _ = try dispatchMouseEventOn(frame, target, "mouseup", .{ .x = x, .y = y, .button = button, .buttons = remaining, .detail = detail });- }- }-- // After mouseup, the activation event depends on the button.- switch (button) {- mouse_button.main => {- _ = try dispatchPointerEventOn(frame, target, "click", .{ .x = x, .y = y, .buttons = remaining, .detail = detail });- // A second click in quick succession also fires dblclick.- if (click_count == 2) {- _ = try dispatchMouseEventOn(frame, target, "dblclick", .{ .x = x, .y = y, .button = button, .buttons = remaining, .detail = detail });- }- },- mouse_button.auxiliary => _ = try dispatchMouseEventOn(frame, target, "auxclick", .{ .x = x, .y = y, .button = button, .buttons = remaining, .detail = detail }),- mouse_button.secondary => _ = try dispatchMouseEventOn(frame, target, "contextmenu", .{ .x = x, .y = y, .button = button, .buttons = remaining, .detail = detail }),- else => {},- }+ const click_target = if (down_target) |dt| commonClickTarget(dt, target) else target;+ const g: Gesture = .{+ .button = button,+ .buttons_down = gesture.held,+ .click_count = detail,+ .coords = .{ .x = x, .y = y },+ .emit_pointer_events = true,+ .emit_mouse_compat = true,+ .focus_error = .warn,+ };+ try releaseSequence(frame, target, g, gesture.was_suppressed, click_target);}pub fn triggerMouseWheel(frame: *Frame, x: f64, y: f64, delta_x: f64, delta_y: f64) !void {diff --git a/src/browser/webapi/WebDriver.zig b/src/browser/webapi/WebDriver.zigindex 0e472abcb..c2d55bcd5 100644--- a/src/browser/webapi/WebDriver.zig+++ b/src/browser/webapi/WebDriver.zig@@ -60,12 +60,7 @@ fn getComputedLabel(_: *const WebDriver, element: *Element, frame: *Frame) ![]co// synchronously so the events are observable when the testdriver promise// resolves.pub fn click(_: *const WebDriver, element: *Element, frame: *Frame) !void {- if (element.is(Element.Html)) |html| {- switch (html._type) {- .button, .input, .textarea, .select, .option, .optgroup => if (element.isDisabled()) return,- else => {},- }- }+ if (element.isDisabled()) return;// A dispatch error must never reject the testdriver command.Frame.user_input.triggerClick(frame, element, frame.page.input_modifiers) catch |err| {@@ -237,6 +232,7 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {// Where the last pointerDown landed: the click fires at the nearest common// inclusive ancestor of the down and up targets when they differ.var down_target: ?*Element = null;+ var pointer_suppressed: bool = false;var click_count: u32 = 0;var last_click_button: i32 = 0;var last_click_target: ?*Element = null;@@ -263,7 +259,9 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {}const el = target orelse continue;if (is_touch) {- dispatchPointer(el, "pointermove", 0, pressed_mask, frame);+ _ = Frame.user_input.emitPointer(frame, el, "pointermove", .{+ .modifiers = frame.page.input_modifiers,+ }, 0, pressed_mask) catch {};if (pressed) {dispatchTouch(el, "touchmove", frame);}@@ -273,8 +271,12 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {.modifiers = frame.page.input_modifiers,.with_pointer = true,});- dispatchPointer(el, "pointermove", 0, pressed_mask, frame);- _ = dispatchMouse(el, "mousemove", 0, pressed_mask, 0, frame);+ _ = Frame.user_input.emitPointer(frame, el, "pointermove", .{+ .modifiers = frame.page.input_modifiers,+ }, 0, pressed_mask) catch {};+ _ = Frame.user_input.emitMouse(frame, el, "mousemove", .{+ .modifiers = frame.page.input_modifiers,+ }, 0, pressed_mask) catch {};}} else if (action_type.eql(comptime .wrap("pointerDown"))) {const el = target orelse continue;@@ -287,64 +289,68 @@ fn performPointerSource(source: js.Object, frame: *Frame) !void {} else {click_count = 1;}- dispatchPointer(el, "pointerdown", button, Frame.user_input.buttonsBitmask(button), frame);if (is_touch) {+ const g: Frame.user_input.Gesture = .{+ .button = button,+ .buttons_down = pressed_mask,+ .click_count = click_count,+ .modifiers = frame.page.input_modifiers,+ .emit_pointer_events = true,+ .emit_mouse_compat = false,+ };+ Frame.user_input.pressSequence(frame, el, g, &pointer_suppressed) catch {};dispatchTouch(el, "touchstart", frame);} else {- const suppressed = dispatchMouse(el, "mousedown", button, Frame.user_input.buttonsBitmask(button), click_count, frame);- if (!suppressed) {- Frame.user_input.focusForMouseDown(frame, el) catch |err| {- log.debug(.app, "webdriver mousedown focus", .{ .err = err });- };- }+ const g: Frame.user_input.Gesture = .{+ .button = button,+ .buttons_down = pressed_mask,+ .click_count = click_count,+ .modifiers = frame.page.input_modifiers,+ .emit_pointer_events = true,+ .emit_mouse_compat = true,+ .focus_error = .warn,+ };+ Frame.user_input.pressSequence(frame, el, g, &pointer_suppressed) catch {};}} else if (action_type.eql(comptime .wrap("pointerUp"))) {const el = target orelse continue;const button = readI32(action, "button", 0);pressed = false;pressed_mask = 0;- dispatchPointer(el, "pointerup", button, 0, frame);+ const click_target = Frame.user_input.commonClickTarget(down_target orelse el, el);+ last_click_button = button;+ last_click_target = click_target;if (is_touch) {+ const g: Frame.user_input.Gesture = .{+ .button = button,+ .buttons_down = 0,+ .click_count = click_count,+ .modifiers = frame.page.input_modifiers,+ .emit_pointer_events = true,+ .emit_mouse_compat = false,+ };+ Frame.user_input.releaseSequence(frame, el, g, pointer_suppressed, click_target) catch {};dispatchTouch(el, "touchend", frame);} else {- _ = 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);- if (click_count % 2 == 0) {- _ = 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, "auxclick", button, 0, click_count, frame);- }+ const g: Frame.user_input.Gesture = .{+ .button = button,+ .buttons_down = 0,+ .click_count = click_count,+ .modifiers = frame.page.input_modifiers,+ .emit_pointer_events = true,+ .emit_mouse_compat = true,+ .focus_error = .warn,+ };+ Frame.user_input.releaseSequence(frame, el, g, pointer_suppressed, click_target) catch {};}down_target = null;+ pointer_suppressed = false;}// "pause" carries timing only and is ignored. ("pointerCancel" is not// emitted by the testdriver Actions builder.)}}-// A click whose mousedown and mouseup landed on different elements fires at-// their nearest common inclusive ancestor element.-fn commonClickTarget(down: *Element, up: *Element) *Element {- if (down == up) {- return up;- }- var current: ?*@import("Node.zig") = down.asNode();- while (current) |node| : (current = node.parentNode()) {- if (node.contains(up.asNode())) {- return node.is(Element) orelse break;- }- }- return up;-}-fn performWheelSource(source: js.Object, frame: *Frame) !void {const actions_val = try source.get("actions");if (!actions_val.isArray()) {@@ -531,51 +537,6 @@ fn readI32(obj: js.Object, key: []const u8, default: i32) i32 {return val.toI32() catch default;}-fn dispatchPointer(el: *Element, comptime typ: []const u8, button: i32, buttons: u16, frame: *Frame) void {- const modifiers = frame.page.input_modifiers;- const event = PointerEvent.initTrusted(typ, .{- .bubbles = true,- .cancelable = true,- .composed = true,- .button = button,- .buttons = buttons,- .pointerId = 1,- .pointerType = "mouse",- .isPrimary = true,- .ctrlKey = modifiers.ctrl,- .shiftKey = modifiers.shift,- .altKey = modifiers.alt,- .metaKey = modifiers.meta,- }, frame) catch |err| {- log.debug(.app, "webdriver pointer event", .{ .err = err, .type = typ });- return;- };- dispatch(el.asEventTarget(), event.asEvent(), frame, typ);-}--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,- .cancelable = true,- .composed = true,- .button = button,- .buttons = buttons,- .detail = detail,- .ctrlKey = modifiers.ctrl,- .shiftKey = modifiers.shift,- .altKey = modifiers.alt,- .metaKey = modifiers.meta,- }, frame) catch |err| {- log.debug(.app, "webdriver mouse event", .{ .err = err, .type = typ });- return false;- };- return frame._event_manager.dispatchCancelable(el.asEventTarget(), event.asEvent()) catch |err| {- log.debug(.app, "webdriver dispatch", .{ .err = err, .type = typ });- return false;- };-}-// The action's x/y, which the caller already resolved the target from. An// element origin makes them offsets from its center, but the faux layout has// no center worth computing.diff --git a/src/server/cdp/domains/input.zig b/src/server/cdp/domains/input.zigindex c590d7649..a0a7ad29d 100644--- a/src/server/cdp/domains/input.zig+++ b/src/server/cdp/domains/input.zig@@ -946,6 +946,46 @@ test "cdp.input: a cancelled pointerdown suppresses mousedown and mouseup acrosstry testing.expect(result.isTrue());}+test "cdp.input: mousePressed and mouseReleased on a disabled button emit no events" {+ var ctx = try testing.context();+ defer ctx.deinit();++ const bc = try ctx.loadBrowserContext(.{});+ const page = try bc.session.createPage();+ const frame = page.frame().?;++ const url = "http://localhost:9582/src/browser/tests/mcp_actions.html";+ try frame.navigate(url, .{ .reason = .address_bar, .kind = .{ .push = null } });+ try testing.waitForPage(bc);++ var ls: lp.js.Local.Scope = undefined;+ frame.js.localScope(&ls);+ defer ls.deinit();++ var try_catch: lp.js.TryCatch = undefined;+ try_catch.init(&ls.local);+ defer try_catch.deinit();++ const rect_x = try (try ls.local.compileAndRun("document.getElementById('btnDisabled').getBoundingClientRect().x", null)).toF64();+ const rect_y = try (try ls.local.compileAndRun("document.getElementById('btnDisabled').getBoundingClientRect().y", null)).toF64();++ try ctx.processMessage(.{+ .id = 1,+ .method = "Input.dispatchMouseEvent",+ .params = .{ .type = "mousePressed", .x = rect_x, .y = rect_y, .button = "left", .clickCount = 1 },+ });+ try ctx.processMessage(.{+ .id = 2,+ .method = "Input.dispatchMouseEvent",+ .params = .{ .type = "mouseReleased", .x = rect_x, .y = rect_y, .button = "left", .clickCount = 1 },+ });++ const result = try ls.local.compileAndRun(+ \\JSON.stringify(window.disabledEvents) === '[]'+ , null);+ try testing.expect(result.isTrue());+}+// Asserts only the pointer events: pointerdown/pointerup fire at the mask's// 0/nonzero transitions and a mid-gesture button change is a pointermove (the// activation order below is a pre-existing, non-spec deviation from Chrome).