Bug 4343 - XMLHttpRequest doesn't work in a JavaScript-created window
Summary: XMLHttpRequest doesn't work in a JavaScript-created window
Alias: None
Product: WebKit
Classification: Unclassified
Component: XML (show other bugs)
Version: 420+
Hardware: Macintosh OS X 10.4
: P2 Major
Assignee: Alexey Proskuryakov
Depends on:
Reported: 2005-08-08 18:14 PDT by Jacob Weber
Modified: 2009-03-03 08:46 PST (History)
3 users (show)

See Also:

test case (366 bytes, text/html)
2005-12-23 02:55 PST, Alexey Proskuryakov
no flags Details
test case for landing (2.98 KB, patch)
2009-03-03 02:59 PST, Alexey Proskuryakov
aroben: review+
Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jacob Weber 2005-08-08 18:14:33 PDT
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);
function result() {alert(req.responseText);}

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.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("function result() {alert(req.responseText);}");
Comment 1 Alexey Proskuryakov 2005-12-23 02:53:40 PST
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.
Comment 2 Alexey Proskuryakov 2005-12-23 02:55:12 PST
Created attachment 5244 [details]
test case

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
Comment 3 Alexey Proskuryakov 2006-01-02 02:59:50 PST
See also: bug 5292.
Comment 4 Alexey Proskuryakov 2009-03-03 02:50:46 PST
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.
Comment 5 Alexey Proskuryakov 2009-03-03 02:59:37 PST
Created attachment 28218 [details]
test case for landing
Comment 6 Adam Roben (:aroben) 2009-03-03 07:26:37 PST
Comment on attachment 28218 [details]
test case for landing

Comment 7 Alexey Proskuryakov 2009-03-03 08:46:59 PST
Committed revision 41382.