Reputation:
I'm making a JavaScript game, and I don't want anyone to cheat. Is there any way that I can detect, and possibly log, commands issue in the JavaScript console? The skeleton of what I'd be looking for is something like:
consoleCommands = "";
window.console.command = function ( thiscmd )
{
consoleCommands += thiscmd;
}
window.onbeforeunload = function ( )
{
// send log of commands to server
$.ajax({url:'recordNewCommandLog',method:'POST',data:{cmdlog:consoleCommands}});
};
Of course, an attacker could overwrite that, but I'll try to obfuscate it enough to make it difficult for him to figure out that his commands are getting logged in the first place.
Upvotes: 2
Views: 892
Reputation: 174957
In addition to the answers (and duplicate links) you've received, I want you to consider this:
Why do you care someone cheated?
Not to mention, how will you do your debugging without the console? You'll have a hard time reproducing bugs and fixing problems.
Don't block the console. Secure your server if applicable and leave the client "hackable" the client is the user's domain anyway, not yours.
Upvotes: 4
Reputation: 1
var arr = [];
console.log = function () {
arr.push([].slice.call(arguments));
// if `arr.length` , do stuff
return console.log
}
Upvotes: 1