question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Obfuscated js throws error: "Uncaught SyntaxError: Illegal return statement"

See original GitHub issue

I am using javascript-obfuscator 0.10.0-beta.8, and I have been obfuscating my js from the command line, with good success, for a few months now. But as of the past week or so, many of my resultant obfuscations error out inside my Chrome extension. I haven’t touched javascript-obfuscator, haven’t updated it, nothing. Also I haven’t changed the way I’m calling it from cmd-line, nor changed any params.

Here is the error I have been getting: Uncaught SyntaxError: Illegal return statement. And here is the obfuscated block of code that triggers it:

if (_0x4423('0x7') === 'mJc') {
     zingLog(_0x4423('0x8'));
} else {
      return !![];
}

The return !![]; seems to be throwing the error. Both Chrome and JSNice point at the same line. When I encountered this 3-4 days ago, I had no idea what to do about it. I ended up re-obfuscating my files 2 or 3 more times, and after that – PRESTO – the error was gone. I wish I had taken a diff so I could know what changed. But that was another puzzling thing: how can I get different obfuscated results after changing nothing, no cmd-line params, no source code, etc? It seems as though the obfuscator generates different results each time it runs??

Here is how I’m calling the obfuscator:

node "C:\javascript-obfuscator.js" "myfile.js" --output "C:\obfuscated.js" --compact true --controlFlowFlattening true --controlFlowFlatteningThreshold 0.75 --deadCodeInjection true --deadCodeInjectionThreshold 0.4 --mangle false --rotateStringArray true --selfDefending true --stringArray true --stringArrayThreshold 0.75 --stringArrayEncoding false --unicodeEscapeSequence false

That always executes with no errors, and as mentioned, in the past the resulting obfuscations work great, and ran fine in Chrome. I am currently using Chrome Version 61.0.3163.79 (Official Build) (64-bit). That’s the latest update as of 9/12/2017, but the previous version I was on (60.xxx - before today) threw the same error.

Is this a bug in the obfuscator? A bug in the browser? Can changing a cmd-line option solve this? My entire obfuscated file is over 1500 lines so it seems ill-advised to post all of it here, but I can if necessary. Please help.

Thanks in advance.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

2reactions
HerrimanCodercommented, Sep 13, 2017

That works great now. Thanks so much!

0reactions
lock[bot]commented, Jun 6, 2018

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Syntax error: Illegal return statement in JavaScript
In my experience, most often this error message means that you have put an accidental closing brace somewhere, leaving the ...
Read more >
SyntaxError: Illegal return statement in JavaScript | bobbyhadz
The "Illegal return statement" error occurs when the return statement is used outside of a function. To solve the error make sure to...
Read more >
What Causes “Uncaught SyntaxError: Illegal return statement ...
If you get in your JavaScript console, it's usually because you accidentally put a return statement () outside of a function. This is...
Read more >
{solved} SyntaxError: Illegal return statement - Codecademy
Your code threw the following error: SyntaxError: Illegal return statement" I've looked in the forum for this question and lots of people post...
Read more >
Why does JavaScript code receive the error 'Illegal Return ...
JavaScript throws this error when we use return statement without function body. · return statement only makes sense when used inside a function...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found