Insert an image in chrome extension

后端 未结 1 974
悲哀的现实
悲哀的现实 2020-11-27 18:37

I want to know how to insert an image in a Chrome extension.


相关标签:
1条回答
  • 2020-11-27 19:01

    There are two possible causes for the problem.

    1. You're injecting an image with src="logo.png". The inserted image element becomes a part of the page, so the browser does not try to load the image from the extension.
      To fix this problem, use chrome.extension.getURL('logo.png'); to get the absolute URL of the resource.

    2. "manifest_version": 2 is enabled in the manifest file. That disables all resources for external use, by default. When this error occurs, the following message appears in the console:

      Not allowed to load local resource: chrome://gbmfhbpbiibnbbgjcoankapcmcgdkkno/logo.png

      To solve the problem, add the resource to a whitelist, namely "web_accessible_resources" in the manifest file:

        ...,
        "web_accessible_resources": ["logo.png"]
      }
      

    UPDATE: chrome.extension.getURL('logo.png')

    Deprecated since Chrome 58. Please use runtime.getURL.

    0 讨论(0)
提交回复
热议问题