Lightpanda: the headless browser designed for AI and automation
debug: remove unknown property logging
Karl Seguineabc865338d7
diff --git a/src/browser/js/Snapshot.zig b/src/browser/js/Snapshot.zigindex 2d95273cf..c3afbba69 100644--- a/src/browser/js/Snapshot.zig+++ b/src/browser/js/Snapshot.zig@@ -592,14 +592,15 @@ fn collectExternalReferences() [countExternalReferences()]isize {}}- if (comptime lp.IS_DEBUG) {- inline for (JsApis) |JsApi| {- if (!hasNamedIndexedGetter(JsApi)) {- references[idx] = @bitCast(@intFromPtr(bridge.unknownObjectPropertyCallback(JsApi)));- idx += 1;- }- }- }+ // @LOG-UNKNOWN-PROPERTY+ // if (comptime lp.IS_DEBUG) {+ // inline for (JsApis) |JsApi| {+ // if (!hasNamedIndexedGetter(JsApi)) {+ // references[idx] = @bitCast(@intFromPtr(bridge.unknownObjectPropertyCallback(JsApi)));+ // idx += 1;+ // }+ // }+ // }return references;}@@ -907,22 +908,23 @@ fn attachClass(comptime JsApi: type, comptime flatten: bool, isolate: *v8.Isolatv8.v8__Template__Set(@ptrCast(instance), js_name, js_value, v8.ReadOnly + v8.DontEnum);}- if (comptime lp.IS_DEBUG) {- if (!has_named_index_getter) {- var configuration: v8.NamedPropertyHandlerConfiguration = .{- .getter = bridge.unknownObjectPropertyCallback(JsApi),- .setter = null,- .query = null,- .deleter = null,- .enumerator = null,- .definer = null,- .descriptor = null,- .data = null,- .flags = v8.kOnlyInterceptStrings | v8.kNonMasking,- };- v8.v8__ObjectTemplate__SetNamedHandler(instance, &configuration);- }- }+ // @LOG-UNKNOWN-PROPERTY+ // if (comptime lp.IS_DEBUG) {+ // if (!has_named_index_getter) {+ // var configuration: v8.NamedPropertyHandlerConfiguration = .{+ // .getter = bridge.unknownObjectPropertyCallback(JsApi),+ // .setter = null,+ // .query = null,+ // .deleter = null,+ // .enumerator = null,+ // .definer = null,+ // .descriptor = null,+ // .data = null,+ // .flags = v8.kOnlyInterceptStrings | v8.kNonMasking,+ // };+ // v8.v8__ObjectTemplate__SetNamedHandler(instance, &configuration);+ // }+ // }}// The chain of interface types reachable from a [Global] interface via WebIDLdiff --git a/src/browser/js/bridge.zig b/src/browser/js/bridge.zigindex ea5d627ce..f79297a77 100644--- a/src/browser/js/bridge.zig+++ b/src/browser/js/bridge.zig@@ -684,128 +684,132 @@ pub fn unknownWindowPropertyCallback(c_name: ?*const v8.Name, handle: ?*const v8.worker => {}, // no global lookup in a worker}- if (comptime lp.IS_DEBUG) {- if (std.mem.startsWith(u8, property, "__")) {- // some frameworks will extend built-in types using a __ prefix- // these should always be safe to ignore.- return js.Intercepted.no;- }-- const ignored = std.StaticStringMap(void).initComptime(.{- .{ "Deno", {} },- .{ "process", {} },- .{ "ShadyDOM", {} },- .{ "ShadyCSS", {} },-- // a lot of sites seem to like having their own window.config.- .{ "config", {} },-- .{ "litNonce", {} },- .{ "litHtmlVersions", {} },- .{ "litElementVersions", {} },- .{ "litHtmlPolyfillSupport", {} },- .{ "litElementHydrateSupport", {} },- .{ "litElementPolyfillSupport", {} },- .{ "reactiveElementVersions", {} },-- .{ "recaptcha", {} },- .{ "grecaptcha", {} },- .{ "___grecaptcha_cfg", {} },- .{ "__recaptcha_api", {} },- .{ "__google_recaptcha_client", {} },-- .{ "CLOSURE_FLAGS", {} },- .{ "__REACT_DEVTOOLS_GLOBAL_HOOK__", {} },- .{ "ApplePaySession", {} },- });- if (!ignored.has(property)) {- var buf: [2048]u8 = undefined;- const key = std.fmt.bufPrint(&buf, "Window:{s}", .{property}) catch return js.Intercepted.no;- logUnknownProperty(local, key) catch return js.Intercepted.no;- }- }+ // @LOG-UNKNOWN-PROPERTY+ // This was really useful when sites often broke because of an unimplemented+ // feature. But it hasnt' been useful to me in ~6 months.+ // if (comptime lp.IS_DEBUG) {+ // if (std.mem.startsWith(u8, property, "__")) {+ // // some frameworks will extend built-in types using a __ prefix+ // // these should always be safe to ignore.+ // return js.Intercepted.no;+ // }++ // const ignored = std.StaticStringMap(void).initComptime(.{+ // .{ "Deno", {} },+ // .{ "process", {} },+ // .{ "ShadyDOM", {} },+ // .{ "ShadyCSS", {} },++ // // a lot of sites seem to like having their own window.config.+ // .{ "config", {} },++ // .{ "litNonce", {} },+ // .{ "litHtmlVersions", {} },+ // .{ "litElementVersions", {} },+ // .{ "litHtmlPolyfillSupport", {} },+ // .{ "litElementHydrateSupport", {} },+ // .{ "litElementPolyfillSupport", {} },+ // .{ "reactiveElementVersions", {} },++ // .{ "recaptcha", {} },+ // .{ "grecaptcha", {} },+ // .{ "___grecaptcha_cfg", {} },+ // .{ "__recaptcha_api", {} },+ // .{ "__google_recaptcha_client", {} },++ // .{ "CLOSURE_FLAGS", {} },+ // .{ "__REACT_DEVTOOLS_GLOBAL_HOOK__", {} },+ // .{ "ApplePaySession", {} },+ // });+ // if (!ignored.has(property)) {+ // var buf: [2048]u8 = undefined;+ // const key = std.fmt.bufPrint(&buf, "Window:{s}", .{property}) catch return js.Intercepted.no;+ // logUnknownProperty(local, key) catch return js.Intercepted.no;+ // }+ // }return js.Intercepted.no;}+// @LOG-UNKNOWN-PROPERTY// Only used for debugging-pub fn unknownObjectPropertyCallback(comptime JsApi: type) *const fn (?*const v8.Name, ?*const v8.PropertyCallbackInfo) callconv(.c) u32 {- if (comptime !lp.IS_DEBUG) {- @compileError("unknownObjectPropertyCallback should only be used in debug builds");- }-- return struct {- fn wrap(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u32 {- const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;-- var caller: Caller = undefined;- if (!caller.init(v8_isolate)) {- return js.Intercepted.no;- }- defer caller.deinit();-- const local = &caller.local;-- var hs: js.HandleScope = undefined;- hs.init(local.isolate);- defer hs.deinit();-- const property: []const u8 = js.String.toSlice(.{ .local = local, .handle = @ptrCast(c_name.?) }) catch {- return js.Intercepted.no;- };-- if (std.mem.startsWith(u8, property, "__")) {- // some frameworks will extend built-in types using a __ prefix- // these should always be safe to ignore.- return js.Intercepted.no;- }-- if (std.mem.startsWith(u8, property, "jQuery")) {- return js.Intercepted.no;- }-- if (JsApi == @import("../webapi/cdata/Text.zig").JsApi or JsApi == @import("../webapi/cdata/Comment.zig").JsApi) {- if (std.mem.eql(u8, property, "tagName")) {- // knockout does this, a lot.- return js.Intercepted.no;- }- }-- if (JsApi == @import("../webapi/element/Html.zig").JsApi or JsApi == @import("../webapi/Element.zig").JsApi or JsApi == @import("../webapi/element/html/Custom.zig").JsApi) {- // react ?- if (std.mem.eql(u8, property, "props")) return js.Intercepted.no;- if (std.mem.eql(u8, property, "hydrated")) return js.Intercepted.no;- if (std.mem.eql(u8, property, "isHydrated")) return js.Intercepted.no;- }-- if (JsApi == @import("../webapi/Console.zig").JsApi) {- if (std.mem.eql(u8, property, "firebug")) return js.Intercepted.no;- }-- const ignored = std.StaticStringMap(void).initComptime(.{});- if (!ignored.has(property)) {- var buf: [2048]u8 = undefined;- const key = std.fmt.bufPrint(&buf, "{s}:{s}", .{ if (@hasDecl(JsApi.Meta, "name")) JsApi.Meta.name else @typeName(JsApi), property }) catch return js.Intercepted.no;- logUnknownProperty(local, key) catch return js.Intercepted.no;- }- return js.Intercepted.no;- }- }.wrap;-}--fn logUnknownProperty(local: *const js.Local, key: []const u8) !void {- const ctx = local.ctx;- const gop = try ctx.unknown_properties.getOrPut(ctx.arena.allocator(), key);- if (gop.found_existing) {- gop.value_ptr.count += 1;- } else {- gop.key_ptr.* = try ctx.arena.dupe(u8, key);- gop.value_ptr.* = .{- .count = 1,- .first_stack = try ctx.arena.dupe(u8, (try local.stackTrace()) orelse "???"),- };- }-}+// pub fn unknownObjectPropertyCallback(comptime JsApi: type) *const fn (?*const v8.Name, ?*const v8.PropertyCallbackInfo) callconv(.c) u32 {+// if (comptime !lp.IS_DEBUG) {+// @compileError("unknownObjectPropertyCallback should only be used in debug builds");+// }++// return struct {+// fn wrap(c_name: ?*const v8.Name, handle: ?*const v8.PropertyCallbackInfo) callconv(.c) u32 {+// const v8_isolate = v8.v8__PropertyCallbackInfo__GetIsolate(handle).?;++// var caller: Caller = undefined;+// if (!caller.init(v8_isolate)) {+// return js.Intercepted.no;+// }+// defer caller.deinit();++// const local = &caller.local;++// var hs: js.HandleScope = undefined;+// hs.init(local.isolate);+// defer hs.deinit();++// const property: []const u8 = js.String.toSlice(.{ .local = local, .handle = @ptrCast(c_name.?) }) catch {+// return js.Intercepted.no;+// };++// if (std.mem.startsWith(u8, property, "__")) {+// // some frameworks will extend built-in types using a __ prefix+// // these should always be safe to ignore.+// return js.Intercepted.no;+// }++// if (std.mem.startsWith(u8, property, "jQuery")) {+// return js.Intercepted.no;+// }++// if (JsApi == @import("../webapi/cdata/Text.zig").JsApi or JsApi == @import("../webapi/cdata/Comment.zig").JsApi) {+// if (std.mem.eql(u8, property, "tagName")) {+// // knockout does this, a lot.+// return js.Intercepted.no;+// }+// }++// if (JsApi == @import("../webapi/element/Html.zig").JsApi or JsApi == @import("../webapi/Element.zig").JsApi or JsApi == @import("../webapi/element/html/Custom.zig").JsApi) {+// // react ?+// if (std.mem.eql(u8, property, "props")) return js.Intercepted.no;+// if (std.mem.eql(u8, property, "hydrated")) return js.Intercepted.no;+// if (std.mem.eql(u8, property, "isHydrated")) return js.Intercepted.no;+// }++// if (JsApi == @import("../webapi/Console.zig").JsApi) {+// if (std.mem.eql(u8, property, "firebug")) return js.Intercepted.no;+// }++// const ignored = std.StaticStringMap(void).initComptime(.{});+// if (!ignored.has(property)) {+// var buf: [2048]u8 = undefined;+// const key = std.fmt.bufPrint(&buf, "{s}:{s}", .{ if (@hasDecl(JsApi.Meta, "name")) JsApi.Meta.name else @typeName(JsApi), property }) catch return js.Intercepted.no;+// logUnknownProperty(local, key) catch return js.Intercepted.no;+// }+// return js.Intercepted.no;+// }+// }.wrap;+// }++// fn logUnknownProperty(local: *const js.Local, key: []const u8) !void {+// const ctx = local.ctx;+// const gop = try ctx.unknown_properties.getOrPut(ctx.arena.allocator(), key);+// if (gop.found_existing) {+// gop.value_ptr.count += 1;+// } else {+// gop.key_ptr.* = try ctx.arena.dupe(u8, key);+// gop.value_ptr.* = .{+// .count = 1,+// .first_stack = try ctx.arena.dupe(u8, (try local.stackTrace()) orelse "???"),+// };+// }+// }// Given a Type, returns the length of the prototype chain, including selffn prototypeChainLength(comptime T: type) usize {