Google has just released some new extension APIs for it’s superb browser chrome. I already use some own experimental extensions to augment my browsing experience. And now I start to test the new possibilities. There will be a lot of new uses. You can now implement own infobars, program the omnibox (how about tweeting directly from the omnibox?) and add customized context menus, that can work selectively on the type of content (for example a page, a link/video/image or a selection) or the current url.

My first experiment with the new APIs was a simple one: Provide a context menu item to search for the selected text on different sites (too bad, this can’t at this time be integrated with the defined/personally configured search engines/sites of chrome). Nonetheless I'd like to share this simple naive implementation with you, to help get you started with chrome extensions.

The whole code contains of two files that you put together in a directory. File one is “manifest.json”, which declares the permissions used by the extension (see documentation):

  "name": "LookUp",
  "description": "Look up selected word(s) on different sites",
  "version": "0.9",
  "permissions": ["contextMenus","tabs"],
  "background_page": "background.html"

The other file is the “backgroud.html” which gets loaded when the extension is loaded/activated. It only contains the javascript needed to define the sites to search on and the action that should be taken on click (in this case always open a new tab with a search url) and hook these actions to the menu:

var definitions=[
	{"title":"Wiki (en)","action":function(info,tab){chrome.tabs.create({"url":""+info.selectionText});}},

for(var i=0;i<definitions.length;i++) {
	var item=definitions[i];
	var id=chrome.contextMenus.create({"title": item.title, "contexts":["selection"],"onclick": item.action});

To get such a local extension running, you go to chrome://extensions/, click on ”load unpacked extension…” and select the directory in which you saved above two files. That’s it.

Dieser Text ist mir etwas wert:


Trackback-URL für diesen Eintrag
    Keine Trackbacks


    #1 bandler am 09/04/10 um 02:21
    *den google browser finde ich auch sehr gut. mir fehlt hier nur noch eine stand alone version ohne installationsroutinen.
    #2 Stecki am 09/04/10 um 09:18
    *Mal Chrome portable probiert?

Kommentar schreiben

Umschließende Sterne heben ein Wort hervor (*wort*), per _wort_ kann ein Wort unterstrichen werden.
Standard-Text Smilies wie :-) und ;-) werden zu Bildern konvertiert.

Um maschinelle und automatische Übertragung von Spamkommentaren zu verhindern, bitte die Zeichenfolge im dargestellten Bild in der Eingabemaske eintragen. Nur wenn die Zeichenfolge richtig eingegeben wurde, kann der Kommentar angenommen werden. Bitte beachten Sie, dass Ihr Browser Cookies unterstützen muss, um dieses Verfahren anzuwenden.

:'(  :-)  :-|  :-O  :-(  8-)  :-D  :-P  ;-) 
Gravatar, Identica, Favatar, Pavatar, Twitter Autoren-Bilder werden unterstützt.

  Kommentare werden erst nach redaktioneller Prüfung freigeschaltet!