Reputation: 259
On a Website with a browser game im logging an object to the console. I can inspect the object, but what i would like to do, if possible, is export or save this object to or into a custom script in order to loop over this object to analyze several proberties of it.
If this is not possible, is it possible to locally alter the JavaScript file my browser is getting from the server so i could replace the console.log() part locally ?
Upvotes: 2
Views: 352
Reputation: 136568
Because you don't have access to the logger script,
you will have to override the console.log
function, before your script does log your object.
(function(){
//save the original function
var originalConsoleLog = console.log;
//override the original console.log
console.log = function() {
originalConsoleLog.apply(console, arguments);
// here you can call your own checking function
yourCheck(arguments);
}
})();
Now each time an object will be logged to the console, yourCheck
will be called, with the logged arguments, so you may want to add some sanity check in your own function to be sure you catched the good one.
Upvotes: 1
Reputation: 7775
Serialize it as JSON:
JSON.stringify(obj);
Deserialize it using:
JSON.parse(obj);
Upvotes: 3
Reputation: 2121
Hi if it is from the server..? so as i have practiced i will give a suggestion to find it from the header's request easily from the developer's tool just get from there and and beautify it will better to analyze you data.
or you even can use the fiddler or else tools that tracks the request and responses with the server.
Upvotes: 0
Reputation: 1369
As answered by @roland JSON.stringify
is exactly what you asked for.
Furthermore, if you are actually looking for how to analysis the data on-the-fly, you can try bookmarklet. A googling on bookmarklet
will show the details.
Upvotes: 0
Reputation: 19772
Just use the global copy
method from the console. For example:
var myObjectInTheConsole = {};
copy(myObjectInTheConsole);
Tested and works in the most recent versions of Chrome, Safari, and Firefox.
Upvotes: 0