Question

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:

enter image description here

Here is what gets outputted when I type "console":

enter image description here

Was it helpful?

Solution

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.

OTHER TIPS

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.

This works for me:

screenshot

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:

screenshot

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top