dynamic script support

This commit is contained in:
Karl Seguin
2025-08-03 07:20:33 +08:00
parent dc83765808
commit 3c0d027306
2 changed files with 11 additions and 20 deletions

View File

@@ -884,19 +884,12 @@ fn timestamp() u32 {
// after the document is loaded, it's ok to execute any async and defer scripts
// immediately.
pub export fn scriptAddedCallback(ctx: ?*anyopaque, element: ?*parser.Element) callconv(.C) void {
_ = ctx;
_ = element;
// @newhttp
// const self: *Page = @alignCast(@ptrCast(ctx.?));
// if (self.delayed_navigation) {
// // if we're planning on navigating to another page, don't run this script
// return;
// }
// var script = Script.init(element.?, self) catch |err| {
// log.warn(.browser, "script added init error", .{ .err = err });
// return;
// } orelse return;
// _ = self.evalScript(&script);
const self: *Page = @alignCast(@ptrCast(ctx.?));
if (self.delayed_navigation) {
// if we're planning on navigating to another page, don't run this script
return;
}
self.script_manager.addFromElement(element.?) catch |err| {
log.warn(.browser, "dynamcic script", .{ .err = err });
};
}

View File

@@ -38,7 +38,7 @@ const Http = @This();
opts: Opts,
client: *Client,
ca_blob: ?c.curl_blob,
ca_blob: c.curl_blob,
cert_arena: ArenaAllocator,
pub fn init(allocator: Allocator, opts: Opts) !Http {
@@ -79,7 +79,7 @@ pub const Connection = struct {
// Is called by Handles when already partially initialized. Done like this
// so that we have a stable pointer to error_buffer.
pub fn init(ca_blob_: ?c.curl_blob, opts: Opts) !Connection {
pub fn init(ca_blob: c.curl_blob, opts: Opts) !Connection {
const easy = c.curl_easy_init() orelse return error.FailedToInitializeEasy;
errdefer _ = c.curl_easy_cleanup(easy);
@@ -95,9 +95,7 @@ pub const Connection = struct {
// tls
// try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SSL_VERIFYHOST, @as(c_long, 0)));
// try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_SSL_VERIFYPEER, @as(c_long, 0)));
if (ca_blob_) |ca_blob| {
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_CAINFO_BLOB, ca_blob));
}
try errorCheck(c.curl_easy_setopt(easy, c.CURLOPT_CAINFO_BLOB, ca_blob));
// debug
if (comptime Http.ENABLE_DEBUG) {