How can I execute some JavaScript after a component becomes known to the DO

Hi Vaadin experts!

I have a BrowserFrame component, and I’m trying to react to its ‘popstate’ so that I can keep an eye on what the UI in there is doing.

In my UI.init, I use JavaScript.addFunction to add a server-side listener for the event and register it client-sde as ‘’. I then want to call the function from the BrowserFrame’s iframe’s ‘popstate’:
JavaScript.getCurrent().execute(“document.getElementById(‘theIdOfTheBrowserFrame’).contentWindow.window.onpopstate =”);

When can I do this? In init(), the component isn’t in the DOM yet and so causes a JavaScript exception as the getElementById does not return a node. I tried moving the code into an AttachListener, but this doesn’t work either.

Any help you can offer warmly received.
Thanks, Dan.

SizeReporter addon may be useful.