Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert an image in chrome extension

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

<img id="image" src="logo.png" /> 

I'm inserting that html tag correctly into a website, but naturally can't load that logo.png image.

Any ideas on how to modify manifest.json?

like image 977
jacktrades Avatar asked Aug 03 '12 22:08

jacktrades


People also ask

How do I add an extension to a Picture?

Click the plus button , and select Image extension. From the “Add to” drop-down menu, select a campaign or ad group you want to add your image extensions to. Click the plus button next to “Images”, then select an image source from the top of the dialog box.

How do I get Google image extensions?

Google Image Search. This extension for Google Chrome adds a shortcut to searching images or other content on google based on a supplied image. Simply Right-Click any image in the browser to access the context menu and select "Search Google using this image".


1 Answers

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.

like image 126
Rob W Avatar answered Oct 02 '22 15:10

Rob W