javascriptgoogle-chromegoogle-chrome-extensiongoogle-chrome-devtools

' Unable to download all specified images.' when trying to run a notification on a chrome extension


Script:

 chrome.notifications.create(
    'name-for-notification',{   
    type: 'basic', 
    iconUrl: 'icon4.png',
    title: "This is a notification", 
    message: "hello there!" 
    });

Everytime I run it, I get the error

Unchecked runtime.lastError while running notifications.create: Unable to download all specified images.

But here's the thing, "icon4.png" is in the same file as my script, background. See for yourself.

I don't know why it's not working, the icon is there. I've tried using this aswell:

 chrome.notifications.create(
        'name-for-notification',{   
        type: 'basic', 
        iconUrl: 'http://www.filehosting.org/file/details/671921/icon4.png',
        title: "This is a notification", 
        message: "hello there!" 
        });

And it still doesnt work!

And yes, I have the notifications permission set in my manifest.


Solution

  • URLs must be relative to your manifest.json (first code block)

    Your issue is that you have not provided Chrome with a URL that provides the iconUrl as a URL relative to your manifest.json. The iconUrl documentation states [emphasis mine]:

    URLs can be a data URL, a blob URL, or a URL relative to a resource within this extension's .crx file

    You appear to have provided a URL that is relative to the location of your background.js script, not relative to your manifest.json. This can be determined by the fact that your manifest.json is not in the same directory as your background.js. Without you providing your manifest.json it's not possible to tell you exactly what this URL must be. However, it needs to be a path relative to your manifest.json file, similar to how you have referenced your bakground.js.

    External URLs are not permitted (second code block)

    The iconUrl you have provided is not permitted. The permitted types of URLs are clearly listed in the documentation (see quote above). Effectively, the restriction is that the data for the icon must be supplied completely from within the extension. You can not have Chrome fetch the data for the icon from the network by just passing an external URL for iconUrl. That does not mean that you must include the icon data (e.g. icon4.png) in your extension's .crx file. You could fetch the data yourself; convert it to a data URL or blob URL; then provide it to Chrome. But, the data must already exist in your extension.