@@ -39,6 +39,9 @@ const storage = @import("../storage/storage.zig");
3939
4040const FetchResult = std .http .Client .FetchResult ;
4141
42+ const UserContext = @import ("../user_context.zig" ).UserContext ;
43+ const HttpClient = @import ("../async/Client.zig" );
44+
4245const log = std .log .scoped (.browser );
4346
4447// Browser is an instance of the browser.
@@ -92,6 +95,7 @@ pub const Session = struct {
9295 // TODO move the shed to the browser?
9396 storageShed : storage.Shed ,
9497 page : ? * Page = null ,
98+ httpClient : HttpClient ,
9599
96100 jstypes : [Types .len ]usize = undefined ,
97101
@@ -105,9 +109,11 @@ pub const Session = struct {
105109 .loader = Loader .init (alloc ),
106110 .loop = try Loop .init (alloc ),
107111 .storageShed = storage .Shed .init (alloc ),
112+ .httpClient = undefined ,
108113 };
109114
110115 self .env = try Env .init (self .arena .allocator (), & self .loop , null );
116+ self .httpClient = .{ .allocator = alloc , .loop = & self .loop };
111117 try self .env .load (& self .jstypes );
112118
113119 return self ;
@@ -122,6 +128,7 @@ pub const Session = struct {
122128 self .loader .deinit ();
123129 self .loop .deinit ();
124130 self .storageShed .deinit ();
131+ self .httpClient .deinit ();
125132 self .alloc .destroy (self );
126133 }
127134
@@ -289,6 +296,12 @@ pub const Page = struct {
289296 log .debug ("start js env" , .{});
290297 try self .session .env .start (alloc );
291298
299+ // replace the user context document with the new one.
300+ try self .session .env .setUserContext (.{
301+ .document = html_doc ,
302+ .httpClient = & self .session .httpClient ,
303+ });
304+
292305 // add global objects
293306 log .debug ("setup global env" , .{});
294307 try self .session .env .bindGlobal (& self .session .window );
0 commit comments