function doit() {
alert(3);
// Statement 1
// chrome.tabs.create({url:"http://www.google.com"});
// Statement 2
// chrome.tabs.update({url:"http://en.wikipedia.org"});
alert(4);
}
chrome.browserAction.onClicked.addListener(doit);
When the script runs as is, I get JS alerts of 3 and 4. OK.
When I comment in statement 1 and run the script, I get a JS alert of 3, then Google opens in a new, active tab, then I get a JS alert of 4. As expected.
When I comment out statement 1 and comment in statement 2, I get a JS alert of 3, and that's it.
According to http://code.google.com/chrome/extensions/tabs.html#method-update, I do not need to pass a tabId object, because it "defaults to the selected tab of the current window." The url object is defined as "A URL to navigate the tab to", as I noticed when I ran the chrome.tabs.create in statement 1.
Why does my chrome.tabs.update statement not work?
Keyboard shortcut to reload tabs is bound to Alt - Shift - R. Reload all tabs in all windows (enabled via options)
Chrome keeps the most recently closed tab just one click away. Right-click a blank space on the tab bar at the top of the window and choose Reopen closed tab. You can also use a keyboard shortcut to accomplish this: CTRL + Shift + T on a PC or Command + Shift + T on a Mac.
The tabId
parameter has to be specified. Supply null
if you want to use the default settings. Otherwise, the following error occurs:
Error in event handler for 'browserAction.onClicked': Error: Invalid value for argument 1. Expected 'integer' but got 'object'.
This message is logged at the background page. To access this console, follow the four steps in this answer.
Corrected code: chrome.tabs.update(null, {url:"http://en.wikipedia.org"});
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