I'm currently working on creating a Chrome extension for Pinterest integration.
After referencing some examples from the Chrome extension demo (specifically one that displays an icon in the omnibox when the URL contains a 'g'), I made modifications to make it work for URLs containing "pinterest.com". Here is the updated code:
manifest.json:
"permissions": [
"tabs",
"http://*.pinterest.com/"
]
In background.js, I mostly replicated the example code found online:
function showPinterestAction(tabId, ChangeInfo, tab) {
if(tab.url.indexOf('pinterest.com') > -1){
chrome.pageAction.show(tabId);
}
/* This doesn't work. tab.url returns as undefined for me :( */
};
chrome.tabs.onUpdated.addListener(function(tabId, change, tab) {
if (change.status == "complete") {
showPinterestAction(tabId);
}
});
chrome.tabs.onActivated.addListener(function(tabId, info) {
selectedId = tabId;
showPinterestAction(tabId);
});
// Ensure the current selected tab is set up.
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
alert(tabs[0].id);
showPinterestAction(tabs[0].id);
});
The issue I am facing is that the icon is not appearing on the correct page. When I try to alert(tab.url)
, it simply shows undefined
. Could someone please help me identify what's wrong with my code?