Persistent iframe in background

2,447 views
Skip to first unread message

Jerzy

unread,
Apr 8, 2010, 10:04:46 AM4/8/10
to Chromium-extensions
Is it possible to have a background page with an iframe, which will be
loaded only once a session, and a popup, which will contain an iframe
with the background page? Now each time I open a popup, the iframe
refreshes. I want it to be persistent.

Antony Sargent

unread,
Apr 8, 2010, 1:49:54 PM4/8/10
to Jerzy, Chromium-extensions
Maybe. See this recent thread for a possible way to do this:




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


Jerzy Głowacki

unread,
Apr 9, 2010, 6:48:12 AM4/9/10
to Antony Sargent, Chromium-extensions
Unfortunately, document.importNode doesn't work properly with iframes
- I can see it but its content refreshes each time I open a popup.
Maybe it is a bug of Google Chrome?

Antony Sargent

unread,
Apr 9, 2010, 3:03:19 PM4/9/10
to Jerzy Głowacki, Chromium-extensions
Did you try getting the handle to iframe's window via chrome.extension.getBackgroundPage().frames and then call importNode on that (as opposed to calling importNode on the iframe node)?


2010/4/9 Jerzy Głowacki <jerzyg...@gmail.com>

Dmitry Titov

unread,
Apr 9, 2010, 8:24:07 PM4/9/10
to Antony Sargent, Jerzy Głowacki, Chromium-extensions
In Chromium, you could use adoptNode instead of importNode to pass the whole iframe, alive, between documents.

var iframe = bgPage.document.getElementById("my_iframe");
document.adoptNode(iframe);
someElement.appendChild(iframe);

This is known as "magic iframe" feature :-) It keeps the iframe alive and does not reload it. Timers continue ticking, XHRs continue loading etc. Same trick can be used to 'park it back' to background page once it is not needed on a popup anymore.


PhistucK

unread,
Apr 10, 2010, 4:42:48 AM4/10/10
to Dmitry Titov, Antony Sargent, Jerzy Głowacki, Chromium-extensions
Regarding "Same trick can be used to 'park it back' to background page once it is not needed on a popup anymore." - I am not sure about that, since we do not have real unload handlers in a browser\pageAction popup (so it will be quick to close it). At least in the need of parking it back once the popup is closed.

☆PhistucK


2010/4/10 Dmitry Titov <dim...@chromium.org>

PhistucK

unread,
Apr 10, 2010, 5:14:00 AM4/10/10
to Antony Sargent, Jerzy Głowacki, Chromium-extensions
background page -
<!DOCTYPE HTML>
<html>
 <body>
  <iframe id="GoogleTalk" src="http://talkgadget.google.com/talkgadget/popout"></iframe>
 </body>
</html>

Popup page -
<!DOCTYPE HTML>
<html>
 <head>
 </head>
 <body>
  <script>
   var GoogleTalkClient = document.importNode(chrome.extension.getBackgroundPage().frames[0]);
   document.body.appendChild(GoogleTalkClient)
  </script>
 </body>
</html>

Popup page JavaScript error -
Uncaught Error: NOT_SUPPORTED_ERR: DOM Exception 9

I also tried "adoptNode".

But, this one is partly working -
<!DOCTYPE HTML>
<html>
 <head>
 </head>
 <body>
  <script>
   var GoogleTalkClient = document.importNode(chrome.extension.getBackgroundPage().document.getElementById("GoogleTalk"));
   document.body.appendChild(GoogleTalkClient)
  </script>
 </body>
</html>

It seems like the page, or the plugin, is re-loaded when I use "importNode". However, when I use "adaptNode", it brings the iframe into the popup page, but it remains empty for some reason.

Any idea?

☆PhistucK


2010/4/9 Antony Sargent <asar...@chromium.org>

PhistucK

unread,
Apr 12, 2010, 12:35:30 AM4/12/10
to Dmitry Titov, Antony Sargent, Jerzy Głowacki, Chromium-extensions
I cannot really resize the popup window.
When I open the popup page in Chrome, like a regular page (by URL), I experience the same behavior.
The iFrame was indeed adopted, along with its content, but its Flash content remains blank.

The unpacked extension is attached (I hard coded the ID).
Go to chrome-extension://fbpokmljcipbpgamjomaldihgicgagmo/popup.html to see what happens.

☆PhistucK


On Mon, Apr 12, 2010 at 06:18, Dmitry Titov <dim...@google.com> wrote:
adoptNode should work... It might still have a bug where content is not re-rendered - does it appear if you resize the popup window?
GoogleTalk.zip

PhistucK

unread,
Oct 9, 2010, 7:34:25 AM10/9/10
to ionas, Chromium-extensions
Even if I did, the popup does not have an onbeforeunload\onunload event, so you cannot move it back to the background page in order to adopt it again in the popup once re-opened, so it does not really matter.

