javascript - Comment Facebook désactive le navigateur activé#39;s Integrated Developer Tools

Mots clés : javascriptfacebookgoogle-chrome-devtoolsjavascript

meilleur 5 Réponses javascript - Comment Facebook désactive le navigateur activé#39;s Integrated Developer Tools

vote vote

92

with ((console && console._commandLineAPI) || {}) {   <code goes here> } 
Object.defineProperty(console, '_commandLineAPI',    { get : function() { throw 'Nooo!' } }) 
vote vote

84

Object.defineProperty(window, "console", {     value: console,     writable: false,     configurable: false });  var i = 0; function showWarningAndThrow() {     if (!i) {         setTimeout(function () {             console.log("%cWarning message", "font: 2em sans-serif; color: yellow; background-color: red;");         }, 1);         i = 1;     }     throw "Console is disabled"; }  var l, n = {         set: function (o) {             l = o;         },         get: function () {             showWarningAndThrow();             return l;         }     }; Object.defineProperty(console, "_commandLineAPI", n); Object.defineProperty(console, "__commandLineAPI", n); 
vote vote

71

window.console.log = function(){     console.error('The developer console is temp...');     window.console.log = function() {         return false;     } }  console.log('test'); 
vote vote

60

var is; Object.defineProperty(Object.prototype,"_lastResult",{    get:function(){        return this._lR;    },    set:function(v){        if (typeof this._commandLineAPIImpl=="object") is=this;        this._lR=v;    } }); setTimeout(function(){    var ev=is._evaluateAndWrap;    is._evaluateAndWrap=function(){        var res=ev.apply(is,arguments);        console.log();        if (arguments[2]==="completion") {            //This is the path you end up when a user types in the console and autocompletion get's evaluated             //Chrome expects a wrapped result to be returned from evaluateAndWrap.            //You can use `ev` to generate an object yourself.            //In case of the autocompletion chrome exptects an wrapped object with the properties that can be autocompleted. e.g.;            //{iGetAutoCompleted: true}            //You would then go and return that object wrapped, like            //return ev.call (is, '', '({test:true})', 'completion', true, false, true);            //Would make `test` pop up for every autocompletion.            //Note that syntax as well as every Object.prototype property get's added to that list later,            //so you won't be able to exclude things like `while` from the autocompletion list,            //unless you wou'd find a way to rewrite the getCompletions function.            //            return res; //Return the autocompletion result. If you want to break that, return nothing or an empty object        } else {            //This is the path where you end up when a user actually presses enter to evaluate an expression.            //In order to return anything as normal evaluation output, you have to return a wrapped object.             //In this case, we want to return the generated remote object.             //Since this is already a wrapped object it would be converted if we directly return it. Hence,            //`return result` would actually replicate the very normal behaviour as the result is converted.            //to output what's actually in the remote object, we have to stringify it and `evaluateAndWrap` that object again.`            //This is quite interesting;            return ev.call (is, null, '(' + JSON.stringify (res) + ')', "console", true, false, true)        }    }; },0); 
if (window.URL) {     var ish, _call = Function.prototype.call;     Function.prototype.call = function () { //Could be wrapped in a setter for _commandLineAPI, to redefine only when the user started typing.         if (arguments.length > 0 && this.name === "evaluate" && arguments [0].constructor.name === "InjectedScriptHost") { //If thisArg is the evaluate function and the arg0 is the ISH             ish = arguments[0];             ish.evaluate = function (e) { //Redefine the evaluation behaviour                 throw new Error ('Rejected evaluation of: \n\'' + e.split ('\n').slice(1,-1).join ("\n") + '\'');             };             Function.prototype.call = _call; //Reset the Function.prototype.call             return _call.apply(this, arguments);           }     }; } 
vote vote

53

(function() {     try {         var $_console$$ = console;         Object.defineProperty(window, "console", {             get: function() {                 if ($_console$$._commandLineAPI)                     throw "Sorry, for security reasons, the script console is deactivated on netflix.com";                 return $_console$$             },             set: function($val$$) {                 $_console$$ = $val$$             }         })     } catch ($ignore$$) {     } })(); 

Questions similaires