Frage

I am developing a firefox extension where I need to save the state of an arbitrary web page in order to be able to restore that webpage later. The quirk is that I need to restore the entire state of the page, including the state of all javascript variables. The "saving" can be done in memory, it doesn't need to be serializable.

So, is there a way to exactly clone a browser element, so that it starts running from the same point of execution that the original is currently at?

If not, how much effort would it require to add this to firefox (using C++), and which files and documentation would I start looking at?

War es hilfreich?

Lösung

No, there isn't a way to do exactly what you want. Even the built-in session restore will only restore form fields (and some other selected things), but not the full JS and native object state.

Implementing something like this yourself not feasible (and would be also a massive task):

  • You could uneval() most js objects, but that will loose type information and you'll only get the source, but not any internal state (think "hidden" state via closures). Native objects like window or document need some special treatment, and getting the internal state isn't exactly always possible here without some C++-level "reflection".
  • You could potentially get a lot of the actual state using the debugger API in new ways, however I don't see any way to actually restore it later. And "a lot" is still not the same as "all".

About the closed-over "hidden" state: There is no way I know of to reliably get the internal state of counter in the following example, let alone restore it later, without getting as low-level as a platform-dependent full memory dump.

var count = (function() {
  var counter = 0;
  return function() { return ++counter; };
})();
count();
count();

Andere Tipps

I guess that you could walk the properties of all objects and save them somewhere but preserving context of e.g. bound functions would be difficult. Maybe you could make some use of the session store?

See: Session_store_API and nsISessionStore

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top