Reputation: 288
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?
Upvotes: 1
Views: 2244
Reputation: 288
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);
}
});
});
Upvotes: 2