I'm learning about creating chrome extensions. I have studied about page actions, which is used to create an icon inside the address bar. My code as follows:
In my 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 my background.js
chrome.tabs.getSelected(null, function(tab) {
chrome.pageAction.show(tab.id);
});
In my 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 this page now!!</button>
</div>
</body>
</html>
So when I'm using the above code,it shows like below:
But when I goes to another pages like google or others, it will not show the icon:
What goes wrong and what is the use of background
in my manifest.json
and why we are using content_script
, what is the exact meaning of that?
I have looked through the devguide