Open Bug 1342259 Opened 7 years ago Updated 2 years ago

Expose a human-readable message to help debug the failure when creating a script element

Categories

(DevTools :: Console, defect, P3)

defect

Tracking

(Not tracked)

REOPENED

People

(Reporter: jujjyl, Unassigned)

Details

Attachments

(1 file)

Attached image script_error.png
Looking at the DOM Level 3 Events error object at 

https://developer.mozilla.org/en-US/docs/Web/Events/error

It looks like that object does not specify any error reason. Why is that?

I have the following function to dynamically add loaded .js code to DOM.

> function addScriptToDom(scriptCode) {
> 	return new Promise(function(resolve, reject) {
> 		var script = document.createElement('script');
> 		var blob = (scriptCode instanceof Blob) ? scriptCode : new Blob([scriptCode], { type: 'text/javascript' });
> 		var objectUrl = URL.createObjectURL(blob);
> 		script.src = objectUrl;
> 		script.onload = function() {
> 			URL.revokeObjectURL(objectUrl); // Free up the blob. Note that for debugging purposes, this can be useful to comment out to be able to read the sources in debugger.
> 			resolve();
> 		}
> 		script.onerror = function(e) {
> 			URL.revokeObjectURL(objectUrl);
> 			console.error('script failed to add to dom: ' + e);
> 			console.error(scriptCode);
> 			console.error(e);
> 			reject(e);
> 		}
> 		document.body.appendChild(script);
> 	});
> }

and it is failing, with the three console.error() prints giving a result as shown in the attachment. Is there a way to get a human readable error reason for why the script failed to be added? This is adding 150MB asm.js code, and I'm quite sure it is due to an OOM, but it would be good to have the browser tell that to the developer?
There is another ErrorEvent object documented at https://developer.mozilla.org/en-US/docs/Web/API/ErrorEvent, which looks more useful and would have a human readable message. What is the history here, does anyone know?
So, you're talking about error event dispatched to <script>. That is defined in HTML spec.
https://html.spec.whatwg.org/multipage/scripting.html#the-script-element
"fire an event named error at the element"
See also https://dom.spec.whatwg.org/#concept-event-fire

If you want to change that, please file an HTML spec bug.
https://whatwg.org/newbug

As of now, this is invalid.
Status: NEW → RESOLVED
Closed: 7 years ago
Resolution: --- → INVALID
Thanks, posted this as https://github.com/whatwg/html/issues/2395.
Let me reopen this, since changing the spec is expected to be a potential security issue, and the suggestion in the above GitHub entry is that browsers themselves should do the error reporting in a way that JS code cannot read the errors.
Status: RESOLVED → REOPENED
Resolution: INVALID → ---
So, if I read it right, the underlying need here is to make the console error message more friendly to developers? "Firefox/Developer Tools: Console" looks like a more proper module for this issue.

Bug 435025 is the meta bug for this kind of improvement.
Summary: Why does the DOM L3 error event not have an error reason? → Expose a human-readable helpful message
Summary: Expose a human-readable helpful message → Why does the DOM L3 error event not have an error reason?
Component: DOM: Events → Developer Tools: Console
Product: Core → Firefox
Summary: Why does the DOM L3 error event not have an error reason? → Expose a human-readable message to help debug the failure when creating a script element
Product: Firefox → DevTools
Priority: -- → P3
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: