Copy JS objects from chrome console window

0
(0)

 Copy JS objects from chrome console window

 

Right-click the JS object in Chrome’s console and select “Store as Global Variable” from the context menu.
This Generate and Return a Global Variable with JS object as Result with name something like temp1

1. Copy JS object result on Clip Board
Use Chrome copy() method, as below

copy(temp1)
//Open Notepad, Edit > Paste / Ctrl + V

 

2. Generate a JSON file with Result of JS object
Copy and paste below code in chrome console and hit enter

(function(console){
console.save = function(data, filename){
  if(!data) {
     console.error('Console.save: No data')
     return;
  }

  if(!filename) filename = 'console.json'

  if(typeof data === "object"){
    data = JSON.stringify(data, undefined, 4)
  } 

  var blob = new Blob([data], {type: 'text/json'}),
  e = document.createEvent('MouseEvents'),
  a = document.createElement('a')
  a.download = filename
  a.href = window.URL.createObjectURL(blob)
  a.dataset.downloadurl =  ['text/json', a.download, a.href].join(':')
  e.initMouseEvent('click', true, false, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null)
  a.dispatchEvent(e)
}
})(console)

 

Now use the function for downloading, by typing following code in Chrome Console and hit enter

console.save(temp1);

// This generate and a JSON file with JS object as result for Download

 

More on Java Script …

How useful was this post?

Click on a star to rate it!

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

Be the first to comment

Leave a Reply

Your email address will not be published.


*


4 × 2 =