Conditional contextMenus depending on site

I'm am working on a little chrome extension which uses the contextMenu to add an option or two when the user right clicks a webpage. However, this is only relevant of a few webpages out there and I would like to only show the additional menu item when it is relevant.

I would therefore like a way to get the current URL in my background page and see if the URL matches any of the sites in my whitelist.

I've googled a bit around but I'm not sure this is even possible. Any help would be appreciated, and please do not spare me for the details - JavaScript is not my strong side.



chrome.contextMenus.create(object createProperties, function callback)


createProperties ( object )

type ( optional enumerated string ["normal", "checkbox", "radio", "separator"] )

The type of menu item. Defaults to 'normal' if not specified.

title ( optional string )

The text to be displayed in the item; this is required unless type is 'separator'. When the context is 'selection', you can use %s within the string to show the selected text. For example, if this parameter's value is "Translate '%s' to Pig Latin" and the user selects the word "cool", the context menu item for the selection is "Translate 'cool' to Pig Latin".

checked ( optional boolean )

The initial state of a checkbox or radio item: true for selected and false for unselected. Only one radio item can be selected at a time in a given group of radio items.

contexts ( optional array of string ["all", "page", "frame", "selection", "link", "editable", "image", "video", "audio"] )

List of contexts this menu item will appear in. Defaults to ['page'] if not specified.

parentId ( optional integer )

The ID of a parent menu item; this makes the item a child of a previously added item.

documentUrlPatterns ( optional array of string )

Lets you restrict the item to apply only to documents whose URL matches one of the given patterns. (This applies to frames as well.) For details on the format of a pattern, see Match Patterns.

targetUrlPatterns ( optional array of string )

Similar to documentUrlPatterns, but lets you filter based on the src attribute of img/audio/video tags and the href of anchor tags.

onclick ( optional function )

A function that will be called back when the menu item is clicked.


info ( OnClickData )

Information about the item clicked and the context where the click happened.

tab ( Tab )

The details of the tab where the click took place.

Need Your Help

By using laravel 5.1 error that appears in view when trying display image from array by foreach

php laravel web laravel-5.1

I'm trying to display image from array defined inside controller through foreach loop defined inside view at Laravel 5.1 but i have this error that's appearing because the cache

Targeting an img that prompts a confirm

javascript jquery html image title

So what I am looking to do is to pull info from a dynamically added <img> on mouse click.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.