mirror of
https://github.com/lightpanda-io/browser.git
synced 2026-02-04 14:33:47 +00:00
Document log_filter_scope argument
Add fetch logging
This commit is contained in:
@@ -27,6 +27,8 @@ const App = @import("../App.zig");
|
|||||||
const HttpClient = @import("../http/Client.zig");
|
const HttpClient = @import("../http/Client.zig");
|
||||||
const Notification = @import("../Notification.zig");
|
const Notification = @import("../Notification.zig");
|
||||||
|
|
||||||
|
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||||
|
|
||||||
const Session = @import("Session.zig");
|
const Session = @import("Session.zig");
|
||||||
|
|
||||||
// Browser is an instance of the browser.
|
// Browser is an instance of the browser.
|
||||||
@@ -104,7 +106,9 @@ pub fn runMicrotasks(self: *const Browser) void {
|
|||||||
|
|
||||||
pub fn runMessageLoop(self: *const Browser) void {
|
pub fn runMessageLoop(self: *const Browser) void {
|
||||||
while (self.env.pumpMessageLoop()) {
|
while (self.env.pumpMessageLoop()) {
|
||||||
log.debug(.browser, "pumpMessageLoop", .{});
|
if (comptime IS_DEBUG) {
|
||||||
|
log.debug(.browser, "pumpMessageLoop", .{});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
self.env.runIdleTasks();
|
self.env.runIdleTasks();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -472,11 +472,13 @@ fn pageHeaderDoneCallback(transfer: *Http.Transfer) !void {
|
|||||||
self.window._location = try Location.init(self.url, self);
|
self.window._location = try Location.init(self.url, self);
|
||||||
self.document._location = self.window._location;
|
self.document._location = self.window._location;
|
||||||
|
|
||||||
log.debug(.page, "navigate header", .{
|
if (comptime IS_DEBUG) {
|
||||||
.url = self.url,
|
log.debug(.page, "navigate header", .{
|
||||||
.status = header.status,
|
.url = self.url,
|
||||||
.content_type = header.contentType(),
|
.status = header.status,
|
||||||
});
|
.content_type = header.contentType(),
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn pageDataCallback(transfer: *Http.Transfer, data: []const u8) !void {
|
fn pageDataCallback(transfer: *Http.Transfer, data: []const u8) !void {
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ const Browser = @import("Browser.zig");
|
|||||||
|
|
||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const NavigateOpts = Page.NavigateOpts;
|
const NavigateOpts = Page.NavigateOpts;
|
||||||
|
const IS_DEBUG = @import("builtin").mode == .Debug;
|
||||||
|
|
||||||
// Session is like a browser's tab.
|
// Session is like a browser's tab.
|
||||||
// It owns the js env and the loader for all the pages of the session.
|
// It owns the js env and the loader for all the pages of the session.
|
||||||
@@ -110,7 +111,9 @@ pub fn createPage(self: *Session) !*Page {
|
|||||||
// Creates a new NavigationEventTarget for this page.
|
// Creates a new NavigationEventTarget for this page.
|
||||||
try self.navigation.onNewPage(page);
|
try self.navigation.onNewPage(page);
|
||||||
|
|
||||||
log.debug(.browser, "create page", .{});
|
if (comptime IS_DEBUG) {
|
||||||
|
log.debug(.browser, "create page", .{});
|
||||||
|
}
|
||||||
// start JS env
|
// start JS env
|
||||||
// Inform CDP the main page has been created such that additional context for other Worlds can be created as well
|
// Inform CDP the main page has been created such that additional context for other Worlds can be created as well
|
||||||
self.browser.notification.dispatch(.page_created, page);
|
self.browser.notification.dispatch(.page_created, page);
|
||||||
@@ -129,7 +132,9 @@ pub fn removePage(self: *Session) void {
|
|||||||
|
|
||||||
self.navigation.onRemovePage();
|
self.navigation.onRemovePage();
|
||||||
|
|
||||||
log.debug(.browser, "remove page", .{});
|
if (comptime IS_DEBUG) {
|
||||||
|
log.debug(.browser, "remove page", .{});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn currentPage(self: *Session) ?*Page {
|
pub fn currentPage(self: *Session) ?*Page {
|
||||||
|
|||||||
@@ -28,17 +28,17 @@ const DOMStringMap = @This();
|
|||||||
|
|
||||||
_element: *Element,
|
_element: *Element,
|
||||||
|
|
||||||
fn _getProperty(self: *DOMStringMap, name: []const u8, page: *Page) !?[]const u8 {
|
fn getProperty(self: *DOMStringMap, name: []const u8, page: *Page) !?[]const u8 {
|
||||||
const attr_name = try camelToKebab(page.call_arena, name);
|
const attr_name = try camelToKebab(page.call_arena, name);
|
||||||
return try self._element.getAttribute(attr_name, page);
|
return try self._element.getAttribute(attr_name, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _setProperty(self: *DOMStringMap, name: []const u8, value: []const u8, page: *Page) !void {
|
fn setProperty(self: *DOMStringMap, name: []const u8, value: []const u8, page: *Page) !void {
|
||||||
const attr_name = try camelToKebab(page.call_arena, name);
|
const attr_name = try camelToKebab(page.call_arena, name);
|
||||||
return self._element.setAttributeSafe(attr_name, value, page);
|
return self._element.setAttributeSafe(attr_name, value, page);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn _deleteProperty(self: *DOMStringMap, name: []const u8, page: *Page) !void {
|
fn deleteProperty(self: *DOMStringMap, name: []const u8, page: *Page) !void {
|
||||||
const attr_name = try camelToKebab(page.call_arena, name);
|
const attr_name = try camelToKebab(page.call_arena, name);
|
||||||
try self._element.removeAttribute(attr_name, page);
|
try self._element.removeAttribute(attr_name, page);
|
||||||
}
|
}
|
||||||
@@ -101,5 +101,5 @@ pub const JsApi = struct {
|
|||||||
pub var class_id: bridge.ClassId = undefined;
|
pub var class_id: bridge.ClassId = undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const @"[]" = bridge.namedIndexed(_getProperty, _setProperty, _deleteProperty, .{ .null_as_undefined = true });
|
pub const @"[]" = bridge.namedIndexed(getProperty, setProperty, deleteProperty, .{ .null_as_undefined = true });
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -99,6 +99,14 @@ fn httpHeaderDoneCallback(transfer: *Http.Transfer) !void {
|
|||||||
const res = self._response;
|
const res = self._response;
|
||||||
const header = transfer.response_header.?;
|
const header = transfer.response_header.?;
|
||||||
|
|
||||||
|
if (comptime IS_DEBUG) {
|
||||||
|
log.debug(.http, "request header", .{
|
||||||
|
.source = "xhr",
|
||||||
|
.url = self._url,
|
||||||
|
.status = header.status,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
res._status = header.status;
|
res._status = header.status;
|
||||||
res._url = try self._page.arena.dupeZ(u8, std.mem.span(header.url));
|
res._url = try self._page.arena.dupeZ(u8, std.mem.span(header.url));
|
||||||
res._is_redirected = header.redirect_count > 0;
|
res._is_redirected = header.redirect_count > 0;
|
||||||
@@ -135,6 +143,14 @@ fn httpDataCallback(transfer: *Http.Transfer, data: []const u8) !void {
|
|||||||
fn httpDoneCallback(ctx: *anyopaque) !void {
|
fn httpDoneCallback(ctx: *anyopaque) !void {
|
||||||
const self: *Fetch = @ptrCast(@alignCast(ctx));
|
const self: *Fetch = @ptrCast(@alignCast(ctx));
|
||||||
self._response._body = self._buf.items;
|
self._response._body = self._buf.items;
|
||||||
|
|
||||||
|
log.info(.http, "request complete", .{
|
||||||
|
.source = "fetch",
|
||||||
|
.url = self._url,
|
||||||
|
.status = self._response._status,
|
||||||
|
.len = self._buf.items.len,
|
||||||
|
});
|
||||||
|
|
||||||
return self._resolver.resolve("fetch done", self._response);
|
return self._resolver.resolve("fetch done", self._response);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -305,6 +305,11 @@ const Command = struct {
|
|||||||
\\--log_format The log format: pretty or logfmt.
|
\\--log_format The log format: pretty or logfmt.
|
||||||
\\ Defaults to
|
\\ Defaults to
|
||||||
++ (if (builtin.mode == .Debug) " pretty." else " logfmt.") ++
|
++ (if (builtin.mode == .Debug) " pretty." else " logfmt.") ++
|
||||||
|
\\
|
||||||
|
\\
|
||||||
|
\\--log_filter_scopes
|
||||||
|
\\ Filter out too verbose logs per scope:
|
||||||
|
\\ http, unknown_prop, event, ...
|
||||||
\\
|
\\
|
||||||
\\ --user_agent_suffix
|
\\ --user_agent_suffix
|
||||||
\\ Suffix to append to the Lightpanda/X.Y User-Agent
|
\\ Suffix to append to the Lightpanda/X.Y User-Agent
|
||||||
|
|||||||
Reference in New Issue
Block a user