Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get a Chrome Extension PageAction icon to appear in the address bar?

I'm trying to build a Chrome Extension that appears as an icon in the address bar which, when clicked, sets contenteditable=true on all elements on the page, and then when clicked again sets them back to contenteditable=false.

However, I'm falling at the first hurdle... The icon isn't even showing up in the address bar.

Here's my manifest file:

 {
  "name": "Caret",
  "version": "1.0",
  "description": "Allows you to edit the content on any webpage",
  "page_action": {
    "default_icon": "icon.png"
  },
  "content_scripts": [
    {
      "matches": ["http://*/*"],
      "js": ["jquery.js", "caret.js"]
    }
  ],
  "permissions" : [
    "tabs"
  ]
}

and here's the caret.js script:

    chrome.browserAction.onClicked.addListener(function(Tab) {

    $("*").attr("contenteditable",true);

}); 

This is my first attempt at an extension, so it's quite probably a newbie mistake, but I'd really appreciate any help or advice!

like image 355
Chris Armstrong Avatar asked Jan 12 '11 21:01

Chris Armstrong


People also ask

What is the extension icon in Chrome?

It's the icon that looks like a small puzzle piece next to the profile avatar. The dropdown shows all the extensions installed and enabled in Chrome. Next to each one, you will see a pin icon. If it's blue it means the extension is showing if white it means it's hidden.

Where is the Google extensions tab?

On your computer, open Chrome . At the top right, click Extensions .

Is Google Analytics an extension?

Analytics users can download it from the Chrome web store. After you install the extension for your Chrome browser, you can load a page that you are tracking with Analytics and see the following information: Metrics: Pageviews, Unique Pageviews, Avg. Time on Page, Bounce Rate, % Exit.


2 Answers

Ok, turns out I needed to use chrome.pageAction.show(tab.id);, which meant I needed to get the ID of the current tab, which is achieved with:

chrome.tabs.getSelected(null, function(tab) {

    chrome.pageAction.show(tab.id);


});

BUT it turns out you can't use chrome.tabs within a content script, so I had to switch to using a background page instead.

like image 109
Chris Armstrong Avatar answered Oct 27 '22 07:10

Chris Armstrong


This is no longer possible as of last release.

Chrome extension page action appearing outside of address bar

https://groups.google.com/a/chromium.org/forum/#!searchin/chromium-extensions/upcoming/chromium-extensions/7As9MKhav5E/dNiZDoSCCQAJ

like image 32
Ropstah Avatar answered Oct 27 '22 06:10

Ropstah