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.

Comments

rfay’s picture

Version: 6.x-dev » 7.x-dev

We need to fix D7 first, unless it's not an issue there. Thanks for tracking this down!

EvanDonovan’s picture

@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...

rfay’s picture

Status: Needs review » Needs work

There 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.

guddomeNt’s picture

The 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?

rfay’s picture

@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!

guddomeNt’s picture

Providing 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?

rfay’s picture

No, 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!

guddomeNt’s picture

StatusFileSize
new942 bytes

OK, 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:

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.

rfay’s picture

Status: Needs work » Needs review
cosmicdreams’s picture

very 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.

cosmicdreams’s picture

ok, stepping in to test this. updating my dev site to most recent cvs and tracking down the extension you referenced.

cosmicdreams’s picture

Test 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.

sun’s picture

Status: Needs review » Needs work
Issue tags: +Chrome

See 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.

guddomeNt’s picture

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.

As 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.

sun’s picture

Status: Needs work » Needs review
StatusFileSize
new1.75 KB

Don't think you misunderstood me.

However, forgot to add a short comment about the technically improper header.

Anyway, please test.

cosmicdreams’s picture

@sun, I hope to be able to test this on Wednesday night!

rfay’s picture

Issue tags: -Chrome

Status: Needs review » Needs work
Issue tags: +Chrome

The last submitted patch, drupal.ajax-form-upload-chrome.15.patch, failed testing.

bryancasler’s picture

subscribe

Sometimes I get the following error when installing modules

http://awesomescreenshot.com/0f99f8p66

hairyfro’s picture

sub

deggertsen’s picture

Issue summary: View changes

Some 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...

selwynpolit’s picture

I 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.

Status: Needs work » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.