Script tag onerror event does not fire if src attribute points to non-existing file://

RESOLVED WORKSFORME

Status

()

Core
DOM: Events
RESOLVED WORKSFORME
6 years ago
5 years ago

People

(Reporter: st777, Unassigned)

Tracking

({testcase})

Trunk
testcase
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

(Reporter)

Description

6 years ago
User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13

I'm attempting to inject a new script tag dynamically into a head element using DOM appendChild. When I inject a script tag that points to a non-existent file, onerror event of the injected script tag does not fire.

Reproducible: Always

Steps to Reproduce:
1. Create a new script tag: var newScript = document.createElement("script");
2. Bind an event to new script element: newScript.onerror = function() { alert('error!');}

3. Set src attribute of new script element to a bogus(non-existent) file: newScript.src = "foo.js";

4. Append new script element to head element: document.getElementsByTagName('head')[0].appendChild(newScript);
Actual Results:  
onError handler in step 2 does not fire

Expected Results:  
onError event must fire to let me know that something is wrong with loading a file

Test script is running locally on a desktop machine and not from a hosted location. Not sure if that makes a difference.

This behavior works correctly in all major browsers such as chrome, safari, IE 7-9
> Test script is running locally on a desktop machine and not from a hosted
> location. Not sure if that makes a difference.

It does.  For file:// URIs this is a known issue.

This is similar to bug 269125, and I was pretty sure we had a duplicate of this for <script> already...

Ms2ger, want to fix?
Whiteboard: DUPEME
Bug 608809?

Last time I looked at our script execution code (or the spec, for that matter), it looked sufficiently scary not to attempt a fix. I could try if you pointed me at the place I'd need to patch, though.
> Bug 608809?

That bug wfm.

> I could try if you pointed me at the place I'd need to patch, though.

We need to fire an error event if AsyncOpen on the script's channel returns failure.

Updated

5 years ago
Depends on: 282432

Updated

5 years ago
Duplicate of this bug: 646214

Comment 5

5 years ago
Created attachment 612394 [details]
testcase from bug 646214

Updated

5 years ago
Status: UNCONFIRMED → NEW
Ever confirmed: true
Keywords: testcase
OS: Windows 7 → All
Hardware: x86_64 → All
Summary: Script tag onerror event does not fire if src attribute points to non-existing file → Script tag onerror event does not fire if src attribute points to non-existing file://
Whiteboard: DUPEME
Version: unspecified → Trunk

Comment 6

5 years ago
As more and more people are unit testing their JavaScript (and often using flat file:// URLs), this bug is pretty annoying.  There is some discussion of workarounds at Stack Overflow: http://stackoverflow.com/questions/4150430
JFYI, according to Asqueella's testcase, WFM.
This got fixed in bug 789856, I would bet...
Status: NEW → RESOLVED
Last Resolved: 5 years ago
Depends on: 789856
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.