Lightpanda: the headless browser designed for AI and automation
webapi: add an always-returning-false execCommand
Karl Seguin5aa61f2a4c17
diff --git a/src/browser/tests/document/exec_command.html b/src/browser/tests/document/exec_command.htmlnew file mode 100644index 000000000..4de875cc8--- /dev/null+++ b/src/browser/tests/document/exec_command.html@@ -0,0 +1,47 @@+<!DOCTYPE html>+<meta name=lp-mode content=test>+<script src="../testing.js"></script>+<body><div id="host" contenteditable>abc</div></body>++<script id="unsupported">+{+ // Chrome doesn't support these either. Slack calls the first two (#4216).+ for (const cmd of ['enableObjectResizing', 'autoUrlDetect', 'nope']) {+ testing.expectEqual(false, document.execCommand(cmd, false, false));+ testing.expectEqual(false, document.queryCommandSupported(cmd));+ testing.expectEqual(false, document.queryCommandEnabled(cmd));+ testing.expectEqual(false, document.queryCommandState(cmd));+ testing.expectEqual(false, document.queryCommandIndeterm(cmd));+ testing.expectEqual('', document.queryCommandValue(cmd));+ }+}+</script>++<script id="editing_commands">+{+ const host = $('#host');+ for (const cmd of ['bold', 'insertText']) {+ host.innerHTML = 'abc';+ getSelection().selectAllChildren(host);+ testing.expectEqual(false, document.queryCommandState(cmd));+ testing.expectEqual(false, document.queryCommandIndeterm(cmd));+ testing.diverges('no editing pipeline', () => {+ testing.expectEqual(false, document.queryCommandSupported(cmd));+ testing.expectEqual(false, document.queryCommandEnabled(cmd));+ testing.expectEqual(false, document.execCommand(cmd, false, 'x'));+ testing.expectEqual('abc', host.innerHTML);+ });+ }+ // supported in Chrome whether or not there's a user click; exec isn't+ testing.diverges('no clipboard', () => {+ testing.expectEqual(false, document.queryCommandSupported('copy'));+ });+}+</script>++<script id="command_required">+{+ testing.expectError('TypeError', () => document.execCommand());+ testing.expectError('TypeError', () => document.queryCommandSupported());+}+</script>diff --git a/src/browser/webapi/Document.zig b/src/browser/webapi/Document.zigindex 7026c16b8..82e26e45e 100644--- a/src/browser/webapi/Document.zig+++ b/src/browser/webapi/Document.zig@@ -1416,6 +1416,22 @@ fn exitFullscreen(_: *Document, frame: *Frame) js.Promise {return frame.js.local.?.rejectPromise(.{ .type_error = "Document not in fullscreen" });}+// There's no editing pipeline or clipboard, so every execCommand command is+// unsupported. The spec's answer for that is false (or "" for the value), not+// an exception, which keeps callers on their fallbacks.+fn execCommand(_: *const Document, command: []const u8) bool {+ log.info(.not_implemented, "document.execCommand", .{ .command = command });+ return false;+}++fn queryCommand(_: *const Document, _: []const u8) bool {+ return false;+}++fn queryCommandValue(_: *const Document, _: []const u8) []const u8 {+ return "";+}+pub fn hasFocus(self: *Document) bool {var top = self._frame orelse return false;while (top.parent) |parent| {@@ -1882,6 +1898,12 @@ pub const JsApi = struct {pub const fullscreen = bridge.property(false, .{ .template = false, .readonly = true });pub const fullscreenElement = bridge.accessor(Document.getFullscreenElement, null, .{});pub const exitFullscreen = bridge.function(Document.exitFullscreen, .{});+ pub const execCommand = bridge.function(Document.execCommand, .{});+ pub const queryCommandEnabled = bridge.function(Document.queryCommand, .{});+ pub const queryCommandIndeterm = bridge.function(Document.queryCommand, .{});+ pub const queryCommandState = bridge.function(Document.queryCommand, .{});+ pub const queryCommandSupported = bridge.function(Document.queryCommand, .{});+ pub const queryCommandValue = bridge.function(Document.queryCommandValue, .{});pub const prerendering = bridge.property(false, .{ .template = false });pub const characterSet = bridge.accessor(Document.getCharset, null, .{});