nodejs / node

Node.js JavaScript runtime ✨🐢🚀✨
https://nodejs.org
Other
106.43k stars 29.01k forks source link

Missing ErrorEvent #47587

Open jimmywarting opened 1 year ago

jimmywarting commented 1 year ago

What is the problem this feature will solve?

Where trying to construct a new ErrorEvent... but it was defined.

What is the feature you are proposing to solve the problem?

A few web features can dispatch a ErrorEvent like web workers...

What alternatives have you considered?

No response

bnoordhuis commented 1 year ago

Node doesn't emit ErrorEvents itself so it's questionable if it makes sense to add it.

But... without working code it won't happen in the first place. Go ahead and open a pull request and see how it's received.

jimmywarting commented 1 year ago

As a effort into implementing spec'ed web worker (https://github.com/nodejs/node/issues/43583) (which is highly desirable and upvoted) then the worker.onerror would have to emit a ErrorEvent.

I notice this when i tried to build a more spec comp. web worker.

jimmywarting commented 1 year ago

I have notice other events that Deno also has... here is a list of them: https://github.com/jimmywarting/missing-dom-events#compatibility-table

anyway undici have both of this event builtin, maybe it could just be a mater of just exposing those on the global scope?


There is also a desire to make globalThis inherit EventTarget in some open issue here too. so it can dispatch/emit postMessages, ErrorEvents

github-actions[bot] commented 10 months ago

There has been no activity on this feature request for 5 months and it is unlikely to be implemented. It will be closed 6 months after the last non-automated comment.

For more information on how the project manages feature requests, please consult the feature request management document.

regseb commented 10 months ago
  • CloseEvent: For when a WebbSocket closes.
  • ErrorEvent: For when WebSocket fails and you also get this on globalThis.onerror

ErrorEvent isn't used by WebSocket. The error event of WebSocket returns a generic Event. Maybe only web workers use ErrorEvent.

Now that WebSocket is in Node.js v21 (behind the --experimental-websocket flag), I've opened an issue https://github.com/nodejs/node/issues/50275 to add CloseEvent in Node.js.

github-actions[bot] commented 4 months ago

There has been no activity on this feature request for 5 months. To help maintain relevant open issues, please add the https://github.com/nodejs/node/labels/never-stale label or close this issue if it should be closed. If not, the issue will be automatically closed 6 months after the last non-automated comment. For more information on how the project manages feature requests, please consult the feature request management document.

KhafraDev commented 4 months ago

WebSocket may use ErrorEvents, see the spec: https://html.spec.whatwg.org/multipage/indices.html#event-error

regseb commented 4 months ago

@KhafraDev The https://html.spec.whatwg.org/multipage/indices.html#event-error page describes the general HTML specification. The word WebSocket doesn't appear. For the error event, it indicates that the type may be Event or ErrorEvent.

The MDN page WebSocket: error event indicates only A generic Event.

The WebSocket specification doesn't mention ErrorEvent. For events, it doesn't specify the type of error events, whereas for the close event, it's a CloseEvent:

web-platform-tests only tests Event for error:

If I run the following code in Firefox or Chromium, e is an Event variable.

new WebSocket("ws://localhost:666").addEventListener("error", (e) => console.log(e, e.constructor.name));