I have various "JavaScript snippets". They are often related to some kind of obfuscation mechanism. For example:

var _0xb144=['setRequestHeader','x-tool','oldbrowsers','accept-ianguage','en-US,en;q=0.9,es;q=0.8'];(function(_0x17e496,_0xb144df){var _0x46bf77=function(_0x446715){while(--_0x446715){_0x17e496['push'](_0x17e496['shift']());}};_0x46bf77(++_0xb144df);}(_0xb144,0x104));var _0x46bf=function(_0x17e496,_0xb144df){_0x17e496=_0x17e496-0x0;var _0x46bf77=_0xb144[_0x17e496];return _0x46bf77;};var _0x557861=_0x46bf;xhr[_0x557861('0x0')]('X-Session-Hash',a),xhr[_0x557861('0x0')](_0x557861('0x1'),_0x557861('0x2')),xhr[_0x557861('0x0')](_0x557861('0x3'),_0x557861('0x4')),xhr[_0x557861('0x0')]('x-vt-anti-abuse-header','LVpHOXVkQ0JpWlNCbGRtbHMt');

I'm trying to run this code, safely, and get back whatever the result may be. In this case, I guess I want to know the value of the _0xb144 variable after this code has run.

I'm not trying to simply "beautify" the code; I'm trying to have it actually executed, safely and sandboxed in an automated manner, without any browser involved.

The context is a PHP CLI script, so there is no web browser or JavaScript engine natively available.

I want to put the above code into a file called test.js, then feed this into some kind of "JavaScript black box" and have it return the answer in some kind of sensible form. That is, without having to reverse-engineer what the code actually does and re-implement it in PHP. (I've tried, but it's very cryptic and is probably going to change regularly.)

I've already made extensive research into all available "headless browser" solutions, but these are all abandoned or just don't work at all.

I want to essentially do:

jsblackbox.exe test.js

And then get some kind of sensible output, showing the new values of all variables in the code after the script has been run safely inside some sort of sandbox.

For "personal reasons", I cannot install/use Node.js, so please don't suggest that or anything which depends on it.

  • Perhaps try "Google Chrome headless", or PhantomJS. – knb Nov 2 '20 at 9:56

Test JavaScript in almost any browser. For that matter, simply going to developer mode in many browsers enables running a JavaScript. In Firefox, for example, press CtrlShiftK to open a developer console.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.