How Shape Security's JavaScript VM Works▋
Shape Security’s anti-bot script runs its logic as bytecode on a custom VM. The dispatch loop is written in WebAssembly, and the instructions themselves are JavaScript functions.
We’ve been writing a decompiler for it, and the examples here come from that work. If you’ve read our post on writing a register VM in Go, two of the ideas listed at the end of it, opcode permutation and super-operators, are both used here.
Every name, offset and number below comes from one build of the script, so treat them as examples rather than constants.
Key Takeaways
- The dispatch loop is WebAssembly; the instruction semantics are 194 JavaScript handlers it calls through a function table.
- Each opcode byte is decoded through one of 10 permutation tables, and every instruction picks the table for the next one, so you can’t decode a byte without knowing how execution reached it.
- Handlers are fused (one handler does a string decode, a stack read and a
defineProperty), so there’s no one-to-one mapping from opcode to operation.- Some branches test conditions that always come out the same way, and the code on the side that never runs writes over live instructions. A disassembler that follows both sides of every branch decodes code that never runs.
- Once decompiled, the bytecode’s checks read as plain JavaScript. One logs an
Errorwith astackgetter to spot an attached inspector, which no longer fires in current Chrome; another readsProxy.toStringfrom a stack trace to tell whetherwindowornavigatoris aProxy.- The collectors hold some odd details, including a timestamp matching the Hiroshima bomb, a fake
lavc1337codec, a misspelledHelkevtricafont and emoji read back one pixel at a time.
What’s in the script
The file is about 347 KB on a single line. Pretty-printed and with its inline string decoding folded into a helper, it’s around 4,200 lines, and all of it lives inside one function:
(function n(Xn, Q, P, D) {
// ... the whole VM ...
C(Q, P, null, D, [], [], void 0, void 0)();
})(typeof window !== "undefined" && window != null && window.window === window ? window : typeof global !== "undefined" && global != null && global.global === global ? global : this, 0, 0, [1, 2, 0, 3]);
The four parameters are the global object, the program counter to start at, the starting state (more on that shortly), and the scope slots the first routine gets. C makes a JavaScript function that runs bytecode from that pc and state, and the trailing () calls it. Unless we say otherwise, the snippets in this post come from that pretty-printed version, which also drops copies of parameters like var m = H;.
The script’s own names are one or two letters. We show the first two snippets, and handler 6 later on, with both those names and readable ones; everywhere else we only use readable names. The names are ours, picked from what each identifier does; otherwise the code is only lightly tidied, and does the same thing. Here’s the outer function again:
(function vm(global, entryPc, entryState, entryFresh) {
// ... the whole VM ...
makeRoutine(entryPc, entryState, null, entryFresh, [], [], void 0, void 0)();
})(globalObject, 0, 0, [1, 2, 0, 3]); // globalObject: window, global or this, as above
The main parts inside n:
| Name | Readable name | What it is |
|---|---|---|
v | constants | The constant table: 1,451 strings, plain ones like "addEventListener" mixed with base64 halves of encrypted ones |
XW | descriptors | 655 closure descriptors, describing the scope of each function the bytecode can create |
XN | Scope | The scope: an array of cells, { v: value } |
Xy | Frame | A frame: operand stack lk, exception stack m, pc H, state I, scope D |
XU | handlers | 194 handler functions, each taking a frame plus operands |
C | makeRoutine | Makes the JavaScript function for a routine |
R | memory | A 3-page WebAssembly.Memory the bytecode is decoded into |
two WebAssembly.Modules | One imports the 194 handlers and exports them as a function table; the other is the dispatch loop |
The bytecode itself is a base64 string the script decodes straight into the WebAssembly memory with XS("...", new Uint8Array(R.buffer)), where XS is its base64 decoder. It’s 174,507 bytes: code from offset 0, a pool of 159 doubles at 168,695, and the opcode tables at the end.
How an instruction runs
A frame runs when JavaScript calls the dispatcher’s exported function o(pc, state, frame):
var Xj = function(m) {
var X = (0, J.exports.o)(m.H, m.I, m);
switch (X) {
case 0: { return; }
case 1: { return m.lk.lb(); } // pop the return value off the operand stack
}
};
With readable names (J is the dispatcher’s WebAssembly.Instance):
var runFrame = function(frame) {
var result = (0, dispatcher.exports.run)(frame.pc, frame.state, frame);
switch (result) {
case 0: { return; }
case 1: { return frame.stack.pop(); }
}
};
From there, everything happens inside one WebAssembly loop. These are the first instructions of that loop, decoded from the module’s bytes:
loop
i32.const 169967 ;; base of the opcode tables
local.get 1 ;; state
i32.const 454 ;; 227 entries x 2 bytes per state
i32.mul
local.get 0 ;; pc
i32.load8_u ;; the opcode byte at pc
local.tee 3
i32.const 1
i32.shl
i32.add
i32.add
local.tee 31 ;; entry = 169967 + state * 454 + byte * 2
i32.load8_u
local.set 3 ;; op = mem[entry]
local.get 31
i32.load8_u offset=1
local.set 1 ;; state = mem[entry + 1]
Then a br_table with 227 targets jumps to the code for op.
The byte at pc indexes one of 10 tables, and the state picks which. Each table is a permutation of the 227 operations, and each entry also says which state the next instruction is decoded in. Here’s what the byte 0x05 means in each state in this build:
| State | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 |
|---|---|---|---|---|---|---|---|---|---|---|
| Op | 193 | 126 | 197 | 196 | 167 | 200 | 31 | 181 | 157 | 47 |
| Next state | 3 | 3 | 1 | 5 | 1 | 4 | 8 | 6 | 8 | 9 |
Most branch and jump instructions encode a state alongside the target pc, so the state is known where they land. The exception is a jump to a pc and state popped off the operand stack, which comes up below.
What the 227 operations are
Ops 0 to 193 call a JavaScript handler: handlers[op](frame, operands...), through the function table the other module exports. Each op’s case in the loop reads its operands at fixed offsets as 1, 2 or 3-byte integers and moves the pc on by a fixed amount.
Ops 194 to 226 are handled in the loop itself, some with a small imported helper:
- push a literal:
{},[],true,false,undefined,nullorInfinity - push a number, either from the operand bytes or from the double pool (
f64[168695 + u8 * 8]) - branch on a popped value, jump, or jump to a pc and state popped off the operand stack
- open and close
tryblocks, and keepfinallybookkeeping - call and return from subroutines (a gosub, with the return pc and state kept in WebAssembly locals)
- return from the routine
- write a byte into memory:
mem[u24] = u8
The last one lets the bytecode modify itself. We’ll come back to it.
The double pool holds 159 numbers. The first three are 3814355952, 9007199254740991 (Number.MAX_SAFE_INTEGER) and 101.2. 89 of the 159 are integers between 2^24 and 2^32, the size you’d expect of 32-bit hash constants, and 61 are decimals.
The handlers are fused
Most handlers do several things at once. This is handler 6 as it appears in the original script:
function(X,n,H){var x=v[n];var a=H;b1:{var V=x;var O=V+","+a;var u=b[O];if(typeof u!=="undefined"){var h=u;break b1}var e=v[a];var m=XS(e);var W=XS(V);var t=m[0]+W[0]&255;var K="";for(var J=1;J<m.length;++J){K+=Xt(W[J]^m[J]^t)}var h=b[O]=K}var j=null;var r=X.lk[X.lk.length-1];Xh(r,h,{writable:true,configurable:true,enumerable:true,value:j});X.lk[X.lk.length-1]=r}
And the same handler with its string decode folded into a helper and readable names:
function defineNullProperty(frame, maskIndex, dataIndex) {
var name = decodeString(constants[maskIndex], dataIndex);
var target = frame.stack[frame.stack.length - 1];
Object.defineProperty(target, name, {
writable: true,
configurable: true,
enumerable: true,
value: null
});
frame.stack[frame.stack.length - 1] = target;
}
It decrypts a property name from two constant-table entries, then defines that property with the value null on the object at the top of the stack. Other handlers read a scope slot, store into a property and push two values in one go. There’s no table that maps opcode 6 to a single operation; you have to read each handler’s body to work out what it does to the stack, the scope and anything outside the VM.
Strings are encrypted in pairs
All 29 inline string decodes in the handlers use the same algorithm. Both inputs are base64 strings from the constant table: one is the data, the other a mask at least as long. As a standalone function:
function decodeString(key, index) {
var cacheKey = key + "," + index;
var cached = cache[cacheKey];
if (typeof cached !== "undefined") {
return cached;
}
var data = base64Decode(constants[index]);
var mask = base64Decode(key);
var seed = data[0] + mask[0] & 255; // + binds tighter than &
var text = "";
for (var i = 1; i < data.length; ++i) {
text += String.fromCharCode(mask[i] ^ data[i] ^ seed);
}
return cache[cacheKey] = text;
}
The first byte of each half makes the seed, and every character is the XOR of the mask byte, the data byte and the seed. Here’s one worked through. The data is constants[900], "BHSXCeFtusCbWQ", and the mask is constants[449], "ZXqRB9Jnlcq/fR8":
data 04 74 97 09 e1 6d ba c0 9b 59
mask 65 7a 91 07 d2 67 95 ca bf 7d 1f
seed (0x04 + 0x65) & 255 = 0x69
0x7a ^ 0x74 ^ 0x69 = 0x67 "g"
... "gogZcFcMM"
gogZcFcMM is the name of the event the VM uses to pass its result back to the page’s loader script. The loader contains it as plain text; the VM script only contains the two encoded halves.
Property stores are strict
Eight handlers assign a property, and one deletes one. All nine start with "use strict", and no other handler does:
function setProperty(frame) {
"use strict";
var stack = frame.stack; // [..., object, key, value]
stack[stack.length - 3][stack[stack.length - 2]] = stack[stack.length - 1];
stack.length -= 3;
}
In sloppy mode, assigning to a read-only property or to a property of a primitive fails silently; in strict mode it throws a TypeError. A failed delete behaves the same way, so every failed property assignment or delete in the VM throws.
Scopes, frames and closures
The bytecode keeps its variables in cells:
function Scope() {
this.cells = [];
}
// declare(slot) this.cells[slot] = { value: void 0 };
// get(slot) return this.cells[slot].value;
// set(slot, value) this.cells[slot].value = value;
// clone() copy.cells = [].slice !== slice ? uncurriedSlice(this.cells, 0) : this.cells.slice(0);
Cloning a scope copies the array that holds the cells, and the cell objects themselves are shared. Two scopes that share a cell object see each other’s writes; a cell declared after the clone belongs to one scope only. Closures are built on this.
Each closure descriptor in descriptors looks like { C: [2], G: [2, 4], N: [0, 1, 3, 13, 17, 21, 31] }, with optional j and P slots:
N: captured slots. When the closure is made, those cells are copied by reference from the maker’s scope.G: slots each call gets fresh cells for.C: parameter slots, filled fromarguments.j: a slot set to the call’sargumentsobject.P: a slot holding the function itself, so its code can refer to itself.
The function the VM hands out is below. Its free variables are the parameters of the function that builds it, B(pc, state, closureScope, freshSlots, parameterSlots, hasArgumentsSlot, argumentsSlot), and parameterCount is parameterSlots.length:
var closure = function() {
"use strict";
var scope = closureScope.clone();
var frame = new Frame(pc, state, scope, this);
var i, count, passed = Math.min(arguments.length, parameterCount);
if (hasArgumentsSlot) {
scope.declare(argumentsSlot);
scope.set(argumentsSlot, arguments);
}
for (i = 0, count = freshSlots.length; i < count; ++i) {
scope.declare(freshSlots[i]);
}
for (i = 0; i < passed; ++i) {
scope.set(parameterSlots[i], arguments[i]);
}
for (i = passed; i < parameterCount; ++i) {
scope.set(parameterSlots[i], void 0);
}
return runFrame(frame);
};
This behaves the same as a JavaScript closure: captured variables are shared with the enclosing function, and locals are new on each call. In compiler terms these are flat closures over boxed variables, as described by Luca Cardelli (“Compiling a Functional Language”, 1984) and Kent Dybvig (“Three Implementation Models for Scheme”, 1987). Because the behaviour matches, each routine can be decompiled into a nested JavaScript function.
The frame stores this in two forms:
function Frame(pc, state, scope, thisValue) {
this.stack = newStack();
this.exceptions = newStack();
this.state = state;
this.pc = pc;
this.scope = scope;
this.sloppyThis = thisValue == null ? global : Object(thisValue);
this.rawThis = thisValue;
}
The closure is strict, so it receives this exactly as passed. Handlers that read this use one of the two: rawThis as passed, or sloppyThis, the value a non-strict function would see (undefined and null become the global object, primitives become objects). That lets the bytecode reproduce either mode’s this, even though the closure itself is always strict.
Builtins are copied at load
The first statement inside the outer function copies the builtins the VM uses:
var bind = Object.bind, call = Object.call, uncurryThis = call.bind(bind, call), apply = Object.apply, uncurriedApply = uncurryThis(apply), push = [].push, /* ... */ slice = [].slice, /* ... */ uncurriedPush = uncurryThis(push), uncurriedSlice = uncurryThis(slice), /* ... */ min = Math.min, /* ... */;
uncurryThis(f) evaluates to Function.prototype.call.bind(f), a function where uncurryThis(f)(obj, a, b) is f.call(obj, a, b). uncurriedPush pushes onto any array without looking up push at call time, so a page script that replaces Array.prototype.push after the VM loads can’t intercept it. The scope clone shown earlier checks for this too: [].slice !== slice ? uncurriedSlice(this.cells, 0) : this.cells.slice(0) uses the copied slice if the live one has been replaced.
The VM’s own stacks get the same treatment. newStack, which makes the operand and exception stacks, returns a plain array with the copied pop, push, slice and splice attached as its own non-enumerable properties (lb, lu, lT and lf in the script), so frame.stack.pop() is the original Array.prototype.pop whatever the page has done since.
Exception handling
The dispatcher uses no WebAssembly exception-handling instructions, so a JavaScript exception thrown inside a handler would unwind straight through the loop and out of o. The VM catches exceptions in JavaScript instead, and leaves a flag for the loop to check.
When bytecode opens a try, the loop stores the handler’s pc and state in its own locals (up to three deep). While one is open, handlers aren’t called through the table; they’re called through one of five imports that are all the same wrapper:
var callInTry = function(frame, a, b, c, d) {
"use strict";
try {
handlers[arguments[arguments.length - 1]](frame, a, b, c, d); // the op number is passed as the last argument
} catch (error) {
(0, dispatcher.exports.setThrown)(); // set the dispatcher's "thrown" flag
frame.exceptions.push(error); // push the exception onto the frame's exception stack
}
};
After each call, the loop checks the flag. If it’s set, the loop clears it, restores the pc and state of the innermost handler and carries on from there. The catch block pops the exception off the frame’s exception stack into a scope slot. finally is bookkeeping on top: counters in locals, a helper that trims the exception stack, and another that rethrows.
There are no try statements in the bytecode to read off. A decompiler has to work out which instructions run while each handler is installed.
Code that runs in a Web Worker
Some routines run in a Web Worker rather than on the page. Handler 141 sends work to it:
function callInWorker(frame, descriptor) {
var stack = frame.stack; // [..., state, pc, argument, callback]
if (!startWorker()) {
stack[stack.length - 4] = false;
stack.length -= 3;
return;
}
workerCallbacks.push(stack[stack.length - 1]);
worker.postMessage([stack[stack.length - 4], stack[stack.length - 3], stack[stack.length - 2], descriptor]);
stack[stack.length - 4] = true;
stack.length -= 3;
}
startWorker starts the worker the first time it’s called, and the worker’s source is the VM itself:
var source = "(" + vm + ")(self," + 18502 + "," + 3 + "," + JSON.stringify(descriptors[214].G) + ")";
var blob = new Blob([source], { type: "application/javascript" });
worker = new Worker(URL.createObjectURL(blob));
worker.onmessage = function(event) {
workerCallbacks[event.data.a](event.data.b);
};
"(" + vm + ")" stringifies the whole outer function, so the worker runs the same VM, started at a different pc and state: 18502 and 3 instead of 0 and 0. That entry point sets self.onmessage. In this build the page posts [3, 83556, argument, 157]: a state, a pc, a value and a closure descriptor. The worker numbers the call, builds a closure from those values and calls it, and the answer comes back as { a: callIndex, b: result }, which worker.onmessage passes to the callback the page kept.
The closure’s pc, state and descriptor come from the message, so a disassembler has to carry the posted values across to the worker to find that routine.
Why it’s hard to analyse
You can’t disassemble it linearly, because a byte is only an opcode once you know the state, and the state comes from the instruction before it or from the branch that jumped there. You have to follow control flow from the entry points, carrying the state, which means you need to know where every branch and jump goes before you can decode its target. The computed jump makes that harder. It pops a pc and a state off the operand stack, so you have to track the stack to know where each of its 2,675 live uses goes.
Control flow and semantics are also in different languages. The loop, the opcode tables, branching, try and subroutines are WebAssembly, and what the instructions do is JavaScript, so understanding one instruction means reading both.
Subroutines are shared. The live code has 9,915 gosub calls. The most used subroutine is called from 319 places across the program, and another is called from 75 places inside a single routine. If a return is treated as a jump to an unknown address, the control flow of all those callers merges together.
This build has 656 routines and 59,129 distinct instructions.
Techniques it uses
Conditions that are always true or always false
In this build, 102 tests only ever go one way. 61 of them guard code that never runs, and nearly all of those test literals the bytecode pushed just before, under ordinary JavaScript rules:
if (null) { /* never */ }
typeof null === "object" // always true
typeof (x + "str") === "string" // never false: string + x is a string, or it throws
typeof (a + b) !== "function" // always true
3 === 2 // always false
undefined != null // always false
+ always returns a string, a number or a BigInt, so a typeof of a sum can never be "function". A tool that doesn’t evaluate these conditions has to treat both sides as reachable.
Dead code that writes into live code
If you decode the code on the side that never runs as if it could run, it reads or pops below the bottom of the operand stack, and some of it writes into the bytecode.
The byte-write op stores one byte to an address given in its operands. The live program has 781 of them, and every one writes back the byte that’s already there, so in practice they never change anything. A tool still has to handle them to know that. Nine writes in the dead code put different values over live instructions: five over opcodes and four over operands, two of those inside gosub target addresses.
One of them writes 148 to address 37490. At 37490 there’s a 37, and the instruction there is decoded in state 6, where 37 is op 199: a conditional branch. In state 6, 148 is op 107, a JavaScript handler, which then decodes the next instruction in state 8 instead of wherever the branch would have gone.
A disassembler that follows both sides of every branch walks into this code. If it applies the writes, it corrupts opcodes the live code uses. If it ignores them, it still treats code that pops below the bottom of the stack as part of the program. Either way, what it decodes isn’t the program that runs. You have to know which way each test goes, so the disassembler has to evaluate the bytecode as it walks it, at least the parts that decide control flow.
The decompiled output
Here’s the entry routine, the one the outer call starts at pc 0, state 0, decompiled. The body of the large routine it calls is cut out (it’s about 38,900 lines):
function main() { // 0:0
let v0, v1, v2, v3;
v0 = document.createEvent("CustomEvent");
let t0 = [];
v3 = (function (v281) { // 51696:9
/* ... builds the object the loader receives ... */
})((this == null ? globalThis : Object(this)));
Object.defineProperty(t0, 0, {writable: true, configurable: true, enumerable: true, value: "gogZcFcMM"});
v1 = t0;
let t1 = 0;
L1: for (;;) {
v2 = t1;
if (t1 < v1.length) {
v0.initCustomEvent(v1[v2], false, false, v3);
dispatchEvent(v0);
t1 = Number(v2) + 1;
continue L1;
} else {
return;
}
}
}
The VM builds its result object, then dispatches it on the page as the detail of a CustomEvent named gogZcFcMM. The loader script that injected the VM listens for that event name; it stops the event’s propagation and calls e.detail.init(...). The gogZcFcMM here is the decoded string from the worked example earlier.
Some notes on reading it. vN names are scope cells (slot N), and tN names are values that only ever lived on the VM’s operand stack or inside a handler. The (this == null ? globalThis : Object(this)) argument is the sloppyThis form of this from earlier. And in t1 = Number(v2) + 1, the bytecode converts the loop counter with Number() before adding, as i++ would, so a string counter can’t turn the + into concatenation.
Closures come out as nested functions. The descriptor’s parameter slots become the function’s parameters, the arguments slot becomes let vN = arguments;, and the self slot becomes the function’s name. This is a polyfill for Object.assign from inside that large routine:
v430 = function (v4) { // 20455:9
let v1 = arguments;
let v0, v2, v3, v5, v6, v7, v8, v9, v10;
let t0 = Object.assign;
v8 = t0;
if ((typeof t0) === "function") {
return v8.apply(Object, v1);
} else {
if (null == v4) {
throw new TypeError("Cannot convert undefined or null to object");
} else {
v8 = Object(v4);
// ... copy own enumerable properties from each source ...
}
}
};
Two checks from the decompiled code
With the bytecode decompiled, the checks it runs in the browser can be read as ordinary JavaScript. Here are two of them. The snippets below are tidied further than the output above: names are ours, object and array literals built with Object.defineProperty are written as literals, the code that encodes each result into the VM’s output is replaced with a comment, and work unrelated to the check is left out. The browser results are from Chrome 156 unless we say otherwise.
Detecting an attached inspector with a stack getter
This check is in routine 120482:6. It’s one of the callbacks of a larger routine (113014:3) that groups several automation checks; the others look for Selenium IDE’s prompt.js extension scripts and watch document.body for its sideexplayingflag attribute.
let flags = [false, false, false];
let console = window.console;
let error = new Error();
error.name = "";
Object.defineProperty(error, "stack", {
get: function () {
flags[0] = true;
// encode flags into the output
return "";
}
});
console.log(error);
if ("__sentry_original__" in console.log) {
let original = console.log.__sentry_original__;
if (typeof original === "function") {
original.call(console, error);
flags[1] = true;
}
}
// encode flags into the output
This only runs if window.console exists. new Error() already gives the error a configurable own stack, so defineProperty swaps in the getter and stack stays non-enumerable and configurable. The flags are encoded into the output three times: just before the error is made, from inside the getter if it runs, and after the console.log calls.
A sibling callback of 113014:3, routine 17753:9, sets the third flag. It runs the same trick in a hidden iframe. It logs another Error through iframe.contentWindow.console.log, and that error’s stack getter sets flags[2].
With no inspector attached, console.log in Chrome doesn’t read the error’s stack. We ran the same code in Chrome with nothing attached and the getter ran 0 times.
The check relies on how older versions of V8 behaved. When an inspector client enabled the DevTools Protocol’s Runtime domain, V8 sent every console call to that client, and to describe an Error argument it read stack, which ran the getter. DevTools enables Runtime when it opens. Automation libraries that drive Chrome over the DevTools Protocol, such as Puppeteer and Playwright, send Runtime.enable as well.
You can still see that behaviour in Node 24, which ships V8 13.6. This connects an in-process inspector session and counts how often the getter runs during console.log:
const inspector = require("inspector");
function probe() {
let reads = 0;
const error = new Error();
error.name = "";
Object.defineProperty(error, "stack", { get() { reads++; return ""; } });
console.log(error);
return reads;
}
probe(); // 1: Node's own console formats the error
const session = new inspector.Session();
session.connect();
session.post("Runtime.enable", () => {
probe(); // 2: the inspector reads it as well
});
Node’s console formats the error itself, so it reads stack once with no inspector. After Runtime.enable it’s read twice per call: once by Node’s console and once by the inspector. After Runtime.disable it goes back to once.
On a V8 like that, flags[0] doesn’t distinguish DevTools from an automation client. It isn’t specific to an inspector either, because a page’s own console.log wrapper that reads stack sets it with nothing attached.
Current Chrome no longer runs the getter. V8 changed the inspector in May 2025 to avoid running user code during object preview. In Chrome 146 and 156, with Runtime enabled over the protocol, the console event still arrives but the getter runs 0 times, and the preview lists stack only as an accessor. Chrome 156 with DevTools open also gives 0. The script still ships the check, so on these versions flags[0] stays false when an inspector attaches. The inspector still reads other properties. In Chrome 156 an error’s name getter ran once with no inspector and twice with Runtime enabled.
Sentry’s browser SDK wraps console methods to record breadcrumbs, and keeps the function it replaced on the wrapper as __sentry_original__. If the VM finds one, it calls the original with the same error and sets flags[1], so the result also carries whether the page’s console.log was a Sentry wrapper.
Detecting a proxied window or navigator
This check is in routine 92737:6, a callback of routine 117672:7. The same callback also counts wheel events and times an XMLHttpRequest. Date and navigator are read from window when 117672:7 runs.
let Date = window.Date;
let navigator = window.navigator;
let flags = [false, false];
try {
Date.prototype.toString.call(window);
} catch (error) {
let stack = error.stack == null ? undefined : error.stack.toString();
if ((stack && stack.indexOf("Proxy.toString") >= 0) ||
(error.message && error.message.indexOf("incompatible Proxy") >= 0)) {
flags[0] = true;
}
}
try {
Date.prototype.toString.call(navigator);
} catch (error) {
let stack = error.stack == null ? undefined : error.stack.toString();
if ((stack && stack.indexOf("Proxy.toString") >= 0) ||
(error.message && error.message.indexOf("incompatible Proxy") >= 0)) {
flags[1] = true;
}
}
if (!flags[1] && typeof window.structuredClone === "function") {
try {
window.structuredClone(navigator);
} catch (error) {
if (error.message && error.message.indexOf("#<Navigator>") >= 0) {
flags[1] = true;
}
}
}
// encode flags into the output
Date.prototype.toString throws a TypeError for anything that isn’t a Date, so both calls always throw. The VM only looks at what the error says.
When a built-in method throws, V8 names its stack frame after the receiver’s type. For a Proxy receiver, the type is Proxy, whatever the proxy wraps:
| Call | Second line of error.stack |
|---|---|
Date.prototype.toString.call(window) | at toString (<anonymous>) |
Date.prototype.toString.call(new Proxy(window, {})) | at Proxy.toString (<anonymous>) |
Date.prototype.toString.call(navigator) | at Navigator.toString (<anonymous>) |
Date.prototype.toString.call(new Proxy(navigator, {})) | at Proxy.toString (<anonymous>) |
The message doesn’t change. For window it’s Method Date.prototype.toString called on incompatible receiver #<Window> whether or not it’s a Proxy, so in Chrome only the stack shows the difference.
Other ways of inspecting a Proxy that forwards to the real navigator mostly give the same answers as the real object. With a get trap that calls Reflect.get on the target, instanceof Navigator is true, Object.prototype.toString returns "[object Navigator]", and every property the trap doesn’t change has its real value. proxy.javaEnabled() is different and throws Illegal invocation, unless the trap binds the method to the target. window.navigator is a configurable accessor, so a script can replace it with such a Proxy to change a few properties. window can’t be replaced from a page, but it can be a Proxy when the script runs in an environment that provides its own global object.
The "incompatible Proxy" test is on the message, not the stack. Chrome’s message names the target’s type, so it never matches there. In Firefox 153, Date.prototype.toString.call(new Proxy(navigator, {})) throws Date.prototype.toString called on incompatible Proxy, which is the text this test looks for. The real window gets the same message in Firefox, so flags[0] is set there with no page-made Proxy involved.
If the stack test didn’t flag navigator, the VM tries to clone it. Navigator can’t be cloned, so this throws a DataCloneError either way, but the message depends on what was passed:
| Call | Message ends with |
|---|---|
structuredClone(navigator) | Navigator object could not be cloned. |
structuredClone(new Proxy(navigator, {})) | #<Navigator> could not be cloned. |
structuredClone(new Proxy({}, {})) | #<Object> could not be cloned. |
The real object gets Blink’s message for a platform object. The Proxy gets V8’s message, which prints the target’s class as #<Navigator>. Finding #<Navigator> in the message therefore means navigator is a Proxy, and the VM sets flags[1].
A page script can still interfere with this check. The VM reads window.Date, Date.prototype.toString and window.structuredClone live, and V8 lets a script change the stack trace. With Error.stackTraceLimit = 0 the trace has no frames, so Proxy.toString never appears, and Error.prepareStackTrace can return any string. The clone message doesn’t depend on the trace, so setting the limit to 0 doesn’t hide a proxied navigator from the structuredClone test.
Odd things in the collectors
Much of the decompiled code gathers facts about the browser. As above, the snippets are tidied and the encoding is replaced with a comment.
A date from 1945
Two routines, 110554:9 and 109103:0, add the same string to their output:
new Date(-770172240000).toString();
// encode the string into the output
Read in Japan’s time zone, that’s a very specific moment:
Mon Aug 06 1945 08:16:00 GMT+0900 (Japan Standard Time)
The US National Park Service times the detonation over Hiroshima at 8:16:02 that morning. The code doesn’t say why it uses this date, but a whole-minute timestamp two seconds from the detonation would be an odd coincidence.
An old date also exposes time zone history. toString() applies the time zone rules in force on that date, and browsers ship the history of those rules. Zones that share an offset today can be hours apart in 1945:
| Zone | January 2026 | 6 August 1945 |
|---|---|---|
Europe/Berlin | GMT+01:00 | GMT+03:00 |
Europe/Paris | GMT+01:00 | GMT+02:00 |
Africa/Lagos | GMT+01:00 | GMT+01:00 |
Asia/Hong_Kong | GMT+08:00 | GMT+09:00 |
Australia/Perth | GMT+08:00 | GMT+08:00 |
Asia/Ulaanbaatar | GMT+08:00 | GMT+07:00 |
Hong Kong’s GMT+09:00 is the Japanese occupation, and Berlin’s GMT+03:00 is wartime double summer time. In Node 24, the 418 time zones give 37 different offsets in January 2026, but 104 different combinations once the 1945 offset is added. Anything faking a time zone by patching Date in JavaScript would have to reproduce that history too.
A codec and a font that don’t exist
Routine 136714:9 asks a <video> element about 34 media types, and most are ordinary. Some aren’t real:
| Type | canPlayType in Chrome |
|---|---|
video/mp4; codecs="avc1.42E01E" | probably |
video/mp4; codecs="lavc1337" | empty string |
video/mp4; codecs="hvc1x" | empty string |
audio/webz | empty string |
lavc is the name used by FFmpeg’s libavcodec, and 1337 is the joke you’d expect. The font list does the same thing. It has 47 names, and the last is a misspelling of Helvetica:
const fonts = ["Andale Mono", "Arial Narrow", /* ... */ "Wingdings 3", "Helkevtrica"];
ctx.font = "50px sans-serif";
const sansWidth = ctx.measureText("0-_{w.").width;
ctx.font = "50px serif";
const serifWidth = ctx.measureText("0-_{w.").width;
for (const font of shuffled(fonts)) {
ctx.font = `50px '${font}', sans-serif`;
let found = ctx.measureText("0-_{w.").width !== sansWidth;
if (!found) {
ctx.font = `50px '${font}', serif`;
found = ctx.measureText("0-_{w.").width !== serifWidth;
}
results[i++] = found ? 2 : 1;
}
If the text’s width changes, the font must be installed. In Chrome, Helkevtrica gives exactly the fallback widths, 136.2 for sans-serif and 136.0 for serif, while Verdana gives 175.4. Neither fake should ever come back positive, so a browser that claims to play lavc1337 or to have Helkevtrica is probably saying yes to everything, or adding noise to its measurements.
Reading emoji one pixel at a time
Routine 66389:3 draws 21 emoji one at a time and reads back two pixels from each:
for (const [emoji, points] of emojis) { // ["👨🚀", [[53, 46], [55, 42]]], ...
canvas.width = canvas.height = 96;
const ctx = canvas.getContext("2d", { willReadFrequently: true });
ctx.font = "94px sans-serif";
ctx.fillStyle = "#000";
ctx.fillText(emoji, -1, 96);
for (const [x, y] of points) {
const [r, g, b, a] = ctx.getImageData(x, y, 1, 1).data;
// encode the pixel into the output
}
}
Each vendor draws its own emoji and changes the artwork between releases, so a few pixels can point to the operating system and how up to date it is. Faking them would take the real font. The list includes very recent emoji: was added in Unicode 16 and in Unicode 17, so a system without them draws something else.
Four entries, including those two, end in a stray zero width joiner with nothing to join. In Chrome the three we tried (🚵, and ) gave the same pixels with or without it, so we don’t know what it’s for. Routine 118133:5 is a second, smaller version: eight emoji, one colour channel of one pixel each, with the flag of England in there twice.
An open-source incognito check
Routine 46278:3 tries to detect private browsing, and it lines up with an older version of the open-source detectIncognito library. This is the Chromium branch:
if (navigator.vendor.indexOf("Google") === 0 && eval.toString().length === 33) {
let browser = "E";
if (navigator.userAgent.match(/Chrome/)) {
if (navigator.brave !== undefined) browser = "A";
else if (navigator.userAgent.match(/Edg/)) browser = "B";
else if (navigator.userAgent.match(/OPR/)) browser = "C";
else browser = "D";
}
navigator.webkitTemporaryStorage.queryUsageAndQuota((usage, quota) => {
const limit = performance.memory?.jsHeapSizeLimit ?? 1073741824;
report({ a: quota < limit, b: browser });
});
}
The library’s Brave, Edge, Opera, Chrome and Chromium names have become the letters A to E. Incognito windows get a smaller storage quota, which is what quota < limit tests. Another branch tries to store a Blob in IndexedDB and looks for the error BlobURLs are not yet supported, the same test the library uses for Safari.
Looking for recorders
Alongside the usual names, such as chromedriver’s $cdc_asdjflasutopfhvcZLmcfl_ and PhantomJS’s callPhantom, the script looks for some less obvious tools. Routines 18254:8 and 17753:9 check for browser recording extensions built on SideeX:
const found = document.querySelectorAll(
"script[src^=chrome-extension][src$=prompt\\.js], script[src^=moz-extension][src$=prompt\\.js]"
).length !== 0 || /from-page-runscript/.test(window.error);
new MutationObserver(() => { playing = true; })
.observe(document.body, { attributes: true, attributeFilter: ["sideexplayingflag"] });
These match the source of Katalon Recorder, which is derived from SideeX. It ships page/prompt.js, labels messages from its runScript command from-page-runscript, and checks for a SideeXPlayingFlag attribute on the body. The observer waits for that attribute to appear, so it would catch a recorder as it starts replaying.
Routine 91671:6 has a list with a single entry, "Sequentum", which shares its name with a web scraping vendor. The check is "Sequentum" in window.external.
The canvas fallback
The canvas check in routine 78124:9 draws Hel$&?6%){mZ+#@, and routine 30014:6 draws the same text with a 👺 on the end. The first sends the start of the image’s data URL along with a hash:
try {
ctx.font = "18pt Sans";
ctx.textBaseline = "top";
ctx.fillText("Hel$&?6%){mZ+#@", 2, 2);
const url = canvas.toDataURL("image/png");
// encode url.slice(0, 50), a hash of url and the time taken
} catch {
// encode this string and the number 92629711
"data:image/png;base64,____________SAFE____________";
}
If the canvas throws, the placeholder goes out instead. It’s exactly 50 characters, the same length as the slice it replaces, with SAFE in the middle.
If you want to see how a VM like this is built, our post on writing a JavaScript VM in Go builds a much smaller one from scratch. For a different VM design, Incapsula’s thunk-based one comes up in our reese84 write-up.