问题
UPDATED: The reason the console won't log is the site runs this script:
// Production mode
// Disable console.log
console.log = function() {};
I'm guessing there isn't a way to get the function back on the site?
Prior issue:
I'm running a script in my Chrome console that follows everyone on a site. There are 200 people on the page, and I want to iterate through all the follow buttons and click them all by running this script in the console:
javascript:var inputs = document.getElementsByClassName('btn-follow');
for(var i=0; i<inputs.length; i++) {
inputs[i].click();
}
console.log("The btn-follow script has finished");
The script clicks the buttons fine but the log statement returns undefined
.
Is there a way to log to the console from within the console?
When I try console.log directly it looks like this:
Here is what gets outputted when I type "console":
回答1:
You can eliminate shadowed properties with delete
:
delete console.log;
The original log
function (which exists on console
's prototype) was never overwritten -- it has merely been shadowed by a property on the console
instance. You can delete
the instance function and let the original prototype function shine through.
回答2:
This works for me:
The log statement I submit (in blue) is followed by it's effect (the message, in black) and the return type of the log expression (in grey).
EDIT
Verify that you haven't replaced the console somehow. You can try the following:
回答3:
I'm guessing there isn't a way to get the function back on the site?
Since you are using Chrome and can use Object.getPrototypeOf, you can do:
var original_log = Object.getPrototypeOf(console).log;
The log
method is defined on the prototype.
来源:https://stackoverflow.com/questions/20460685/how-do-i-restore-console-log-function-that-has-been-disabled-by-a-website