mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-12-19 10:28:10 +00:00
re-enable minimum viable CDP server
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -23,7 +23,7 @@ const log = @import("../../log.zig");
|
||||
const network = @import("network.zig");
|
||||
|
||||
const Http = @import("../../http/Http.zig");
|
||||
const Notification = @import("../../notification.zig").Notification;
|
||||
const Notification = @import("../../Notification.zig");
|
||||
|
||||
pub fn processMessage(cmd: anytype) !void {
|
||||
const action = std.meta.stringToEnum(enum {
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const Page = @import("../../browser/page.zig").Page;
|
||||
const Page = @import("../../browser/Page.zig");
|
||||
|
||||
pub fn processMessage(cmd: anytype) !void {
|
||||
const action = std.meta.stringToEnum(enum {
|
||||
|
||||
@@ -101,7 +101,7 @@ pub fn LogInterceptor(comptime BC: type) type {
|
||||
.fatal => "error",
|
||||
},
|
||||
.text = self.allocating.written(),
|
||||
.timestamp = @import("../../datetime.zig").milliTimestamp(),
|
||||
.timestamp = @import("../../datetime.zig").milliTimestamp(.monotonic),
|
||||
},
|
||||
}, .{
|
||||
.session_id = self.bc.session_id,
|
||||
|
||||
@@ -21,7 +21,7 @@ const Allocator = std.mem.Allocator;
|
||||
|
||||
const CdpStorage = @import("storage.zig");
|
||||
const Transfer = @import("../../http/Client.zig").Transfer;
|
||||
const Notification = @import("../../notification.zig").Notification;
|
||||
const Notification = @import("../../Notification.zig");
|
||||
|
||||
pub fn processMessage(cmd: anytype) !void {
|
||||
const action = std.meta.stringToEnum(enum {
|
||||
@@ -87,7 +87,7 @@ fn setExtraHTTPHeaders(cmd: anytype) !void {
|
||||
return cmd.sendResult(null, .{});
|
||||
}
|
||||
|
||||
const Cookie = @import("../../browser/storage/storage.zig").Cookie;
|
||||
const Cookie = @import("../../browser/webapi/storage/storage.zig").Cookie;
|
||||
|
||||
// Only matches the cookie on provided parameters
|
||||
fn cookieMatches(cookie: *const Cookie, name: []const u8, domain: ?[]const u8, path: ?[]const u8) bool {
|
||||
@@ -173,7 +173,7 @@ fn getCookies(cmd: anytype) !void {
|
||||
const params = (try cmd.params(GetCookiesParam)) orelse GetCookiesParam{};
|
||||
|
||||
// If not specified, use the URLs of the page and all of its subframes. TODO subframes
|
||||
const page_url = if (bc.session.page) |*page| page.url.raw else null; // @speed: avoid repasing the URL
|
||||
const page_url = if (bc.session.page) |page| page.url else null;
|
||||
const param_urls = params.urls orelse &[_][]const u8{page_url orelse return error.InvalidParams};
|
||||
|
||||
var urls = try std.ArrayListUnmanaged(CdpStorage.PreparedUri).initCapacity(cmd.arena, param_urls.len);
|
||||
@@ -247,7 +247,7 @@ pub fn httpRequestStart(arena: Allocator, bc: anytype, msg: *const Notification.
|
||||
.requestId = try std.fmt.allocPrint(arena, "REQ-{d}", .{transfer.id}),
|
||||
.frameId = target_id,
|
||||
.loaderId = bc.loader_id,
|
||||
.documentUrl = DocumentUrlWriter.init(&page.url.uri),
|
||||
.documentUrl = page.url,
|
||||
.request = TransferAsRequestWriter.init(transfer),
|
||||
.initiator = .{ .type = "other" },
|
||||
}, .{ .session_id = session_id });
|
||||
@@ -416,34 +416,35 @@ const TransferAsResponseWriter = struct {
|
||||
}
|
||||
};
|
||||
|
||||
const DocumentUrlWriter = struct {
|
||||
uri: *std.Uri,
|
||||
// @ZIGDOM - do we still need this? just send the full URL?
|
||||
// const DocumentUrlWriter = struct {
|
||||
// uri: *std.Uri,
|
||||
|
||||
fn init(uri: *std.Uri) DocumentUrlWriter {
|
||||
return .{
|
||||
.uri = uri,
|
||||
};
|
||||
}
|
||||
// fn init(uri: *std.Uri) DocumentUrlWriter {
|
||||
// return .{
|
||||
// .uri = uri,
|
||||
// };
|
||||
// }
|
||||
|
||||
pub fn jsonStringify(self: *const DocumentUrlWriter, jws: anytype) !void {
|
||||
self._jsonStringify(jws) catch return error.WriteFailed;
|
||||
}
|
||||
fn _jsonStringify(self: *const DocumentUrlWriter, jws: anytype) !void {
|
||||
const writer = jws.writer;
|
||||
// pub fn jsonStringify(self: *const DocumentUrlWriter, jws: anytype) !void {
|
||||
// self._jsonStringify(jws) catch return error.WriteFailed;
|
||||
// }
|
||||
// fn _jsonStringify(self: *const DocumentUrlWriter, jws: anytype) !void {
|
||||
// const writer = jws.writer;
|
||||
|
||||
try jws.beginWriteRaw();
|
||||
try writer.writeByte('\"');
|
||||
try self.uri.writeToStream(writer, .{
|
||||
.scheme = true,
|
||||
.authentication = true,
|
||||
.authority = true,
|
||||
.path = true,
|
||||
.query = true,
|
||||
});
|
||||
try writer.writeByte('\"');
|
||||
jws.endWriteRaw();
|
||||
}
|
||||
};
|
||||
// try jws.beginWriteRaw();
|
||||
// try writer.writeByte('\"');
|
||||
// try self.uri.writeToStream(writer, .{
|
||||
// .scheme = true,
|
||||
// .authentication = true,
|
||||
// .authority = true,
|
||||
// .path = true,
|
||||
// .query = true,
|
||||
// });
|
||||
// try writer.writeByte('\"');
|
||||
// jws.endWriteRaw();
|
||||
// }
|
||||
// };
|
||||
|
||||
fn idFromRequestId(request_id: []const u8) !u64 {
|
||||
if (!std.mem.startsWith(u8, request_id, "REQ-")) {
|
||||
|
||||
@@ -17,8 +17,8 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const Page = @import("../../browser/page.zig").Page;
|
||||
const Notification = @import("../../notification.zig").Notification;
|
||||
const Page = @import("../../browser/Page.zig");
|
||||
const Notification = @import("../../Notification.zig");
|
||||
|
||||
const Allocator = std.mem.Allocator;
|
||||
|
||||
@@ -134,7 +134,7 @@ fn createIsolatedWorld(cmd: anytype) !void {
|
||||
|
||||
fn navigate(cmd: anytype) !void {
|
||||
const params = (try cmd.params(struct {
|
||||
url: []const u8,
|
||||
url: [:0]const u8,
|
||||
// referrer: ?[]const u8 = null,
|
||||
// transitionType: ?[]const u8 = null, // TODO: enum
|
||||
// frameId: ?[]const u8 = null,
|
||||
@@ -253,7 +253,8 @@ pub fn pageNavigate(arena: Allocator, bc: anytype, event: *const Notification.Pa
|
||||
bc.inspector.contextCreated(
|
||||
page.js,
|
||||
"",
|
||||
try page.origin(arena),
|
||||
"", // @ZIGDOM
|
||||
// try page.origin(arena),
|
||||
aux_data,
|
||||
true,
|
||||
);
|
||||
@@ -360,7 +361,7 @@ pub fn pageNetworkAlmostIdle(bc: anytype, event: *const Notification.PageNetwork
|
||||
return sendPageLifecycle(bc, "networkAlmostIdle", event.timestamp);
|
||||
}
|
||||
|
||||
fn sendPageLifecycle(bc: anytype, name: []const u8, timestamp: u32) !void {
|
||||
fn sendPageLifecycle(bc: anytype, name: []const u8, timestamp: u64) !void {
|
||||
// detachTarget could be called, in which case, we still have a page doing
|
||||
// things, but no session.
|
||||
const session_id = bc.session_id orelse return;
|
||||
@@ -379,7 +380,7 @@ const LifecycleEvent = struct {
|
||||
frameId: []const u8,
|
||||
loaderId: ?[]const u8,
|
||||
name: []const u8,
|
||||
timestamp: u32,
|
||||
timestamp: u64,
|
||||
};
|
||||
|
||||
const testing = @import("../testing.zig");
|
||||
|
||||
@@ -19,9 +19,9 @@
|
||||
const std = @import("std");
|
||||
|
||||
const log = @import("../../log.zig");
|
||||
const Cookie = @import("../../browser/storage/storage.zig").Cookie;
|
||||
const CookieJar = @import("../../browser/storage/storage.zig").CookieJar;
|
||||
pub const PreparedUri = @import("../../browser/storage/cookie.zig").PreparedUri;
|
||||
const Cookie = @import("../../browser/webapi/storage/storage.zig").Cookie;
|
||||
const CookieJar = @import("../../browser/webapi/storage/storage.zig").Jar;
|
||||
pub const PreparedUri = @import("../../browser/webapi/storage/cookie.zig").PreparedUri;
|
||||
|
||||
pub fn processMessage(cmd: anytype) !void {
|
||||
const action = std.meta.stringToEnum(enum {
|
||||
|
||||
@@ -143,13 +143,14 @@ fn createTarget(cmd: anytype) !void {
|
||||
|
||||
bc.target_id = target_id;
|
||||
|
||||
var page = try bc.session.createPage();
|
||||
const page = try bc.session.createPage();
|
||||
{
|
||||
const aux_data = try std.fmt.allocPrint(cmd.arena, "{{\"isDefault\":true,\"type\":\"default\",\"frameId\":\"{s}\"}}", .{target_id});
|
||||
bc.inspector.contextCreated(
|
||||
page.js,
|
||||
"",
|
||||
try page.origin(cmd.arena),
|
||||
"", // @ZIGDOM
|
||||
// try page.origin(arena),
|
||||
aux_data,
|
||||
true,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user