How to fix downloads with `chrome.downloads` extensions' API getting automatically interrupted if download confirmation setting is ON?

Viewed 269

Description

I am developing a small Chrome extension and needed to download a file off web. Here's how the script behaves:

  1. I initiate the download in my service_worker JS file (either on a command event or with no conditionals at all)
  2. The download starts
  3. The callback runs and receives an ID (which means download starts successfully)
  4. The download never completes (saveAs dialog never opens even if set to true)
  5. Upon analyzing the DownloadItem object for the returned ID, its status is found to be interrupted and its reason to be USER_CANCELED
  6. No errors are reported in either of the consoles -- the page's or the service_worker's -- or the extensions page
  7. chrome.runtime.lastError is undefined as well.

Current Config

  • downloads in the permissions
  • <all_urls> in host permissions (for debugging)

Observation

  • The download succeeds if:
    • Ask where to save each file before downloading setting is turned off and...
    • filename/saveAs isn't set in passed DownloadOptions

But shouldn't the download work nonetheless?

Background.js

chrome.commands.onCommand.addListener((command) => {
  const url = "https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png"; //random image
  chrome.downloads.download({url, saveAs: true}, (id) => {
    console.log(chrome.downloads.search({id}, (result) => {
      console.log(result)
      console.log(chrome.runtime.lastError)
    }))
  })
})

Any idea what's going on? Any help would be highly appreciated!

0 Answers
Related