Categories
JavaScript Answers

How to save a file on disk in a Chrome extension with JavaScript?

Spread the love

Sometimes, we want to save a file on disk in a Chrome extension with JavaScript.

In this article, we’ll look at how to save a file on disk in a Chrome extension with JavaScript.

How to save a file on disk in a Chrome extension with JavaScript?

To save a file on disk in a Chrome extension with JavaScript, we can use the chrome.downloads.download method.

For instance, we write

const url = "https://picsum.photos/200/300";

chrome.downloads.download({ url }, (downloadId) => {
  console.log(downloadId);
});

to call chrome.downloads.download with { url } and a callback that runs when the download starts.

We download the file at the url.

Conclusion

To save a file on disk in a Chrome extension with JavaScript, we can use the chrome.downloads.download method.

Leave a Reply

Your email address will not be published.

If you like the content of this blog, subscribe to my email list to get exclusive articles not available to anyone else.