@@ -197,6 +197,24 @@ pub const Page = struct {
197197 try Dump .writeHTML (self .doc .? , out );
198198 }
199199
200+ pub fn wait (self : * Page ) ! void {
201+ const alloc = self .arena .allocator ();
202+ var res = try self .session .env .waitTryCatch (alloc );
203+ defer res .deinit (alloc );
204+
205+ if (res .success ) {
206+ log .debug ("wait: {s}" , .{res .result });
207+ } else {
208+ if (builtin .mode == .Debug and res .stack != null ) {
209+ log .info ("wait: {s}" , .{res .stack .? });
210+ } else {
211+ log .info ("wait: {s}" , .{res .result });
212+ }
213+ }
214+
215+ return ;
216+ }
217+
200218 // spec reference: https://html.spec.whatwg.org/#document-lifecycle
201219 pub fn navigate (self : * Page , uri : []const u8 ) ! void {
202220 const alloc = self .arena .allocator ();
@@ -448,8 +466,7 @@ pub const Page = struct {
448466 const opt_text = try parser .nodeTextContent (parser .elementToNode (e ));
449467 if (opt_text ) | text | {
450468 // TODO handle charset attribute
451- var res = jsruntime.JSResult {};
452- try self .session .env .run (alloc , text , "" , & res , null );
469+ var res = try self .session .env .execTryCatch (alloc , text , "" );
453470 defer res .deinit (alloc );
454471
455472 if (res .success ) {
@@ -498,8 +515,7 @@ pub const Page = struct {
498515 // check no body
499516 if (fetchres .body == null ) return FetchError .NoBody ;
500517
501- var res = jsruntime.JSResult {};
502- try self .session .env .run (alloc , fetchres .body .? , src , & res , null );
518+ var res = try self .session .env .execTryCatch (alloc , fetchres .body .? , src );
503519 defer res .deinit (alloc );
504520
505521 if (res .success ) {
0 commit comments