Skip to content

Instantly share code, notes, and snippets.

@janaSunrise
Created December 23, 2025 07:52
Show Gist options
  • Select an option

  • Save janaSunrise/a9c785f383f558c5805f1bed1c975807 to your computer and use it in GitHub Desktop.

Select an option

Save janaSunrise/a9c785f383f558c5805f1bed1c975807 to your computer and use it in GitHub Desktop.
Save data to a file from the browser console.
console.save = function save(data, filename = "console.json") {
if (data === undefined) {
console.error("console.save: No data provided");
return;
}
let content;
let mimeType = "application/json";
try {
if (typeof data === "string") {
content = data;
mimeType = "text/plain";
} else {
content = JSON.stringify(data, null, 4);
}
} catch (err) {
console.error("console.save: Failed to serialize data", err);
return;
}
const blob = new Blob([content], { type: mimeType });
const url = URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = filename;
a.style.display = "none";
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(url);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment