Skip to content

Lightpanda: the headless browser designed for AI and automation

add Lock WebAPI

Muki Kiboigocfe538f07e1b
diff --git a/src/browser/js/bridge.zig b/src/browser/js/bridge.zig
index 1507246aa..be5018c26 100644
--- a/src/browser/js/bridge.zig
+++ b/src/browser/js/bridge.zig
@@ -1330,6 +1330,7 @@ pub const PageJsApis = flattenTypes(&.{
@import("../webapi/XPathEvaluator.zig"),
@import("../webapi/collections/DOMStringList.zig"),
@import("../webapi/Sanitizer.zig"),
+ @import("../webapi/Lock.zig"),
});
// APIs available on EVERY worker global — dedicated, shared and service. This
@@ -1415,6 +1416,7 @@ const worker_common_apis = [_]type{
@import("../webapi/MessageChannel.zig"),
@import("../webapi/MessagePort.zig"),
@import("../webapi/collections/DOMStringList.zig"),
+ @import("../webapi/Lock.zig"),
};
// Additionally available on a dedicated or shared worker, but NOT on a service
diff --git a/src/browser/webapi/Lock.zig b/src/browser/webapi/Lock.zig
new file mode 100644
index 000000000..d73783a2b
--- /dev/null
+++ b/src/browser/webapi/Lock.zig
@@ -0,0 +1,57 @@
+// Copyright (C) 2023-2026 Lightpanda (Selecy SAS)
+//
+// Francis Bouvier <[email protected]>
+// Pierre Tachoire <[email protected]>
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as
+// published by the Free Software Foundation, either version 3 of the
+// License, or (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+const lp = @import("lightpanda");
+
+const js = @import("../js/js.zig");
+const Frame = @import("../Frame.zig");
+
+// https://developer.mozilla.org/en-US/docs/Web/API/Lock
+// https://w3c.github.io/web-locks/#lock
+const Lock = @This();
+
+_mode: LockMode,
+_name: lp.String,
+
+pub const LockMode = enum {
+ shared,
+ exclusive,
+
+ pub const js_enum_from_string = true;
+};
+
+fn getMode(self: *const Lock) LockMode {
+ return self._mode;
+}
+
+fn getName(self: *const Lock) lp.String {
+ return self._name;
+}
+
+pub const JsApi = struct {
+ pub const bridge = js.Bridge(Lock);
+
+ pub const Meta = struct {
+ pub const name = "Lock";
+ pub const prototype_chain = bridge.prototypeChain();
+ pub var class_id: bridge.ClassId = undefined;
+ };
+
+ pub const mode = bridge.accessor(Lock.getMode, null, .{});
+ pub const name = bridge.accessor(Lock.getName, null, .{});
+};