JavaScript Obfuscator

5.4.1 · active · verified Sun Apr 19

JavaScript Obfuscator is a powerful, free-to-use library for transforming JavaScript and Node.js source code to make it harder to reverse engineer. The current stable version is 5.4.1. The project demonstrates an active release cadence with frequent minor and patch updates, indicating ongoing development and maintenance. Key features include VM-based bytecode obfuscation (available via the integrated Obfuscator.io Pro API), variable renaming, string extraction and encryption, dead code injection, control flow flattening, and various other code transformations. Its primary differentiator is the breadth of its obfuscation techniques, including advanced VM-based protection, making it a comprehensive solution for source code protection against tampering and intellectual property theft.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to import and use `javascript-obfuscator` to obfuscate a sample JavaScript code string with a comprehensive set of options.

import JavaScriptObfuscator from 'javascript-obfuscator';

const sourceCode = `
function greet(name) {
  const message = 'Hello, ' + name + '! Welcome to the obfuscated world.';
  console.log(message);
}

greet('Developer');

const secretData = {
  apiKey: 'super-secret-key-123',
  database: 'production-db'
};

function getSecret(key) {
  return secretData[key];
}

console.log(getSecret('apiKey'));
`;

const obfuscationOptions = {
  compact: true,
  controlFlowFlattening: true,
  controlFlowFlatteningThreshold: 0.75,
  deadCodeInjection: true,
  deadCodeInjectionThreshold: 0.4,
  debugProtection: false,
  debugProtectionInterval: 0,
  disableConsoleOutput: true,
  identifierNamesGenerator: 'hexadecimal',
  log: false,
  numbersToExpressions: true,
  renameGlobals: false,
  selfDefending: true,
  simplify: true,
  splitStrings: true,
  splitStringsChunkLength: 10,
  stringArray: true,
  stringArrayEncoding: ['base64'],
  stringArrayIndexShift: true,
  stringArrayRotate: true,
  stringArrayShuffle: true,
  stringArrayWrappersCount: 2,
  stringArrayWrappersType: 'variable',
  stringArrayThreshold: 0.75,
  transformObjectKeys: true,
  unicodeEscapeSequence: false,
  domainLock: [
    'example.com',
    process.env.DOMAIN_LOCK_TEST ?? '' // Example for environment variable usage
  ]
};

try {
  const obfuscatedResult = JavaScriptObfuscator.obfuscate(sourceCode, obfuscationOptions);
  console.log('Obfuscated Code:\n', obfuscatedResult.getObfuscatedCode());
  // You can also get the source map if enabled in options
  // console.log('Source Map:\n', obfuscatedResult.getSourceMap());
} catch (error) {
  console.error('Obfuscation failed:', error);
}

view raw JSON →