Bug 4343

Summary: XMLHttpRequest doesn't work in a JavaScript-created window
Product: WebKit Reporter: Jacob Weber <jacob>
Component: XMLAssignee: Alexey Proskuryakov <ap>
Status: RESOLVED FIXED    
Severity: Major CC: abarth, bugs-webkit, ian
Priority: P2    
Version: 420+   
Hardware: Mac   
OS: OS X 10.4   
Attachments:
Description Flags
test case
none
test case for landing aroben: review+

Jacob Weber
Reported Tuesday, August 9, 2005 2:14:33 AM UTC
The following page creates an XMLHttpRequest object, makes a request to Google, and displays its progress in alerts: <html><body><script type="text/javascript"> var req = new XMLHttpRequest(); req.onreadystatechange = result; req.open("GET", "http://www.google.com", true); req.send(); function result() {alert(req.responseText);} </script></body></html> This works fine in Safari. However, it's also possible to use JavaScript to write to a new browser window, and it can even write JavaScript into the window. This also works in Safari. However, if we use JavaScript to write the above code, the XMLHttpRequest never gets sent. For example: <html><body><script type="text/javascript"> winRef=window.open(); winRef.document.writeln("<html><body><script type=\"text/javascript\">"); winRef.document.writeln("var req = new XMLHttpRequest();"); winRef.document.writeln("req.onreadystatechange = result;"); winRef.document.writeln("req.open(\"GET\", \"http://www.google.com\", true);"); winRef.document.writeln("req.send();"); winRef.document.writeln("function result() {alert(req.responseText);}"); winRef.document.writeln("<\/script></body></html>"); winRef.document.close(); </script></body></html>
Attachments
test case (366 bytes, text/html)
2005-12-23 02:55 PST, Alexey Proskuryakov
no flags
test case for landing (2.98 KB, patch)
2009-03-03 02:59 PST, Alexey Proskuryakov
aroben: review+
Alexey Proskuryakov
Comment 1 Friday, December 23, 2005 10:53:40 AM UTC
The problem here is that the created document has an about:blank URL, so it isn't considered a local file, and isn't allowed to use XMLHttpRequest.
Alexey Proskuryakov
Comment 2 Friday, December 23, 2005 10:55:12 AM UTC
Created attachment 5244 [details] test case Safari: winRef.document.URL: file:///Users/ap/Desktop/4343.html document.URL: about:blank Firefox 1.5: winRef.document.URL: about:blank document.URL: file:///Users/ap/Desktop/4343.html
Alexey Proskuryakov
Comment 3 Monday, January 2, 2006 10:59:50 AM UTC
See also: bug 5292.
Alexey Proskuryakov
Comment 4 Tuesday, March 3, 2009 10:50:46 AM UTC
This was fixed in <http://trac.webkit.org/projects/webkit/changeset/34506> and related check-ins. Looks like this exact scenario doesn't have a test yet, so I'll make a patch to land a test for XHR from a pop-up window.
Alexey Proskuryakov
Comment 5 Tuesday, March 3, 2009 10:59:37 AM UTC
Created attachment 28218 [details] test case for landing
Adam Roben (:aroben)
Comment 6 Tuesday, March 3, 2009 3:26:37 PM UTC
Comment on attachment 28218 [details] test case for landing r=me
Alexey Proskuryakov
Comment 7 Tuesday, March 3, 2009 4:46:59 PM UTC
Committed revision 41382.
Note You need to log in before you can comment on or make changes to this bug.