Menu

#925 Cross Frame Javascript Errors from on Load event

Latest SVN
closed
RBRi
None
5
2014-01-30
2009-10-06
Eric Peters
No

The javascript has a nondeterministic behavior in WebKit (Safari) but it's deterministic in FireFox 3 + IE7 - in this example you have a frame that accesses javascript properties from the 2nd frame.

I started spying in a local proxy and noticed that the 2nd frame is never getting called...Perhaps what should happen is all frames get downloaded first, and then only ever all frames are downloaded any onload() is triggered?

index.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
Main Page
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
</head>
<script>

    document.write('<FRAMESET rows="*%,140">');
    document.write('<FRAME name=one frameborder=0 src=one.html>');      
    document.write('<FRAME name=two frameborder=0 src=two.html>');
    document.write('</FRAMSET>');
</script>

</html>

one.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<script>
function setForm() {

if( window.parent.frames[1].document.frm.one == undefined) return;
window.parent.frames[1].document.frm.one.value = "";

}
</script>
Two
<body onload="setForm();">
Frame One
</body>
</html>

two.html:

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

<head>
Two
<body>
Frame Two
<form name="frm" id="frm">

<input type="text" id="one" name="one" value="field one">

</form>
</body>
</html>

The Scala Code:
val webClient = new WebClient(BrowserVersion.FIREFOX_3);
var page = webClient.getPageHtmlPage

Scala Exception:

Exception in thread "main" ======= EXCEPTION START ========
EcmaError: lineNumber=[7] column=[0] lineSource=[null] name=[TypeError] sourceName=[script in http://localhost:8090/TestPage/one.html from (4, 9) to (10, 10)] message=[TypeError: Cannot read property "one" from undefined (script in http://localhost:8090/TestPage/one.html from (4, 9) to (10, 10)#7)]
com.gargoylesoftware.htmlunit.ScriptException: TypeError: Cannot read property "one" from undefined (script in http://localhost:8090/TestPage/one.html from (4, 9) to (10, 10)#7)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:526)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:529)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:536)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:456)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:924)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:182)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:201)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:655)
at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:887)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:529)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:536)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:892)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1138)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:189)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:429)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPageIfPossible(BaseFrame.java:136)
at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPage(BaseFrame.java:95)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1778)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:181)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:429)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:362)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:347)
at fm.crawl.CrawlApp$.main(CrawlApp.scala:72)
at fm.crawl.CrawlApp.main(CrawlApp.scala)
Caused by: net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "one" from undefined (script in http://localhost:8090/TestPage/one.html from (4, 9) to (10, 10)#7)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3726)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3704)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3732)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3751)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3764)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1520)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1379)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:427)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:261)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3130)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:80)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:484)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:449)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:520)
... 25 more
Enclosed exception:
net.sourceforge.htmlunit.corejs.javascript.EcmaError: TypeError: Cannot read property "one" from undefined (script in http://localhost:8090/TestPage/one.html from (4, 9) to (10, 10)#7)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3726)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.constructError(ScriptRuntime.java:3704)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError(ScriptRuntime.java:3732)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.typeError2(ScriptRuntime.java:3751)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.undefReadError(ScriptRuntime.java:3764)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.getObjectPropNoWarn(ScriptRuntime.java:1520)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpretLoop(Interpreter.java:1379)
at script.setForm(script in http://localhost:8090/TestPage/one.html from (4, 9) to (10, 10):7)
at script(onload event for HtmlBody[<body onload="setForm();">] in http://localhost:8090/TestPage/one.html)
at net.sourceforge.htmlunit.corejs.javascript.Interpreter.interpret(Interpreter.java:845)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.doTopCall(ContextFactory.java:427)
at com.gargoylesoftware.htmlunit.javascript.HtmlUnitContextFactory.doTopCall(HtmlUnitContextFactory.java:261)
at net.sourceforge.htmlunit.corejs.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3130)
at net.sourceforge.htmlunit.corejs.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
at com.gargoylesoftware.htmlunit.javascript.host.EventHandler.call(EventHandler.java:80)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:484)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$4.doRun(JavaScriptEngine.java:449)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine$HtmlUnitContextAction.run(JavaScriptEngine.java:520)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:529)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:536)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine.callFunction(JavaScriptEngine.java:456)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeJavaScriptFunctionIfPossible(HtmlPage.java:924)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeEventHandler(EventListenersContainer.java:182)
at com.gargoylesoftware.htmlunit.javascript.host.EventListenersContainer.executeBubblingListeners(EventListenersContainer.java:201)
at com.gargoylesoftware.htmlunit.javascript.host.Node.fireEvent(Node.java:655)
at com.gargoylesoftware.htmlunit.html.HtmlElement$2.run(HtmlElement.java:887)
at net.sourceforge.htmlunit.corejs.javascript.Context.call(Context.java:529)
at net.sourceforge.htmlunit.corejs.javascript.ContextFactory.call(ContextFactory.java:536)
at com.gargoylesoftware.htmlunit.html.HtmlElement.fireEvent(HtmlElement.java:892)
at com.gargoylesoftware.htmlunit.html.HtmlPage.executeEventHandlersIfNeeded(HtmlPage.java:1138)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:189)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:429)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPageIfPossible(BaseFrame.java:136)
at com.gargoylesoftware.htmlunit.html.BaseFrame.loadInnerPage(BaseFrame.java:95)
at com.gargoylesoftware.htmlunit.html.HtmlPage.loadFrames(HtmlPage.java:1778)
at com.gargoylesoftware.htmlunit.html.HtmlPage.initialize(HtmlPage.java:181)
at com.gargoylesoftware.htmlunit.WebClient.loadWebResponseInto(WebClient.java:429)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:305)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:362)
at com.gargoylesoftware.htmlunit.WebClient.getPage(WebClient.java:347)
at fm.crawl.CrawlApp$.main(CrawlApp.scala:72)
at fm.crawl.CrawlApp.main(CrawlApp.scala)
== CALLING JAVASCRIPT ==
function () {
[native code, arity=0]
}

Discussion

  • Ahmed Ashour

    Ahmed Ashour - 2009-12-09
    • HtmlFrame2Test.postponeLoading() was added as @NotYetImplemented
    • The attached patch fixes the case, but HtmlFrameTest.frameScriptReplaceOtherFrame() fails
     
  • Ahmed Ashour

    Ahmed Ashour - 2009-12-09

    Fix patch, but HtmlFrameTest.frameScriptReplaceOtherFrame() fails

     
  • RBRi

    RBRi - 2012-02-22

    Now fixed in SVN. Thanks for reporting.

     

Log in to post a comment.