From: Yuta T. <y.t...@gm...> - 2014-10-28 10:29:24
|
Hi Team, I am writing this e-mail for asking some questions about the scope (e.g. variable and function definition) and DOM tree implementation of HtmlUnit. Now, I would like to execute arbitrary JavaScript codes using the clone (copy) of original JavaScript scope and DOM tree information separately from these of original. I don't want to affect the original scope and DOM tree by executing arbitrary JavaScript codes. So, I tried to write/execute the following arbitrary codes with HtmlUnit 2.13, but does not work well. # cannot copy the information cf. https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scopes_and_Contexts In addition, I tried to execute the following arbitrary JavaScript codes in JavaScriptEngine.java before READY_STATE_COMPLETE of HtmlPage.java. // clone DOM tree HtmlPage tempHtmlPage = htmlPage.clone(); // cannot clone the HtmlPage HtmlPage tempHtmlPage = htmlPage.cloneNode(false); // cannot clone the HtmlPage HtmlPage tempHtmlPage = htmlPage.cloneNode(true); // error at DomNode // clone scope Scriptable globalScope = getScope(htmlPage, null); Context cx = ContextFactory.getGlobal().enterContext(); Scriptable localScope = cx.newObject(globalScope); localScope.setPrototype(globalScope); localScope.setParentScope(null); // 'localScope' does not keep DOM tree information. or final SimpleScriptable tempScope = ((SimpleScriptable) htmlPage.getScriptableObject()).clone(); // 'tempScope' is the same scope of original. So, please tell me the way how to execute arbitrary JavaScript codes using the clone (copy) of scope and DOM information. Looking forward to your help. Regards, Yuta |