Merge pull request #1044 from lightpanda-io/script_nonce_and_df_host
Some checks failed
e2e-test / zig build release (push) Has been cancelled
e2e-test / demo-scripts (push) Has been cancelled
e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
e2e-test / perf-fmt (push) Has been cancelled
zig-test / zig build dev (push) Has been cancelled
zig-test / browser fetch (push) Has been cancelled
zig-test / zig test (push) Has been cancelled
zig-test / perf-fmt (push) Has been cancelled
nightly build / build-linux-x86_64 (push) Has been cancelled
nightly build / build-linux-aarch64 (push) Has been cancelled
nightly build / build-macos-aarch64 (push) Has been cancelled
nightly build / build-macos-x86_64 (push) Has been cancelled
wpt / web platform tests json output (push) Has been cancelled
wpt / perf-fmt (push) Has been cancelled

Add Script get/set nonce
This commit is contained in:
Karl Seguin
2025-09-12 20:45:50 +08:00
committed by GitHub
2 changed files with 19 additions and 0 deletions

View File

@@ -977,6 +977,21 @@ pub const HTMLScriptElement = struct {
return try parser.elementRemoveAttribute(parser.scriptToElt(self), "nomodule"); return try parser.elementRemoveAttribute(parser.scriptToElt(self), "nomodule");
} }
pub fn get_nonce(self: *parser.Script) !?[]const u8 {
return try parser.elementGetAttribute(
parser.scriptToElt(self),
"nonce",
) orelse "";
}
pub fn set_nonce(self: *parser.Script, v: []const u8) !void {
try parser.elementSetAttribute(
parser.scriptToElt(self),
"nonce",
v,
);
}
pub fn get_onload(self: *parser.Script, page: *Page) !?Env.Function { pub fn get_onload(self: *parser.Script, page: *Page) !?Env.Function {
const state = page.getNodeState(@ptrCast(@alignCast(self))) orelse return null; const state = page.getNodeState(@ptrCast(@alignCast(self))) orelse return null;
return state.onload; return state.onload;

View File

@@ -11,4 +11,8 @@
script.defer = true; script.defer = true;
testing.expectEqual(true, script.defer); testing.expectEqual(true, script.defer);
testing.expectEqual('', script.nonce);
script.nonce = 'hello';
testing.expectEqual('hello', script.nonce);
</script> </script>