Skip to content

Instantly share code, notes, and snippets.

@jsEveryDay
Last active November 18, 2020 15:11
Show Gist options
  • Save jsEveryDay/66f5d7785d543badd127f7279bdcf51f to your computer and use it in GitHub Desktop.
Save jsEveryDay/66f5d7785d543badd127f7279bdcf51f to your computer and use it in GitHub Desktop.
Chrome Cookies to CSV
var savefile = (function() {
var a = document.createElement('a');
document.body.appendChild(a);
a.style = 'display: none';
return function(data, name) {
var blob = new Blob(data, { type: 'text/plain;charset=utf-8' }),
url = window.URL.createObjectURL(blob);
a.href = url;
a.download = name;
a.click();
window.URL.revokeObjectURL(url);
};
})();
function json2csv(arr, filename) {
var replacer = (key, value) => (value === null ? '' : value); // specify how you want to handle null values here
var header = Object.keys(arr[0]);
var csv = arr.map(row =>
header.map(fieldName => JSON.stringify(row[fieldName], replacer)).join(',')
);
csv.unshift(header.join(','));
var data = new Blob(
[csv.join('\r\n')],
{ type: 'text/plain;charset=utf-8' }
);
savefile([data], filename);
}
chrome.cookies.getAll(
{},
v => json2csv(v, 'all.csv')
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment