mirror of
https://github.com/lightpanda-io/browser.git
synced 2025-10-28 14:43:28 +00:00
add window.reportError
This commit is contained in:
@@ -72,7 +72,7 @@ pub const Event = struct {
|
||||
.custom_event => .{ .CustomEvent = @as(*CustomEvent, @ptrCast(evt)).* },
|
||||
.progress_event => .{ .ProgressEvent = @as(*ProgressEvent, @ptrCast(evt)).* },
|
||||
.mouse_event => .{ .MouseEvent = @as(*parser.MouseEvent, @ptrCast(evt)) },
|
||||
.error_event => .{ .ErrorEvent = @as(*ErrorEvent, @ptrCast(evt)).* },
|
||||
.error_event => .{ .ErrorEvent = (@as(*ErrorEvent, @fieldParentPtr("proto", evt))).* },
|
||||
.message_event => .{ .MessageEvent = @as(*MessageEvent, @ptrCast(evt)).* },
|
||||
.keyboard_event => .{ .KeyboardEvent = @as(*parser.KeyboardEvent, @ptrCast(evt)) },
|
||||
.pop_state => .{ .PopStateEvent = @as(*PopStateEvent, @ptrCast(evt)).* },
|
||||
|
||||
@@ -42,7 +42,7 @@ pub const ErrorEvent = struct {
|
||||
const event = try parser.eventCreate();
|
||||
defer parser.eventDestroy(event);
|
||||
try parser.eventInit(event, event_type, .{});
|
||||
parser.eventSetInternalType(event, .event);
|
||||
parser.eventSetInternalType(event, .error_event);
|
||||
|
||||
const o = opts orelse ErrorEventInit{};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ const Request = @import("../fetch/Request.zig");
|
||||
const fetchFn = @import("../fetch/fetch.zig").fetch;
|
||||
|
||||
const storage = @import("../storage/storage.zig");
|
||||
const ErrorEvent = @import("error_event.zig").ErrorEvent;
|
||||
|
||||
// https://dom.spec.whatwg.org/#interface-window-extensions
|
||||
// https://html.spec.whatwg.org/multipage/nav-history-apis.html#window
|
||||
@@ -281,6 +282,25 @@ pub const Window = struct {
|
||||
return out;
|
||||
}
|
||||
|
||||
pub fn _reportError(self: *Window, err: js.Object, page: *Page) !void {
|
||||
var error_event = try ErrorEvent.constructor("error", .{
|
||||
.@"error" = err,
|
||||
});
|
||||
_ = try parser.eventTargetDispatchEvent(
|
||||
parser.toEventTarget(Window, self),
|
||||
@as(*parser.Event, &error_event.proto),
|
||||
);
|
||||
|
||||
if (parser.eventDefaultPrevented(&error_event.proto) == false) {
|
||||
const err_string = err.toString() catch "Unknown error";
|
||||
log.info(.user_script, "error", .{
|
||||
.err = err_string,
|
||||
.stack = page.stackTrace() catch "???",
|
||||
.source = "window.reportError",
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
const CreateTimeoutOpts = struct {
|
||||
name: []const u8,
|
||||
args: []js.Object = &.{},
|
||||
|
||||
@@ -149,3 +149,19 @@
|
||||
|
||||
testing.eventually(() => testing.expectEqual(true, isWindowTarget));
|
||||
</script>
|
||||
|
||||
<script id=reportError>
|
||||
let errorEventFired = false;
|
||||
let capturedError = null;
|
||||
|
||||
window.addEventListener('error', (e) => {
|
||||
errorEventFired = true;
|
||||
capturedError = e.error;
|
||||
});
|
||||
|
||||
const testError = new Error('Test error message');
|
||||
window.reportError(testError);
|
||||
|
||||
testing.expectEqual(true, errorEventFired);
|
||||
testing.expectEqual(testError, capturedError);
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user