-
Notifications
You must be signed in to change notification settings - Fork 219
Load about blank doc to set window #630
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -335,6 +335,8 @@ pub const Page = struct { | |
|
||
// if the url is about:blank, nothing to do. | ||
if (std.mem.eql(u8, "about:blank", request_url.raw)) { | ||
var about_blank = AboutBlank{}; | ||
try self.loadHTMLDoc(&about_blank, "utf-8"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I wonder if the behavior can be split into two functions, |
||
return; | ||
} | ||
|
||
|
@@ -393,6 +395,16 @@ pub const Page = struct { | |
}); | ||
} | ||
|
||
// A minimal reader for about:blank such that it can be parsed by loadHTMLDoc. | ||
pub const AboutBlank = struct { | ||
done: bool = false, | ||
pub fn next(self: *AboutBlank) !?[]const u8 { | ||
if (self.done) return null; | ||
self.done = true; | ||
return ""; // The contents is blank | ||
} | ||
}; | ||
|
||
// https://html.spec.whatwg.org/#read-html | ||
fn loadHTMLDoc(self: *Page, reader: anytype, charset: []const u8) !void { | ||
const arena = self.arena; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,6 +125,10 @@ fn createTarget(cmd: anytype) !void { | |
bc.target_id = target_id; | ||
|
||
var page = try bc.session.createPage(); | ||
// Navigate to about:blank such that the window / state.document are created and set | ||
// Playwright uses these before navigating to a real URL to detect when they are removed. | ||
const url = try @import("../../url.zig").URL.parse("about:blank", ""); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could maybe create a const |
||
try page.navigate(url, .{}); | ||
{ | ||
const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id}); | ||
bc.inspector.contextCreated( | ||
|
@@ -501,6 +505,11 @@ test "cdp.target: createTarget" { | |
// should create a browser context | ||
const bc = ctx.cdp().browser_context.?; | ||
try ctx.expectSentEvent("Target.targetCreated", .{ .targetInfo = .{ .url = "about:blank", .title = "about:blank", .attached = false, .type = "page", .canAccessOpener = false, .browserContextId = bc.id, .targetId = bc.target_id.? } }, .{}); | ||
|
||
// Even about:blank should set the window and document | ||
const page = ctx.cdp().browser_context.?.session.page.?; | ||
try std.testing.expect(page.state.document != null); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There's a It's In testing.zig pub const expect = std.testing.expect; in cdp/testing.zig pub const expect = base.expect; Or not, I think this code here is fine, just wanted to FYI about the existing testing files. |
||
try std.testing.expect(page.window.document != null); | ||
} | ||
|
||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AboutBlank
is pretty clever, but this would work too I think: