1

I have a background script in my Chrome Extension which downloads a file called install.bat from the extensions directory. That works perfectly. But when I want to call chrome.downloads.open(id); the following error gets thrown:

Unchecked runtime.lastError while running downloads.open: User gesture required

I have requested both permissions (["downloads", "downloads.open"]) in the manifest.json file which are required for this procedure.

Is there a workaround for this problem or even a plain solution?

Datagrammar
  • 288
  • 3
  • 8
  • Take a look at http://stackoverflow.com/questions/26775564/how-to-open-a-downloaded-file . The comments on the answer appear to explain the issue you're having. – dan Mar 29 '16 at 17:11
  • @dan75 I have seen this question and the comments but they don't provide a solution. [A comment](http://stackoverflow.com/questions/26775564/how-to-open-a-downloaded-file#comment42138751_26778655) there says that you can "present a custom button". But how? Because a JavaScript confirm() dialog and `chrome.downloads.acceptDanger` don't work. – Datagrammar Mar 29 '16 at 17:23
  • I guess this is a known issue as stated [here](https://bugs.chromium.org/p/chromium/issues/detail?id=181124). *"Add user gesture handling to notifications api. This fixes the bug where user gestures were not taken into account after user interacts with a notification."* – abielita Mar 30 '16 at 10:07

1 Answers1

2

So after I read the discussion @abielita mentioned in his comment, I found a solution for my problem. Notifications are now counted as User gesture again. But being not able to open downloads automatically when the permission downloads.open is requested in the manifest makes this permission just useless.

So here is my solution (with wich I'm not really satisfied with, because the download doesn't open automatically) but it worked for me:

var downloadID = 123;

var nIcon = chrome.extension.getURL("icons/icon_48.png");
var nTitle = "My Extension - Client Installer";
var nMessage = "Please click the button below to run the installer.";
var nButtons = [{ title: "Run the installer..." }];

var nOptions = { type: "basic", iconUrl: nIcon, priority: 2, title: nTitle, message: nMessage, buttons: nButtons };
chrome.notifications.create("hello_world", nOptions, function (nIDa) {
    chrome.notifications.onButtonClicked.addListener(function (nIDb, nButtonIndex) {
        if (nIDb === nIDa) {
            chrome.downloads.open(downloadID);
        }
    });
});
Community
  • 1
  • 1
Datagrammar
  • 288
  • 3
  • 8