[crx] Using getViews to get the popup window

1,104 views
Skip to first unread message

tazz_ben

unread,
May 24, 2010, 1:08:18 PM5/24/10
to Chromium-extensions
Ok, so I'm trying to update an already running pop-up (browser action)
from the background page. I have this code:

var views = chrome.extension.getViews();
for (var i = 0; i < views.length; i++) {
var view = views[i];
console.log(view);
if (view.location.href == 'popup.html'){
view.UpdateProjectList();
}
}

The problem is that it never gets into the if statement. I did the
console.log there to see what was going on and I got a bunch of empty
objects. A running popup is a "view" correct?

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

Mohamed Mansour

unread,
May 24, 2010, 1:56:51 PM5/24/10
to tazz_ben, Chromium-extensions
Hi Ben, I believe you would need to do: chrome.extension.getURL('popup.html') instead since view.location.href gives you the full URL.

-
Mohamed Mansour
m...@chromium.org

Vokuro

unread,
May 24, 2010, 1:44:04 PM5/24/10
to Chromium-extensions
uhm, i don't think my post showed up, so i'll type it again.
that code should work, but it really depends on WHEN you run it, to
actually get the popup view it has to be open at the moment, i use the
following function to do this

function getPopupPage(){
if(chrome.extension.getViews()[1]){
return chrome.extension.getViews()[1];
}else{
return false;
}
}

which is used, for example when new data arrives to the background
page ( it tries to get the view, if it doesn't exist, returns false,
else return the view)

if(getPopupPage()){
getPopupPage().dosomething()
}else{
//.... do something else, update icon badge perhaps?
}

if you only have a background and a popup , the popup view index on
the array should be 1.

On May 24, 1:08 pm, tazz_ben <b...@wbpsystems.com> wrote:
> Ok, so I'm trying to update an already running pop-up (browser action)
> from the background page.  I have this code:
>
> var views = chrome.extension.getViews();
>         for (var i = 0; i < views.length; i++) {
>                 var view = views[i];
>                 console.log(view);
>                 if (view.location.href == 'popup.html'){
>                         view.UpdateProjectList();
>                 }
>         }
>
> The problem is that it never gets into the if statement.  I did the
> console.log there to see what was going on and I got a bunch of empty
> objects.  A running popup is a "view" correct?
>
> --
> 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.

Pedro Junior

unread,
May 24, 2010, 2:45:35 PM5/24/10
to Vokuro, Chromium-extensions
By the way you can use:
chrome.experimental.extension.getPopupView() 

2010/5/24 Vokuro <such...@gmail.com>

tazz_ben

unread,
May 24, 2010, 3:07:26 PM5/24/10
to Chromium-extensions
Mohamed -

Yeah, I found the note on the getURL after I posted, and that does
work. However, I'm still perplexed why posting the object to the
console results in an empty object. That can make debugging pretty
difficult.

Pedro -

Do you know where the documentation is for getPopupView? It isn't on
http://code.google.com/chrome/extensions/extension.html , is it an
experimental method?



On May 24, 11:45 am, Pedro Junior <vj...@live.com> wrote:
> By the way you can use:
>
> > chrome.experimental.extension.getPopupView()
>
> 2010/5/24 Vokuro <suchi...@gmail.com>
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .
> > > For more options, visit this group athttp://
> > groups.google.com/a/chromium.org/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...@chromium.org.
> > To unsubscribe from this group, send email to
> > chromium-extensions+unsubscr...@chromium.org<chromium-extensions%2Bunsubscr...@chromium.org>
> > .

Pedro Junior

unread,
May 24, 2010, 3:40:49 PM5/24/10
to tazz_ben, Chromium-extensions
Yes is experimental and isn't documented. but always worked for me.

2010/5/24 tazz_ben <b...@wbpsystems.com>

Pedro -

Do you know where the documentation is for getPopupView?  It isn't on
http://code.google.com/chrome/extensions/extension.html , is it an
experimental method?

Mohamed Mansour

unread,
May 24, 2010, 4:29:49 PM5/24/10
to v.ju.n...@gmail.com, tazz_ben, Chromium-extensions
Well experimental only works if you enable a flag in the chrome, not ideal for production yet since it can change.

Ben, it works for me, I see the DOM object printed in the console. I am using Google Chrome 6.0.408.1 (Official Build 47574) dev (http://www.chromium.org/getting-involved/dev-channel)


-
Mohamed Mansour
m...@chromium.org
Reply all
Reply to author
Forward
0 new messages