WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED WONTFIX
10815
Exception not raised when creating a script element with a non-existent source
https://bugs.webkit.org/show_bug.cgi?id=10815
Summary
Exception not raised when creating a script element with a non-existent source
Kem Apak
Reported
2006-09-11 14:54:46 PDT
The code below throws an exception in Firefox, IE, and Safari, but unfortunately even the exception is logged to the debug window in Safari, it never goes into the catch block, therefore I cannot handle this exception. The exception is trying to catch a bad URI. function loadBadScript() { var badScript = document.createElement('script'); try { badScript.src = 'nonexistantScript.js'; document.appendChild(badScript); } catch(e) { alert('exception caught'); } } The same is true for images as well. Assigning and incorrect URI to the src of the image does not throw an exception, we can partially handle this with onerror property, but it is too late then. Thanks, Kem
Attachments
test case
(1.10 KB, text/html)
2006-09-12 14:38 PDT
,
Alexey Proskuryakov
no flags
Details
View All
Add attachment
proposed patch, testcase, etc.
Alexey Proskuryakov
Comment 1
2006-09-11 21:40:56 PDT
I do get an alert in a current build, so closing as WORKSFORME. Please verify that it works correctly with a nightly build from <
http://nightly.webkit.org
>. Actually, I do not get a console message in stock 10.4.7 Safari/WebKit (just an error in Activity window).
Kem Apak
Comment 2
2006-09-12 14:22:15 PDT
Hi Alexey, Thanks for checking the bug. Unfortunately I tested the bug in the latest version of the WebKit and it did not work. I am attaching my complete HTML prototype code. I am expection to get an exception. The code never goes into the catch block. Here is the code. Please let me know if I am missing something. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
"> <html xmlns="
http://www.w3.org/1999/xhtml
"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" /> <title>Exception Handling Bug Demo in WebKit</title> <script type="text/javascript" language="javascript"> /** * This method is used to load 3rd party scripts. * * @author Kem Apak * @param uri The URI of the script file. */ function loadThirdPartyScript(uri) { var scriptElement = document.createElement('script'); scriptElement.type = 'text/javascript'; scriptElement.language = 'javascript'; try { scriptElement.src = uri; document.getElementById('thirdPartyScriptContainer').appendChild(scriptElement); } catch(exception) { alert(exception); } } </script> </head> <body> <div id="thirdPartyScriptContainer"></div> <script type="text/javascript" language="javascript"> loadThirdPartyScript('nonexistantScript.js'); </script> </body> </html>
Alexey Proskuryakov
Comment 3
2006-09-12 14:38:56 PDT
Created
attachment 10515
[details]
test case Same test as an attachment.
Alexey Proskuryakov
Comment 4
2006-09-12 14:50:25 PDT
I can see how the new test is different - in the first one, the script was appended to the document itself, and this caused an hierarchy exception. I don't get any exception from the new test case in WebKit, but neither do I get one in Firefox. Are you getting different results?
Kem Apak
Comment 5
2006-09-12 22:13:19 PDT
Hi Alexey, Yes it does not work in Firefox as well if we add the scripts inside a container. I will log a bug for them. Thank you very much for helping. Kem
Alexey Proskuryakov
Comment 6
2006-09-17 03:12:17 PDT
This test case crashes WinIE for me. Anyway, I am not aware of any reason to throw an exception here. Mozilla bug report: <
https://bugzilla.mozilla.org/show_bug.cgi?id=352471
>
Ahmad Saleem
Comment 7
2022-08-05 14:16:58 PDT
JS Fiddle Test Case -
https://jsfiddle.net/zk3t1xyh/show
In Safari 15.6 on macOS 12.5, I get following exception in Console (Dev Tools): Failed to load resource: the server responded with a status of 404 () -nonexistantScript.js Similarly in Firefox - I get following: Loading failed for the <script> with source “
https://fiddle.jshell.net/zk3t1xyh/show/light/nonexistantScript.js
”. Same in Chrome: GET
https://fiddle.jshell.net/zk3t1xyh/show/light/nonexistantScript.js
net::ERR_ABORTED 404 ->
ap@webkit.org
- Is this in relation to some other exception? Further, if I take just the JS code from
Comment 0
and turn it into JSFiddle below: Link -
https://jsfiddle.net/dyux7hsf/show
No browser (Chrome Canary 106, Firefox Nightly 105 and Safari 15.6) give any console error. ___ I think at this point since all browsers are working same in both cases, we can mark this as "RESOLVED WONTFIX"? Appreciate your input for my learning as well. Thanks!
Alexey Proskuryakov
Comment 8
2022-08-14 14:25:22 PDT
Yes, I wouldn't expect a DOM exception when appending just because a subresource cannot be loaded.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug