I am building an extension, I want my extension to work as follows : When ever the user visits any website my extension should fetch the url and title of that website and display it whenever the user clicks on the extension icon
this is my code
(manifest.json)
{
"manifest_version": 2,
"name": "My Launcher",
"description": "Quick launch lol Media",
"version": "1.0.0",
"icons": { "128": "icon_128.png" },
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": ["activeTab"],
"background": {
"scripts": ["popup.js"],
"persistent": false
}
}
(popup.html)
<!DOCTYPE html>
<html>
<head>
<title>Hello World</title>
<script src="popup.js">
</script>
<script src="jquery-3.3.1.min">
</script>
</head>
<body>
<h2 id="greet">Hello world!!!</h2>
</body>
</html>
(popup.js)
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
tabs[0].url; //url
tabs[0].title; //title
$('#greet').text((tab[0].url).val());
});
});
When the user clicks on the extension icon he should see a message displaying the url and title of the current webpage he/she is visiting.