Maybe you're trying to output t before your callback has run? Try this:

var t = null;
chrome.tabs.getSelected(null, function(tab) {
  t = tab;
  console.log("t is now set");
  setTimeout(function() {
    console.log("t is " + JSON.stringify(t));
  }, 0);
});



On Wed, Nov 25, 2009 at 3:27 PM, Rlcrock <rlcr...@gmail.com> wrote:

> Ok, so using the debug tools, I can print out the tab using console.log
> (), but when I try to assign to local variables, they do not get
> changed at all.
>
> var t = null;
> chrome.tabs.getSelected(null, function(tab){
>                                                    t = tab;
>                                                   console.log(tab);});
>
> When it runs, the console will have a correct trace, but t will still
> be null.
>
> On Nov 25, 4:02 pm, Rafael Weinstein <rafa...@chromium.org> wrote:
> > Stepping won't work because the function you provide gets called later.
> >
> > Setting a break point inside that function should work.
> >
> > Does it not?
> >
> >
> >
> > On Wed, Nov 25, 2009 at 12:15 PM, Rlcrock <rlcr...@gmail.com> wrote:
> > > 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 <lor...@gmail.com> 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 <lor...@gmail.com> 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 <rafa...@chromium.org> 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 <lor...@gmail.com>
> 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 <don...@verizon.net> 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 <lor...@gmail.com> 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
> chromium-extensi...@googlegroups.com.
> > >> > > > To unsubscribe from this group, send email to
> chromium-extensions+unsubscr...@googlegroups.com<chromium-extensions%2bunsubscr...@googlegroups.com>
> .
> > >> > > > 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
> chromium-extensi...@googlegroups.com.
> > > To unsubscribe from this group, send email to
> chromium-extensions+unsubscr...@googlegroups.com<chromium-extensions%2bunsubscr...@googlegroups.com>
> .
> > > For more options, visit this group athttp://
> groups.google.com/group/chromium-extensions?hl=en.
>
> --
>
> 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...@googlegroups.com.
> To unsubscribe from this group, send email to
> chromium-extensions+unsubscr...@googlegroups.com<chromium-extensions%2bunsubscr...@googlegroups.com>
> .
> For more options, visit this group at
> http://groups.google.com/group/chromium-extensions?hl=en.
>
>
>

--

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...@googlegroups.com.
To unsubscribe from this group, send email to 
chromium-extensions+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/chromium-extensions?hl=en.


Reply via email to