I have experienced some weird errors with ajax in Chrome. Googling around suggests that others have the same issues. I finally tracked the problem down to a browser extension, which injects some html code into the document of a page. Since the ajax file-upload responder responds with a content-type of text/html, the browser extension thinks it's safe to modify the response. The result being a parse-error, when the ajax library tries to parse the json response.
There are different ways to go about this - The best would probably be to respond with the proper content-type, but there seems to be a reason for the current behavior. Instead, I have created a small patch to the javascript, which recovers from this particular error. It doesn't do change behavior for other cases.
I realise that this is a fairly niche case, and probably the fault of the extension-writer, however Chrome is becoming an increasingly popular browser, and this could save many hours of debugging cryptic bug reports from users.
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | drupal.ajax-form-upload-chrome.15.patch | 1.75 KB | sun |
| #8 | chrome-ajax.DRUPAL-7-0-BETA2.patch | 942 bytes | guddomeNt |
| chrome-ajax.patch | 939 bytes | guddomeNt |
Comments
Comment #1
rfayWe need to fix D7 first, unless it's not an issue there. Thanks for tracking this down!
Comment #2
EvanDonovan commented@rfay: I get those "HTTP error 0" error messages on Drupal.org also, when I try to use the project autocomplete. I am using Firefox, so I am not sure if this is just a Chrome issue...
Comment #3
rfayThere are a million ways to get "HTTP Error 0" on firefox and chrome; you can just search the issue queue for them. We've tried to improve the error reporting in D7 to help us track them down. Autocomplete is one of the classic examples, and there's a bug open on that.
Some of them are really Firefox's fault and the way it handles AJAX requests; others are when something corrupts the ajax response (like debugging added to a page that gets added to the ajax response). But there are dozens of open issues of this type.
And our policy is to solve bug reports on the current version first, then backport.
Comment #4
guddomeNt commentedThe problem exists in both D6 and D7 - I found it first in D6, but figured you would rather have a patch for D7, so I ported it there. Do you want me to provide a separate patch for each version?
Comment #5
rfay@troelskn, best to start with D7.
Please make sure to specify the *exact* version of this problem with an explicit test case that can be replicated on a plain-vanilla drupal install (with no contrib modules).
Thanks for your work on this!
Comment #6
guddomeNt commentedProviding a test case can be quite tricky, since it only fails on chrome with a particular plugin installed. Is a written step-by-step guide good enough, or do you require an automated test?
Comment #7
rfayNo, what we need is a step-by-step "how to recreate this bug". Lots of people have chrome.
You also need to assure us that this isn't a bug in the plugin. If this only happens with one plugin and with chrome you'll have a hard time getting action.
Can you make any authoritative statement that "this is the way it should work" instead of "this is what fixes the bug that I have with this one plugin"?
And looking forward to your D7 patch. Thanks!
Comment #8
guddomeNt commentedOK, so I had time to look at this now. I have attached a new patch, which was made against DRUPAL-7-0-BETA2.
To replicate:
/node/add/articleand click "select file" for the field "image". Click upload. You'll be greeted with an error.The supplied patch will strip off the injected html-code (a div) and recover from the error, so that the ajax file-upload works as expected.
Note that this is a workaround for a very specific configuration of browsers. I think it's worth including for two reasons: 1) It doesn't do have any impact on normal execution flow of code since it's confined to the error-handler, and 2) This is potentially a very hard-to-track-down bug.
Comment #9
rfayComment #10
cosmicdreams commentedvery interesting... However, in order to truly know if this is an issue for dev we'd have to test with the most recent dev version. I'll be able to test this either tonight or tomorrow night.
I'll be able to test with Chrome 8 beta and Chrome 9 (Canary Build). I suspect that I'll be able to do a conclusive test even without testing with Chrome 7 since they'll likely have chrome 9 finalized before the end of January. Man those folks move fast.
Comment #11
cosmicdreams commentedok, stepping in to test this. updating my dev site to most recent cvs and tracking down the extension you referenced.
Comment #12
cosmicdreams commentedTest case 1: Fresh cvs, without the extension, node/add/article:
* select a file to upload, uploaded fine
Test case 2: Fresh cvs, with the extension, node/add/article:
* selected a file to upload, tried to upload, received error. and a very descriptive debug report
Test case 3: Fresh cvs, with the extension, applied the patch, node/add/article
* selected a file to upload, tried to upload, received same error
So it looks like this patch needs to be re-rerolled to head.
Comment #13
sunSee end of http://api.drupal.org/api/drupal/includes--ajax.inc/function/ajax_deliver/7
So I guess this error only happens with file uploads? For all other AJAX requests, we're setting a text/javascript Content-Type header.
Note that the link to jQuery Form's documentation has changed: http://malsup.com/jquery/form/#file-upload
There, I don't see a note or warning about the HTTP header to use. Thus, I wonder whether we could always send a text/javascript header, even if there is a file upload and we're wrapping the response in a textarea. While technically wrong, it sounds like it would solve this issue.
Comment #14
guddomeNt commentedAs far as I can tell, that is technically the right thing to do, so if it's possible, it's a much better solution. I just assumed that there was a reason for this hack.
Edit: Disregard my comment. I misunderstood you.
Comment #15
sunDon't think you misunderstood me.
However, forgot to add a short comment about the technically improper header.
Anyway, please test.
Comment #16
cosmicdreams commented@sun, I hope to be able to test this on Wednesday night!
Comment #17
rfay#15: drupal.ajax-form-upload-chrome.15.patch queued for re-testing.
Comment #19
bryancasler commentedsubscribe
Sometimes I get the following error when installing modules
http://awesomescreenshot.com/0f99f8p66
Comment #20
hairyfro commentedsub
Comment #21
deggertsen commentedSome people here mentioned duplicate issues. Could anybody list some of them? I'm wondering if any progress has been made on this in the last 3 years...
Comment #22
selwynpolit commentedI am seeing something like this on a D7 site with an image field. When I add an image and click the upload button, I get an error box but only in my standard Chrome (on mac, with several extensions installed.) When I use Firefox or incognito Chrome, I don't see the error. I haven't tried the patch below but I may if I get the time.
An AJAX HTTP request terminated abnormally. Debugging information follows.
Path: /file/ajax/field_inserted_image/und/
form-zzzzzzzzzzzz <---some gobbledegook here
StatusText: n/a
ResponseText: [{"command":"settings", "settings":{"basePath":"/",".... etc.