Avoiding redeclarations #1315
Replies: 1 comment
|
Hi Richard, this is likely happening because the 60 JavaScript files are being obfuscated separately but then loaded into the same page scope. The obfuscator can generate the same hexadecimal identifier in different files, for example _0x4110. If both files declare that identifier at the same scope, the browser can throw a redeclaration of const error. There isn't a simple option that guarantees globally unique identifiers across independently obfuscated files. I would recommend obfuscating the files as a single bundle instead, or using a bundler such as Webpack, Rollup, or Vite first and then obfuscating the resulting bundle. Also, running the obfuscator repeatedly isn't a reliable solution because it only changes the generated names randomly; it doesn't eliminate the underlying collision problem. |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
I am using the JS Obfuscator extension (1.3.2) for Visual Studio (1.100.3). I cannot find a config setting to avoid redeclarations. I have +/- 60 js files. After minimising with JS Obfuscator i get errors like this when loading the js in the browser:
Uncaught SyntaxError: redeclaration of const _0x4110
and I have to rerun js obfuscator until I get a clean set.
Is there an easier way please?
Here is my settings.json
{
"git.enableSmartCommit": true,
"JSObfuscator.changeFileExtension": "min.js",
"JSObfuscator.overwriteExistingFiles": true,
"JSObfuscator.subPathInWorkspace": "js",
"JSObfuscator.javascript-obfuscator": {
"compact": true,
"controlFlowFlattening": true,
"deadCodeInjection": false,
"debugProtection": false,
"debugProtectionInterval": false,
"disableConsoleOutput": false,
"identifierNamesGenerator": "hexadecimal",
"log": false,
"renameGlobals": false,
"rotateStringArray": true,
"selfDefending": true,
"shuffleStringArray": true,
"splitStrings": false,
"stringArray": true,
"stringArrayEncoding": [
"none",
"base64",
"rc4"
],
"stringArrayThreshold": 0.75,
"unicodeEscapeSequence": false,
"target" : "browser-no-eval"
},
"chat.commandCenter.enabled": false
}
All reactions