r/learnjavascript • • 5d ago

Intercepting property access (e.g., navigator.bluetooth / Object.property) directly in V8

Hey everyone,

I'm working on my master's thesis and diving into V8 internals. I want to know if there's a clean way to intercept (or log/trace) property reads on an object directly inside V8 — for example, navigator.bluetooth or basically any Object.property access.

After reading a few V8 articles (like https://v8.dev/blog/fast-properties), it seems unlikely that all of this funnels through a single C++ function, given how differently properties are represented and resolved (in-object/fast properties, dictionary mode, interceptors, accessors, ICs, JIT tiers, etc.).

Before I go any deeper down this rabbit hole, is intercepting all property accesses in one central V8 spot even realistic, or am I basically throwing peas at a wall?

Thanks for any tips!

5 Upvotes

6 comments sorted by

2

u/androbat 4d ago edited 4d ago

Will proxies around them do what you want?

2

u/Upstairs-Concert5800 4d ago

Not totally, I dont want to do that in the JS execution time, but rather in the V8 engine.

1

u/GiggleSamurai 4d ago

For Web APIs like navigator.bluetooth you don't need V8 internals: they're accessor properties generated from Blink's IDL bindings, so hook the generated getters there (Chromium already does this for its use counters with the [Measure]/[MeasureAs] IDL attributes). For arbitrary JS properties there's no single spot, because inline caches and optimized code read fields straight from the object without calling into the runtime.

1

u/Upstairs-Concert5800 4d ago

Hey thanks for the answer, so lets say I want to capture all navigator.something accesses, so it is necessary to check IDL files if there are [Measure] parameters? e.g. https://github.com/chromium/chromium/blob/main/third_party/blink/renderer/core/frame/navigator.idl and then I can see those at chrome://histograms/Blink.UseCounter.Features ?

1

u/Greedy_Ad_7658 3d ago

Adding to the "no single spot" answer with where the closest thing to a central spot actually is: the Ignition interpreter. Every unoptimized named property read compiles to a LdaNamedProperty bytecode (or the NoFeedback variant), and those have single handlers in the interpreter, generated from interpreter-generator.tq. People doing dynamic analysis on V8 usually hook there, or start cheaper by running with --trace-ic to watch the IC feedback evolve per access site.

The catch is what happens next. Once the ICs warm up and TurboFan optimizes the function, a monomorphic property load gets lowered to a map check plus a plain memory read at a fixed offset. The "property access" stops existing as an operation, so any central hook silently sees less and less as code tiers up. For a thesis that is actually a nice result to demonstrate rather than a failure: run the same workload with --no-opt versus default and show how much of the access stream disappears from your hook as optimization kicks in.

Practical tip: build d8 and experiment there instead of full Chrome. You get the useful flags (--trace-ic, --print-bytecode, --allow-natives-syntax with %DebugPrint to inspect maps and hidden classes) without building Blink. Blink only matters for the navigator.* side, and there the IDL/[Measure] route from the other answer is the right one.

1

u/Upstairs-Concert5800 3d ago

Thanks for the great answer! I did not completely understand all of it, but I will definitely try to dig into it more. My scenario is this: I have some JavaScript running on a page that inspects navigator properties, window.something, canvas/WebGL/audio APIs, and other browser attributes (related to fingerprinting). I am trying to do it on the V8 level, not in the JS level in the browser.