Why tab.url's value is empty?

132 views
Skip to first unread message

joejph

unread,
Dec 19, 2010, 10:06:55 AM12/19/10
to Chromium-extensions
Here is my code:
function checkUrlPattern(tab)
{
alert(tab.url);
}
// Listen for any changes to the URL of any tab.
chrome.tabs.onUpdated.addListener(checkUrlPattern);
chrome.tabs.onCreated.addListener(checkUrlPattern);

when a new tab was created, in CheckUrlPattern the tab.url's value is
empty.
but when the onUpdated event was fired, the tab.url has its value.

but here is some similar code in the page http://code.google.com/chrome/extensions/events.html,
chrome.tabs.onCreated.addListener(function(tab) {
appendToLog('tabs.onCreated --'
+ ' window: ' + tab.windowId
+ ' tab: ' + tab.id
+ ' index: ' + tab.index
+ ' url: ' + tab.url);
});

So I think, the tab'url should has its value when the new tab created.

Another question is "where the log files which contain the log content
written by appendToLog ?"

Thanks for help.

Arne Roomann-Kurrik

unread,
Dec 20, 2010, 3:45:35 PM12/20/10
to joejph, Chromium-extensions
How do you know which fire is onUpdated and which is onCreated, if you're using the same handler?

The signature for onUpdated is different from onCreated:
function(integer tabId, object changeInfo, Tab tab)

Your code would assign a number to tab whenever onUpdated is called, meaning you can't read the URL.  

If you specify a unique callback for onUpdated, it should check the url property of the second argument passed to it.  This can be null, though, from the documentation: http://code.google.com/chrome/extensions/tabs.html#event-onUpdated

~Arne


--
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.


joejph

unread,
Dec 21, 2010, 8:22:07 AM12/21/10
to Chromium-extensions
In my real code, I have used two different handler.

And the handler for onUpdated is :

function checkForValidUrl(tabId, changeInfo, tab)
{
alert(tab.url);
}

In my first post, I haven't check that code carefully.

I really cares about the handler for onCreated, because I want check
the newly created tab's URL before loading.

Adding handler for onCreated is a right way to achieve this?
Or is there another way to achieve this?

Thanks.
> > 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<chromium-extensions%2Bunsubscr...@chromium.org>
> > .
Reply all
Reply to author
Forward
0 new messages