Async Executor
Run the VM asynchronously so the bytecode decryption key can be fetched at runtime instead of shipping inside the bundle.
The vmAsyncExecutor option enables the asynchronous VM executor. Its headline benefit is that vmBytecodeArrayEncodingKeyGetter may now return a Promise - an asynchronous key getter - so the decryption key can come from a network request, IndexedDB, or any async source at load time rather than being available synchronously when the code first runs.
For a complete backend-fetched-key walkthrough, see the recipe Fetching the Bytecode Array Key from Backend.
When to use it
Heavily recommended for fully async codebases. In this mode only async functions are virtualized - a synchronous function cannot be made async without turning its return value into a Promise and breaking its callers - so code that is async throughout gets the most coverage. It still works when the root is synchronous (for example a sync IIFE or UMD wrapper): the outermost async functions inside are protected, and the sync parts are left as-is.
What gets transformed
Every outermost async function, wherever it appears (including nested inside sync wrappers). The outermost async in each chain is the protected unit - everything inside it, sync and async, is compiled in. Synchronous functions and plain generators are left unobfuscated.
Skips and warnings
Async generators are also left unobfuscated when an asynchronous key getter is active - an async generator must return its iterator synchronously and cannot wait for the key. In the default vmTargetFunctionsMode: 'root' skips are silent (selection is automatic). In 'comment' mode a warning is emitted through ObfuscationResult.getWarnings() whenever a function you explicitly marked cannot be virtualized - it turned out synchronous, or it is an async generator under an async key getter. These warnings (VMSyncFunctionSkippedInAsyncMode, VMAsyncGeneratorSkippedInAsyncMode) can be silenced per type via the warnings option (v7.8.0+).
Requirements
- The asynchronous key getter requires
vmBytecodeArrayEncodingtogether with avmBytecodeArrayEncodingKeyGetter. - Obfuscator version 7.3.0 or later.
Enabling the option alone just switches the executor to async mode (only outermost async functions are virtualized). Returning a Promise from the key getter is what unlocks runtime key fetching, and that additionally needs bytecode array encoding with a key getter.
Example
In a fully synchronous codebase almost nothing is virtualized, since only async functions are eligible. If your entry points are not async, prefer a synchronous key getter and leave vmAsyncExecutor off.
