Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Popup is not appearing when used page_action

I am new to Google Chrome extension development. I am having the two following queries

  1. Popup is not appearing when I use page_action in manifest.json but appearing when I used browser_action. I would like to know why? Or am I doing wrong

  2. Also the icon is showing inactive state. Where as when I use browser_action, the icon is showing in active state (means I could see the color if active, or I could see as black and white icon, when inactive)

Manifest.json

{
  "manifest_version": 2,

  "name": "Getting started example",
  "description": "This extension shows a Google Image search result for the current page",
  "version": "1.0",

  "page_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html",
    "default_title":"getStarted Extension"
  },
  "permissions": [
    "activeTab",
    "https://ajax.googleapis.com/"
  ]
}

UPDATE:

Thanks to Teepemm . Followed his explanation and added the answer with code

like image 782
Gopinath Shiva Avatar asked Mar 09 '16 03:03

Gopinath Shiva


1 Answers

Thanks to Teepemm for guiding me with proper explanation, so in order to make the icon active and inactive, you have to use chrome.pageAction.show(tabId) (to activate the icon) and chrome.pageAction.hide(tabId) (to deactivate the icon) => https://developer.chrome.com/extensions/pageAction#method-show

You need to call this method from background.js by invoking it from client.js

//background.js
chrome.extension.onMessage.addListener(
    function(request, sender, sendResponse) {
    if (request.message === "activate_icon") {
        chrome.pageAction.show(sender.tab.id);
    }
});

//content-script.js
chrome.runtime.sendMessage({"message": "activate_icon"});

So once your extension icon is active, on click of the icon, popup will appear. So the popup will appear only when icon is active.

Hope this helps

like image 128
Gopinath Shiva Avatar answered Nov 10 '22 19:11

Gopinath Shiva