[crx] Example Needed - chrome.tabs.update

2,158 views
Skip to first unread message

rc

unread,
May 20, 2010, 12:20:07 AM5/20/10
to Chromium-extensions
Hello-

I've added "permissions": [ "tabs"] to the manifest.json file.

In my code I've attempted to have the following activate in javascript
when a link is click and neither work.
chrome.tabs.update(0, {url: 'http://www.google.com'});
chrome.tabs.update(1, {url: 'http://www.google.com'});

Does anyone have a working example of chrome.tabs.update they can
share?

Thanks,
Rob

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.
For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.

Xan

unread,
May 20, 2010, 1:23:33 AM5/20/10
to Chromium-extensions
Depends on what you want to do. You cant bass 0 or 1 as tab ID, you
must get them from chrome.tabs.getAllInWindow,
chrome.tabs.getSelected, or a callback on tabs events.

Here are two snipptes used in my extension:

------------

chrome.tabs.getAllInWindow(
undefined,
function(tabs) {
for (var i = 0, tab; tab = tabs[i]; i++) {
if (tab.url && isUrl(tab.url, getUrl())) {
chrome.tabs.update(tab.id, {url: tab.url, selected: true});
return;
}
}
chrome.tabs.create({url: getUrl()});
}
);

It's a function that needs to open an URL defined by getUrl(), but
first looks if it's open already in a tab and reuses the tab if it's
true.

------------------

chrome.tabs.onUpdated.addListener(OnLoginHandler);

function OnLoginHandler (tabId, changeInfo, tab){ // Forces update on
login
if (changeInfo.url && changeInfo.url == loggedInURL){
// ..some code..
}
}

This one checks if any updated tab changed URL to login confirmation
page, and does some work immediately after that.

------------------

Hope it helps.

On May 20, 8:20 am, rc <robertcare...@gmail.com> wrote:
> Hello-
>
> I've added "permissions": [ "tabs"] to the manifest.json file.
>
> In my code I've attempted to have the following activate in javascript
> when a link is click and neither work.
> chrome.tabs.update(0, {url: 'http://www.google.com'});
> chrome.tabs.update(1, {url: 'http://www.google.com'});
>
> Does anyone have a working example of chrome.tabs.update they can
> share?
>
> Thanks,
> Rob
>
> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-extensi...@chromium.org.
> To unsubscribe from this group, send email to chromium-extensions+unsubscr...@chromium.org.

rc

unread,
May 20, 2010, 10:59:10 PM5/20/10
to Chromium-extensions
It does help, I got my test example to work from your first example.
Very clever. Thank you!!

Believe it or not I think I do understand. getAllInWindow gets a
collection of tabs. You're looping over the tabs collection and
evaluating each url value. (I see in the documentation the tab object
has other properties as well.) isURL() and getURL() are your own
custom functions. isUR() L I presume evaluates the current tabs URL in
some manner.

So if I am understanding this correctly, your code is refreshing the
page to itself if it's the correct URL... is that right?

-Rob
> For more options, visit this group athttp://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.- Hide quoted text -
>
> - Show quoted text -
Reply all
Reply to author
Forward
0 new messages