@@ -205,15 +205,21 @@ fn reset(self: *Page, comptime initializing: bool) !void {
205205
206206 self .document = (try self ._factory .document (Node.Document.HTMLDocument { ._proto = undefined })).asDocument ();
207207
208- const storage_bucket = try self ._factory .create (storage.Bucket {});
209- self .window = try self ._factory .eventTarget (Window {
210- ._document = self .document ,
211- ._storage_bucket = storage_bucket ,
212- ._history = History .init (self ),
213- ._performance = Performance .init (),
214- ._proto = undefined ,
215- ._location = & default_location ,
216- });
208+ if (comptime initializing == true ) {
209+ const storage_bucket = try self ._factory .create (storage.Bucket {});
210+ self .window = try self ._factory .eventTarget (Window {
211+ ._document = self .document ,
212+ ._storage_bucket = storage_bucket ,
213+ ._history = History .init (self ),
214+ ._performance = Performance .init (),
215+ ._proto = undefined ,
216+ ._location = & default_location ,
217+ });
218+ } else {
219+ self .window ._document = self .document ;
220+ self .window ._location = & default_location ;
221+ // TODO reset _custom_elements?
222+ }
217223
218224 self ._parse_state = .pre ;
219225 self ._load_state = .parsing ;
@@ -224,8 +230,10 @@ fn reset(self: *Page, comptime initializing: bool) !void {
224230 self ._script_manager = ScriptManager .init (self );
225231 errdefer self ._script_manager .deinit ();
226232
227- self .js = try self ._session .executor .createContext (self , true , JS .GlobalMissingCallback .init (& self ._polyfill_loader ));
228- errdefer self .js .deinit ();
233+ if (comptime initializing == true ) {
234+ self .js = try self ._session .executor .createContext (self , true , JS .GlobalMissingCallback .init (& self ._polyfill_loader ));
235+ errdefer self .js .deinit ();
236+ }
229237
230238 self ._element_styles = .{};
231239 self ._element_datasets = .{};
0 commit comments