For my Chrome extension, I need to show the pageAction only on a certain website. I used to do this with declarativeContent, but it isn't supported on Firefox, so I have to do it the manual way. The answers to this question suggested that you could simply use something like this:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
if (changeInfo.status === "complete" && tab.url) {
if (tab.url.match(/google.com/)) {
chrome.pageAction.show(tabId);
}
}
});
This didn't work for me, so I modified the code in the background script to look like this:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
console.log("Tab updated! Tab URL: " + tab.url);
});
Every time you update a tab the console just prints Tab updated! Tab URL: undefined a few times. I also tried to query the tab like the answers to this question said, which produces the same output.
The other files of the extension are:
manifest.json:
{
"name": "Test",
"version": "1.0",
"description": "Test for StackOverflow",
"permissions": ["activeTab"],
"background": {
"scripts": ["background.js"]
},
"page_action": {
"default_popup": "popup.html"
},
"manifest_version": 2
}
popup.html:
<!DOCTYPE html>
<html>
<body>
This is a popup!
</body>
</html>
You are missing the tabs permission from your manifest.json file. With this permission the URL of the tab should also be logged to the console.
"permissions": ["activeTab", "tabs"] // <-- This
manifest.json:
{
"name": "Test",
"version": "1.0",
"description": "Test for StackOverflow",
"permissions": ["activeTab", "tabs"],
"background": {
"scripts": ["background.js"]
},
"page_action": {
"default_popup": "popup.html"
},
"manifest_version": 2
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With