Page 1 of 2 12 LastLast
Results 1 to 10 of 12

This is a discussion on Viewing contents of a Background page? within the Plugins Development section, part of the Chrome Plugins category: Is there any way to view the contents of a background page when I click on say a toolstrip button? ...


  1. #1
    Skyd is offline Junior Member
    Join Date
    Jun 2009
    Posts
    5

    Default Viewing contents of a Background page?

    Is there any way to view the contents of a background page when I click on say a toolstrip button? In other words, I want to have one process running for all of chrome, and the display the contents of that process whenever someone clicks a particular button on the toolstrip. Maybe there's a way to change the window responsible for displaying a webpage by manipulating handles somewhere? I don't know, any ideas?

  2. #2
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    I'm not sure I get what you want to do here.
    You should be able to communicate between toolstrips and background page processes the same way that you can communicate between a toolstrip and a content script.

    Did you try some possible solutions ? Did you get errors ?

    Maybe there's a way to change the window responsible for displaying a webpage by manipulating handles somewhere?
    Hmmm .. not sure I see what you want to do here.

    You should be able to have the toolstrip ask the background page for content and then draw it.

    If your content is static, you can also use XHR.

  3. #3
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    From the toolstrip, you can use chrome.self.getViews() to return all the background pages and toostrips associated with your extension.
    Something like this:
    Code:
    function getBackgroundPage(){
    var views = chrome.self.getViews();
    for(var i in views){
    var itsurl = views[i].document.URL;
    if(itsurl.substr(itsurl.lastIndexOf("/")+1) == "my_background_page.html")
    return views[i];
    }
    }
    You should have complete access to all its JavaScript directly from the return value.
    For example, if you had a variable in your background page named MyVar you can use getBackgroundPage().MyVar from your toolstrip to get the value.

    At least, I think it gets background pages, you can see an example of it accessing a toolstrip here: http://dev.chromium.org/developers/d...ckground-pages
    Last edited by Waha; 06-19-2009 at 11:35 PM.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  4. #4
    Skyd is offline Junior Member
    Join Date
    Jun 2009
    Posts
    5

    Default

    K thanks for your replays. So let me expand a bit on what I'm trying to do, I realize it sounded a bit unclear.

    So what will be running in the background html is an embeded shockwave flash program. The toolstrip button, when clicked, should display this flash program in a small section of the current tab.

    I can't just do something like document.createElement and then embed the flash in the toolstrip html, because that would mean that I'd have a copy of the flash program running for each chrome browser window. I'd like the state of the flash program to be preserved over all chrome browsers, and so the only way I can think of for doing this is by embeding the flash into the background. This way there's only one copy of the flash running at all times. When someone clicks on the toolstrip button, it would simply display the flash program thats running in the background.

    I know you can pass vars around between the toolstrip and background htmls, but I don't know how to display this flash program. Suppose I passed around the HTMLObject that represents the embeded object, how would I display that object? If I did document.getElementsByTagName("body")[0].appendChild(flashObject), wouldn't it create another instance of this flash object and basically reload it? So I'm trying to figure out how to display an embeded object without reloading it. An analogy would be something like window's remote desktop program.

    Hopefully that made it a bit clearer what I'm trying to do.

  5. #5
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    Since the page that you can see and the background page are not running in the same process, I doubt they can share a common element. They can certainly pass data around... but I do not know if it is possible to draw something that is not running in the same process.

    What I recommend is that you post your question on the google extension mailing list [http://groups.google.com/group/chromium-extensions] .. Aaron will be in a much better position to answer you than me.

    You might want to ask the creators of the Aniweather extension. Maybe that's how they did it. You can also check their source code.

  6. #6
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    I'm not sure about that one, I don't really know the finer details of embeds.
    I know how you can put an object into a page from the toolstrip (requires that you communicate with a content script, though), but I don't know how you would preserve the flash data.
    Is there any way you can make the swf talk to the Javascript, save all the data it needs to reinitialize, and then make a new instance of the swf, passing all the data it got from the old one? That's the only way I can think of doing it.
    See this for swf and JS communication: http://maohao.wordpress.com/2007/01/...wf-beyond-101/
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  7. #7
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    The thing is.. it's not that he wants to maintain state (that can be done) .. he wants to save resources by having 1 instance across all browser windows.

    You might want to look into HTML5's canvas tag.. maybe you could use that instead ?

    I know it's not very helpful but.. it might be a viable alternative. In the HTML5 world, flash is going to be (slightly) less useful.

  8. #8
    Waha's Avatar
    Waha is offline Senior Member
    Join Date
    Apr 2009
    Location
    Oregon
    Posts
    788

    Default

    Quote Originally Posted by Kyrax View Post
    The thing is.. it's not that he wants to maintain state (that can be done) .. he wants to save resources by having 1 instance across all browser windows.

    You might want to look into HTML5's canvas tag.. maybe you could use that instead ?

    I know it's not very helpful but.. it might be a viable alternative. In the HTML5 world, flash is going to be (slightly) less useful.
    It would be one thing across all browser windows, it would just become two when you clicked the toolstrip. ^^; I figured it wouldn't be too much of a resource jump, I mean, you could even destroy the one in the background page until the user closes the window (or internal popup or whatever) the toolstrip made.
    ~ Projects ~
    Specialized: Carapass Auction Watcher, Kongregate Chat
    Libraries: bliplib
    Tools: manifest syntax highlighting & snippits
    ~ Happy to make extensions for pay too ;D ~
    Portfolio: Search and Share

  9. #9
    Kyrax is offline Senior Member
    Join Date
    Apr 2009
    Location
    Qc, Canada
    Posts
    495

    Default

    Flash isn't that heavy on resources ( depends what you are doing with it .. )

    But toolstrips only have one instance for every window. It's not that bad, not that many people use multiple windows. Most users have multiple tabs, but a toolstrip is shared across tabs.

  10. #10
    Skyd is offline Junior Member
    Join Date
    Jun 2009
    Posts
    5

    Default

    Hmm okay thanks for your replies. I'll look into html5, sounds fun with o3d and whatnot. Only problem is that it requires the user to specifically install it I think. I'll also look into communicating with swf through javascript.

    One idea I had was what if I could do it similar to switching tabs? You can easily have a button swap the current tab with w/e other tab you're using right? Maybe I can have the background window swap with the current tab when someone presses the toolstrip button, and the swap back once they're done using it. This way there's only one instance and one html, and its container is just being displayed in different places each time. Even across multiple windows, tabs can be moved from one to another. Now I just need to figure out how to get the TabID of the background html...not even sure if it has one.

Page 1 of 2 12 LastLast

Similar Threads

  1. Viewing Saved Passwords
    By CaptainWinky in forum Bugs and Vulnerabilities
    Replies: 1
    Last Post: 03-04-2010, 04:43 PM
  2. Problems viewing youtube
    By snwbordchamp in forum Chrome Troubleshooting
    Replies: 1
    Last Post: 06-12-2009, 06:23 AM
  3. Black Tabs Background? Hmm...
    By dragonic2020 in forum Chrome Talk
    Replies: 2
    Last Post: 05-16-2009, 01:17 PM
  4. Having trouble viewing some media
    By AthenaStarlight in forum Chrome Troubleshooting
    Replies: 7
    Last Post: 05-04-2009, 07:32 PM
  5. Where's the background over-ride color setting?
    By tommy.vinson in forum Chrome Talk
    Replies: 0
    Last Post: 12-12-2008, 01:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •