最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to use web browser download api? - Stack Overflow

programmeradmin2浏览0评论

In this article downloads on MDN, it says we can use downloads api to donwload a file, but code in the example of that article

var downloading = browser.downloads.download({
  url : downloadUrl,
  filename : 'my-image-again.png',
  conflictAction : 'uniquify'
}); 

downloading.then(onStartedDownload, onFailed);

will lead to Uncaught ReferenceError: browser is not defined. I ran this code in chrome console pannel. Did I miss something?

In this article downloads on MDN, it says we can use downloads api to donwload a file, but code in the example of that article

var downloading = browser.downloads.download({
  url : downloadUrl,
  filename : 'my-image-again.png',
  conflictAction : 'uniquify'
}); 

downloading.then(onStartedDownload, onFailed);

will lead to Uncaught ReferenceError: browser is not defined. I ran this code in chrome console pannel. Did I miss something?

Share Improve this question asked Nov 3, 2020 at 8:55 yuanyuan 2,1503 gold badges17 silver badges25 bronze badges 2
  • 1 After the @Quentin's answer, do you still need how to download file in all browsers without using this downloads api – Ayoub Touba Commented Nov 3, 2020 at 9:12
  • 1 @Youba I think I can use <a> to make download action, maybe. – yuan Commented Nov 3, 2020 at 9:16
Add a ment  | 

1 Answer 1

Reset to default 7

Look at the section of the MDN documentation that page appears in. The feature is only available to browser extensions, not to regular webpages (which is the context the Console runs in if you open it against a regular page).

发布评论

评论列表(0)

  1. 暂无评论