Skip to content

Lightpanda: the headless browser designed for AI and automation

input: refuse every edit on a disabled control before beforeinput

Adrià Arrufatbc9fa88abd8a
diff --git a/src/browser/frame/user_input.zig b/src/browser/frame/user_input.zig
index 18675da1c..9f05f54a3 100644
--- a/src/browser/frame/user_input.zig
+++ b/src/browser/frame/user_input.zig
@@ -992,10 +992,13 @@ pub const Edit = union(enum) {
/// refused on a readonly or disabled control. Returns whether it happened.
pub fn applyEdit(frame: *Frame, ctl: anytype, edit: Edit, opts: struct { beforeinput: bool = true }) !bool {
const el = ctl.asElement();
+ if (!ctl.acceptsTextEntry() or el.isDisabled()) {
+ return false;
+ }
const editable = acceptsEdit(el);
// Chrome fires beforeinput and textInput for text typed into a readonly
// control and only then refuses it; its editing commands fire nothing.
- if (!ctl.acceptsTextEntry() or (!editable and edit != .insert)) {
+ if (!editable and edit != .insert) {
return false;
}
diff --git a/src/server/cdp/domains/input.zig b/src/server/cdp/domains/input.zig
index ec48da09d..c7ea96e16 100644
--- a/src/server/cdp/domains/input.zig
+++ b/src/server/cdp/domains/input.zig
@@ -1643,7 +1643,7 @@ test "cdp.input: dispatchKeyEvent text-less keyDown then char types once" {
try testing.expect((try ls.local.compileAndRun("ta.value === 'one\\n' && window.taInput === 'insertLineBreak:null'", null)).isTrue());
}
-test "cdp.input: a readonly textarea fires beforeinput for typed text only" {
+test "cdp.input: a readonly textarea fires beforeinput for typed text only, a disabled one nothing" {
var ctx = try testing.context();
defer ctx.deinit();
@@ -1672,6 +1672,11 @@ test "cdp.input: a readonly textarea fires beforeinput for typed text only" {
try testing.expect((try ls.local.compileAndRun(
\\ta.value === 'ro' && window.edits.join() === 'beforeinput:insertText,beforeinput:insertText'
, null)).isTrue());
+
+ // A disabled control fires nothing, not even for typed text.
+ _ = try ls.local.compileAndRun("ta.readOnly = false; ta.disabled = true; window.edits = [];", null);
+ try ctx.processMessage(.{ .id = 5, .method = "Input.insertText", .params = .{ .text = "z" } });
+ try testing.expect((try ls.local.compileAndRun("ta.value === 'ro' && window.edits.length === 0", null)).isTrue());
}
test "cdp.input: dispatchKeyEvent char honors keypress and beforeinput vetoes" {