Browser Environment
Declare how your production build is served so the protected code can bind its integrity to it.
The browserEnvironment option declares facts about the environment your production build is served in, so the protected code can bind or react to them. It is a small object, and each field takes effect together with one specific protection — on its own the option does nothing:
browserEnvironment: { transport: 'https', hosting: 'remote' }
transport
The scheme your production serves the bundle over — 'http' or 'https'. Takes effect with vmSelfDefending.
With 'https', a copy a reverse engineer serves over plain HTTP will not run correctly. 'http' or an unset field adds no such protection.
hosting
Where your production bundle is served from — 'remote' or 'local'. Takes effect with vmDebugProtection, on the browser and browser-no-eval targets only. Requires obfuscator version 7.14.0 or later.
With 'remote', a copy a reverse engineer lifts and runs in their own local setup is treated as a runtime-environment mismatch, and the automation defenses react as configured by vmDefenseReaction. 'local' or an unset field adds no such protection.
Supported targets
browserEnvironment applies only to the browser, browser-no-eval, and service-worker targets. It is rejected for node, userscript, and bytenode — obfuscation fails with a validation error rather than silently dropping the setting. hosting is narrower still: it is accepted on a service worker but binds nothing there.
Requirements
transporttakes effect withvmSelfDefending,hostingwithvmDebugProtection; neither does anything otherwise.- A
browser,browser-no-eval, orservice-workertarget (browserorbrowser-no-evalforhosting). - Obfuscator version 7.9.0 or later for
transport, 7.14.0 or later forhosting.
Example
JavaScriptObfuscator.obfuscate(code, {
vmObfuscation: true,
vmSelfDefending: true,
vmDebugProtection: true,
target: 'browser',
browserEnvironment: { transport: 'https', hosting: 'remote' }
});