javascript - Page action icon displays only in extension page -


i'm learning creating chrome extensions. have studied page actions, used create icon inside address bar. code follows:

in manifest.json:

{   "manifest_version" :2,       "name" : "gtmetrix",   "description": "test google chrome extension",   "version" : "1.0",   "page_action":{      "default_icon"  : "icon.png",      "default_popup" : "popup.html",      "default_title" : "test google chrome extension"   },   "background": { "scripts": ["background.js"] },   "permissions" : [      "activetab"   ] } 

in background.js

chrome.tabs.getselected(null, function(tab) {   chrome.pageaction.show(tab.id); }); 

in popup.html

<html> <head>         <script src="jquery.min.js"></script>         <script src="popup.js"></script>         <!--<script src="background.js"></script>-->         <style>              body{ background:pink}             .block{ width : 100%;}         </style> </head> <body>         <div class="block">             <h2>test extension</h2>             <button id="checkpage">check page now!!</button>         </div> </body> </html> 

so when i'm using above code,it shows below: enter image description here

but when goes pages google or others, not show icon:

enter image description here

what goes wrong , use of background in manifest.json , why using content_script, exact meaning of that?

i have looked through the devguide

use following in background.js

chrome.tabs.onupdated.addlistener(function(id, info, tab){     showpageaction(tab); });  chrome.tabs.onactivated.addlistener(function(id, info, tab){     chrome.tabs.query({ currentwindow: true, active: true },         function (tabarray) {             if(tabarray[0]){                 showpageaction(tabarray[0]);             }         }); });  function showpageaction(tab){     chrome.pageaction.show(tab.id) } 

there other methods too. chrome extension samples

ps:

  1. before showing can check tab url or criteria.
  2. don't user page action if applicable tabs - use browser action instead.

Comments

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -