Skip to content

Commit e5e57ab

Browse files
authored
Merge pull request #1044 from lightpanda-io/script_nonce_and_df_host
Add Script get/set nonce
2 parents bc341e9 + f3ce5dc commit e5e57ab

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/browser/html/elements.zig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -977,6 +977,21 @@ pub const HTMLScriptElement = struct {
977977
return try parser.elementRemoveAttribute(parser.scriptToElt(self), "nomodule");
978978
}
979979

980+
pub fn get_nonce(self: *parser.Script) !?[]const u8 {
981+
return try parser.elementGetAttribute(
982+
parser.scriptToElt(self),
983+
"nonce",
984+
) orelse "";
985+
}
986+
987+
pub fn set_nonce(self: *parser.Script, v: []const u8) !void {
988+
try parser.elementSetAttribute(
989+
parser.scriptToElt(self),
990+
"nonce",
991+
v,
992+
);
993+
}
994+
980995
pub fn get_onload(self: *parser.Script, page: *Page) !?Env.Function {
981996
const state = page.getNodeState(@ptrCast(@alignCast(self))) orelse return null;
982997
return state.onload;

src/tests/html/script/script.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,8 @@
1111

1212
script.defer = true;
1313
testing.expectEqual(true, script.defer);
14+
15+
testing.expectEqual('', script.nonce);
16+
script.nonce = 'hello';
17+
testing.expectEqual('hello', script.nonce);
1418
</script>

0 commit comments

Comments
 (0)