Reputation: 7878
Good evening everyone ,
I am beginning a chrome extension and in a certain scenario I need to redirect (change URL) of a user's tab .
Here's my code
function changeTabURL(tabName,addr) {
var tabId=parseInt(localStorage.getItem(tabName)); //fetch tab ID
chrome.tabs.update(tabId,{"url":addr});
}
Now here's what's happening , The Chrome:// ... thing is being prepended to my URL ! Say I try to redirect the tab to 'http://www.google.com' , this is what happens :
"No webpage was found for the web address: chrome-extension://oihdngeahhchnacpilhnmaknneooabbc/http://www.google.com"
I can't shake this ! I've tried resetting the URL first
chrome.tabs.get(tabId,function(tab) {
tab.url='';
alert(tab.url);
});
chrome.tabs.update(tabId,{"url":addr});
}
nothing I do shakes this .
Any thoughts?
Upvotes: 1
Views: 5183
Reputation: 267
have you set the permission in your manifest.json like this:
"permissions": [
"notifications",
"contextMenus",
"tabs",
"contentSettings",
"http://*/*",
"https://*/*"
]
Upvotes: 0
Reputation: 310
Since you are already using the chrome.tabs API, you may want to try using chrome.tabs.query to find the active tab and get it's id that way. Here's an example:
queryInfo = new Object();
queryInfo.active = true;
chrome.tabs.query(queryInfo, function(result) {
var activeTab = result[1].id;
updateProperties = new Object();
updateProperties.url = 'YOUR_URL_HERE';
chrome.tabs.update(activeTab, updateProperties, function() {
// Anything else you want to do after the tab has been updated.
});
});
Upvotes: 3