I am having trouble getting getSelected to read at all.
my code is:
var url, title;
chrome.tabs.getSelected(null, function(tab){
url = tab.url;
title = tab.title;
console.log(tab);});
but it never seems to execute the function as I step through in the
debugger, and url and title are always undefined. Is there something
I am doing wrong with my request?
On Nov 24, 1:49 pm, lorenx <[email protected]> wrote:
> hi,
> i found out that the extension behavior about the tab properties
> differ between the two modes, production and development:
> if i use the popup normally i don't need to wait for the onupdated
> listener (the page is already loaded) but if i'm in dev mode, the
> popup is called now from chrome-extension://<extension-id>/popup.html,
> i need the listener to ensure the title not to be undefined.
>
> i'm try to fix both the behavior in one solution but it is not so
> essential...
> thanks.
>
> On Nov 23, 11:34 pm, lorenx <[email protected]> wrote:
>
>
>
> > perfect!
> > and... sorry but... how to combine both?
>
> > something like:
>
> >chrome.tabs.getSelected(null, function(tab){
> > chrome.tabs.onUpdated.addListener(function(tab.id, changeInfo, tab2)
> > {
> > // code here...
> > });
>
> > });
>
> > or:
>
> > chrome.tabs.onUpdated.addListener(function(<what_here?>, changeInfo,
> > tab) {
> > chrome.tabs.getSelected(null, function(tab){
> > // code here...
> > });
>
> > });
>
> > On Nov 23, 8:34 pm, Rafael Weinstein <[email protected]> wrote:
>
> > > You need to listen to chrome.tabs.onUpdated event.
>
> > >http://code.google.com/chrome/extensions/tabs.html#event-onUpdated
>
> > > something like
>
> > > chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
> > > if (changeInfo.status == 'complete') {
> > > tabUrl = tab.url;
> > > tabTitle = tab.title;
> > > createLink();
> > > }
>
> > > On Sun, Nov 22, 2009 at 11:59 AM, lorenx <[email protected]> wrote:
> > > > ok, i did it. thank you!
>
> > > > but the tab is loading and the title is still not available...
> > > > how to wait for the tab to be completly loaded?
>
> > > > On Nov 22, 5:27 am, donaddon <[email protected]> wrote:
> > > >> I'm not sure I understand what you are expecting, but getSelected is
> > > >> an asynchronous call. So you can't expect tabUrl and tabTitle to be
> > > >> set at the time you are currently calling createLink. They will only
> > > >> be set when the callback function is called. You may be looking to do
> > > >> something like this:
>
> > > >>chrome.tabs.getSelected(null, function(tab) {
> > > >> tabUrl = tab.url;
> > > >> tabTitle = tab.title;
> > > >> createLink();
>
> > > >> });
>
> > > >> On Nov 21, 6:21 am, lorenx <[email protected]> wrote:
>
> > > >> > hi all,
> > > >> > i have a problem getting current tab info.
>
> > > >> > var tabUrl;
> > > >> > var tabTitle;
> > > >> > function getTabInfo() {
> > > >> > chrome.tabs.getSelected(null, function(tab){
> > > >> > console.dir(tab);
>
> > > >> > tabUrl = tab.url;
> > > >> > tabTitle = tab.title;
> > > >> > });}
>
> > > >> > function createLink() {
> > > >> > console.log(tabUrl + '|' + tabTitle);}
>
> > > >> > getTabInfo();
> > > >> > createLink();
>
> > > >> > what's wrong with this code?
> > > >> > the tab object is output after createLink() is called...
> > > >> > should i have to set up some communication system between components?
> > > >> > thanks.
>
> > > > --
>
> > > > You received this message because you are subscribed to the Google
> > > > Groups "Chromium-extensions" group.
> > > > To post to this group, send email to
> > > > [email protected].
> > > > To unsubscribe from this group, send email to
> > > > [email protected].
> > > > For more options, visit this group
> > > > athttp://groups.google.com/group/chromium-extensions?hl=.
--
You received this message because you are subscribed to the Google Groups
"Chromium-extensions" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/chromium-extensions?hl=en.