PhistucK



On Sat, Oct 9, 2010 at 00:06, ionas <j0n4s.h...@googlemail.com> wrote:
Hello,

could you make document.adaptNode work?
document.importNode "works" but refreshes the iFrame and thus its not
persistent.
Did you find another way to reload a complete remote website (Google
Talk Widget makes sense)


On Apr 12, 6:35 am, PhistucK <phist...@gmail.com> wrote:
> I cannot really resize the popup window.
> When I open the popup page in Chrome, like a regular page (by URL), I
> experience the same behavior.
> The iFrame was indeed adopted, along with its content, but its Flash content
> remains blank.
>
> The unpacked extension is attached (I hard coded the ID).
> Go to chrome-extension://fbpokmljcipbpgamjomaldihgicgagmo/popup.html to see
> what happens.
>
> ☆PhistucK
>
>
>
> On Mon, Apr 12, 2010 at 06:18, Dmitry Titov <dim...@google.com> wrote:
> > adoptNode should work... It might still have a bug where content is not
> > re-rendered - does it appear if you resize the popup window?
>
> >> But, this one is *partly* working -

> >> <!DOCTYPE HTML>
> >> <html>
> >>  <head>
> >>  </head>
> >>  <body>
> >>   <script>
> >>    var GoogleTalkClient =
> >> document.importNode(chrome.extension.getBackgroundPage().document.getElemen tById("GoogleTalk"));

> >>    document.body.appendChild(GoogleTalkClient)
> >>   </script>
> >>  </body>
> >> </html>
>
> >> It seems like the page, or the plugin, is re-loaded when I use
> >> "importNode". However, when I use "adaptNode", it brings the iframe into the
> >> popup page, but it remains empty for some reason.
>
> >> Any idea?
>
> >> ☆PhistucK
>
> >> 2010/4/9 Antony Sargent <asarg...@chromium.org>

>
> >> Did you try getting the handle to iframe's window via
> >>> chrome.extension.getBackgroundPage().frames and then call importNode on that
> >>> (as opposed to calling importNode on the iframe node)?
>
> >>> 2010/4/9 Jerzy Głowacki <jerzyglowa...@gmail.com>

>
> >>> Unfortunately, document.importNode doesn't work properly with iframes
> >>>> - I can see it but its content refreshes each time I open a popup.
> >>>> Maybe it is a bug of Google Chrome?
>
> >>>> On Thu, Apr 8, 2010 at 7:49 PM, Antony Sargent <asarg...@chromium.org>

> >>>> wrote:
> >>>> > Maybe. See this recent thread for a possible way to do this:
>

>
> >>>  --
> >>> 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
> >>> .
> >>> For more options, visit this group at
> >>>http://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

> >> .
> >> For more options, visit this group at
> >>http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
>  GoogleTalk.zip
> 1KViewDownload

ionas

unread,
Oct 9, 2010, 12:39:58 PM10/9/10
to Chromium-extensions
So, what do you suggest to make persistent popups? Did you find a way
to include that google talk remote widget?

On Oct 9, 1:34 pm, PhistucK <phist...@gmail.com> wrote:
> Even if I did, the popup does not have an onbeforeunload\onunload event, so
> you cannot move it back to the background page in order to adopt it again in
> the popup once re-opened, so it does not really matter.
>
> ☆*PhistucK*
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
>
> > > >>> .
> > > >>> For more options, visit this group at
>
> >http://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>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>

ionas

unread,
Oct 9, 2010, 1:16:01 PM10/9/10
to Chromium-extensions
Yes, I understood why adoptNode does not work:
http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-adoptNode
(it does not create a second reference but "adopts" e.g. takes control
of that DOM node)

So if importNode does refresh iframes (which can be seen as a bug or a
feature?!) did you (or any of you) find another way to create
persistent popups and/or include remote widgets?


p.s.: any reason, why popups do not have onbeforeunload/onunload/
onclose events?


On Oct 9, 1:34 pm, PhistucK <phist...@gmail.com> wrote:
> Even if I did, the popup does not have an onbeforeunload\onunload event, so
> you cannot move it back to the background page in order to adopt it again in
> the popup once re-opened, so it does not really matter.
>
> ☆*PhistucK*
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
>
> > > >>> .
> > > >>> For more options, visit this group at
>
> >http://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>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>

PhistucK

unread,
Oct 11, 2010, 2:47:10 AM10/11/10
to ionas, Chromium-extensions
Inline comments.

PhistucK



On Sat, Oct 9, 2010 at 19:16, ionas <j0n4s.h...@googlemail.com> wrote:
Yes, I understood why adoptNode does not work:
http://www.w3.org/TR/DOM-Level-3-Core/core.html#Document3-adoptNode
(it does not create a second reference but "adopts" e.g. takes control
of that DOM node)


It would have worked if you had those events, because then you would just switch the control back to the background page.
 
So if importNode does refresh iframes (which can be seen as a bug or a
feature?!) did you (or any of you) find another way to create
persistent popups and/or include remote widgets?


Sadly, no.


p.s.: any reason, why popups do not have onbeforeunload/onunload/
onclose events?


It would delay the closure of the popup, which is unacceptable for the user experience in their opinion.
I would simply not allow any dialog to show and let the popup have a few seconds of finishing up while being already hidden. :( It is not like plugin processes do not do that already (when you close a page, its plugins are still active for some time).

To post to this group, send email to chromium-...@chromium.org.
To unsubscribe from this group, send email to chromium-extens...@chromium.org.

ionas

unread,
Oct 11, 2010, 5:31:06 AM10/11/10
to Chromium-extensions
Hello,

it is really sad that there is no rather easy (or none at all?) way to
render remote widgets as persistent popups. I do not see issues there
and its already possible, but not in a persistent way :(.

the last idea I had, but could not fully implement was:
1. Adopting from Background - Cloning within the Popup - and pushing
back to the Background (.e.g. adopting from the Popup).
2. Each time content within the iframe changes (e.g. iframe location
or src="" changes or a user would hit /enter/ within or onclick onto
the iframe) it would push it back to the Background.

// something along this:
function pull() {
var bg = chrome.extension.getBackgroundPage();
var node =
document.adoptNode(bg.document.getElementById("container"), true);
var nodeClone = node.cloneNode(true); // maybe I could just use
cloneNode once instead of multiple adoptNode
document.body.appendChild(node);
var node =
bg.document.adoptNode(document.getElementById("container"), true);
bg.document.body.appendChild(node);
document.body.appendChild(nodeClone);
}

function push() {
var bg = chrome.extension.getBackgroundPage();
var node =
bg.document.adoptNode(document.getElementById("container"), true);
var nodeClone = node.cloneNode(true);
bg.document.body.appendChild(node);
var node =
document.adoptNode(bg.document.getElementById("container"), true);
document.body.appendChild(node);
bg.document.body.appendChild(nodeClone);
}


The issues I have/had are:
1. I am not sure if cloneNode enables persistent transport of iframes
between dom trees. There are probably other hacks around this:
http://codingforums.com/showpost.php?p=499157&postcount=2 (I had
issues with SameOrigin on this one)
http://psoug.org/snippet/Javascript-Copy-IFRAME-contents_124.htm
http://www.quirksmode.org/bugreports/archives/2004/11/Cloning_nodes_from_an_iframe.html
http://msdn.microsoft.com/en-us/library/ms536365(VS.85).aspx (IE
specific but maybe still useful)


2. I guess if you adopt from the popup there will be a tiny second
where the UI moves around as the actual DOM tree is modified. This is
rather unacceptable.

3. I found no way to detect interaction with the iframe.

setInterval(function () {
alert($('#iframe').attr('src')); // won't change if the user
navigates around :/
}, 3 * 1000);

... didn't change when the user interacted with the iFrame + if it
worked, it would work with GET only, not on changes done via POST/PUT/
DELETE on the same http address.


If any of you find any way in future or if this issue is being
resolved (direct support for persistent popups or onunload/
onbeforeunload),
...: please let me know!

Until then,
Jonas H.





On Oct 11, 8:47 am, PhistucK <phist...@gmail.com> wrote:
> Inline comments.
>
> ☆*PhistucK*
> > > > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
> > <chromium-extensions%252Bunsubscr...@chromium.org<chromium-extensions%25252Bunsubscr...@chromium.org>
>
> > > > > >>> .
> > > > > >>> For more options, visit this group at
>
> >http://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>
> > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
>
> > > > <chromium-extensions%2Bunsubscr...@chromium.org<chromium-extensions%252Bunsubscr...@chromium.org>
> > <chromium-extensions%252Bunsubscr...@chromium.org<chromium-extensions%25252Bunsubscr...@chromium.org>
>
> > > > > >> .
> > > > > >> For more options, visit this group at
>
> >http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
> > > > >  GoogleTalk.zip
> > > > > 1KViewDownload
>
> > --
> > 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.

bob Shi

unread,
Aug 26, 2013, 11:10:54 PM8/26/13
to chromium-...@chromium.org
I have the save problem.have you solved the problem?

在 2010年4月8日星期四UTC+8下午10时04分46秒,Jerzy写道:

bookma...@gmail.com

unread,
Dec 16, 2013, 7:27:41 PM12/16/13
to chromium-...@chromium.org
I have the same problem and would be very grateful if someone has an answer. I manage to keep the user on the same page using cookies/php, but tough with the fields. Thanks alot
Reply all
Reply to author
Forward
0 new messages