From f4142069551eb1fa4f1d3215503cef3677a6cfcb Mon Sep 17 00:00:00 2001 From: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> Date: Wed, 18 Sep 2024 06:06:29 +0000 Subject: [PATCH 1/4] move --- files/en-us/_redirects.txt | 1 + files/en-us/web/api/{ => window}/reporterror/index.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) rename files/en-us/web/api/{ => window}/reporterror/index.md (98%) diff --git a/files/en-us/_redirects.txt b/files/en-us/_redirects.txt index b587e9a63a476e3..0c7bef80f7d98ed 100644 --- a/files/en-us/_redirects.txt +++ b/files/en-us/_redirects.txt @@ -10740,6 +10740,7 @@ /en-US/docs/Web/API/range.startOffset /en-US/docs/Web/API/range/startOffset /en-US/docs/Web/API/range.surroundContents /en-US/docs/Web/API/range/surroundContents /en-US/docs/Web/API/range.toString /en-US/docs/Web/API/range/toString +/en-US/docs/Web/API/reportError /en-US/docs/Web/API/Window/reportError /en-US/docs/Web/API/scheduler_property /en-US/docs/Web/API/Window/scheduler /en-US/docs/Web/API/select.type /en-US/docs/Web/API/HTMLSelectElement/type /en-US/docs/Web/API/sessionStorage /en-US/docs/Web/API/Window/sessionStorage diff --git a/files/en-us/web/api/reporterror/index.md b/files/en-us/web/api/window/reporterror/index.md similarity index 98% rename from files/en-us/web/api/reporterror/index.md rename to files/en-us/web/api/window/reporterror/index.md index 0f4c7da6bef1790..04c061a17c6b11a 100644 --- a/files/en-us/web/api/reporterror/index.md +++ b/files/en-us/web/api/window/reporterror/index.md @@ -1,7 +1,7 @@ --- title: reportError() global function short-title: reportError() -slug: Web/API/reportError +slug: Web/API/Window/reportError page-type: web-api-global-function browser-compat: api.reportError --- From ce1263f68a46fabe651640701e8181291e5db615 Mon Sep 17 00:00:00 2001 From: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:53:20 +0800 Subject: [PATCH 2/4] update --- .../mozilla/firefox/releases/93/index.md | 2 +- .../rtcicecandidate/usernamefragment/index.md | 2 +- .../setconfiguration/index.md | 2 +- .../setlocaldescription/index.md | 2 +- .../index.md | 2 +- files/en-us/web/api/web_workers_api/index.md | 2 +- .../signaling_and_video_calling/index.md | 8 +- files/en-us/web/api/window/index.md | 2 +- .../en-us/web/api/window/reporterror/index.md | 24 +++--- .../en-us/web/api/workerglobalscope/index.md | 2 +- .../workerglobalscope/reporterror/index.md | 84 +++++++++++++++++++ files/jsondata/GroupData.json | 2 +- 12 files changed, 110 insertions(+), 24 deletions(-) create mode 100644 files/en-us/web/api/workerglobalscope/reporterror/index.md diff --git a/files/en-us/mozilla/firefox/releases/93/index.md b/files/en-us/mozilla/firefox/releases/93/index.md index f06225ecb7b7ce9..1627d890b8547ae 100644 --- a/files/en-us/mozilla/firefox/releases/93/index.md +++ b/files/en-us/mozilla/firefox/releases/93/index.md @@ -37,7 +37,7 @@ This article provides information about the changes in Firefox 93 that will affe - {{domxref("ElementInternals.shadowRoot")}} and {{domxref("HTMLElement.attachInternals")}} are now supported ([Firefox bug 1723521](https://bugzil.la/1723521)). - The value `device-pixel-content-box` is now supported for {{domxref("ResizeObserver.Observe()")}} ([Firefox bug 1587973](https://bugzil.la/1587973)). -- The {{domxref("reportError()")}} global function is now supported, allowing scripts to report errors to the console or global event handlers, emulating an uncaught JavaScript exception ([Firefox bug 1722448](https://bugzil.la/1722448)). +- The {{domxref("Window.reportError()")}} and {{domxref("WorkerGlobalScope.reportError()")}} is now supported, allowing scripts to report errors to the console or global event handlers, emulating an uncaught JavaScript exception ([Firefox bug 1722448](https://bugzil.la/1722448)). #### Events diff --git a/files/en-us/web/api/rtcicecandidate/usernamefragment/index.md b/files/en-us/web/api/rtcicecandidate/usernamefragment/index.md index 259c3056da3fd22..36cdd81e8ff53a1 100644 --- a/files/en-us/web/api/rtcicecandidate/usernamefragment/index.md +++ b/files/en-us/web/api/rtcicecandidate/usernamefragment/index.md @@ -82,7 +82,7 @@ const ssNewCandidate = (signalMsg) => { } } - pc.addIceCandidate(candidate).catch(reportError); + pc.addIceCandidate(candidate).catch(window.reportError); }; ``` diff --git a/files/en-us/web/api/rtcpeerconnection/setconfiguration/index.md b/files/en-us/web/api/rtcpeerconnection/setconfiguration/index.md index b2624fa5f7715ec..197da3c68ec435a 100644 --- a/files/en-us/web/api/rtcpeerconnection/setconfiguration/index.md +++ b/files/en-us/web/api/rtcpeerconnection/setconfiguration/index.md @@ -74,7 +74,7 @@ myPeerConnection .then(() => { // send the offer to the other peer using the signaling server }) - .catch(reportError); + .catch(window.reportError); ``` First, a new object is created, `restartConfig`, specifying the new ICE server and its credentials. diff --git a/files/en-us/web/api/rtcpeerconnection/setlocaldescription/index.md b/files/en-us/web/api/rtcpeerconnection/setlocaldescription/index.md index 4d260c3f1d36b61..ff85fcaa746e2aa 100644 --- a/files/en-us/web/api/rtcpeerconnection/setlocaldescription/index.md +++ b/files/en-us/web/api/rtcpeerconnection/setlocaldescription/index.md @@ -121,7 +121,7 @@ async function handleNegotiationNeededEvent() { pc.setLocalDescription(offer); signalRemotePeer({ description: pc.localDescription }); } catch (err) { - reportError(err); + window.reportError(err); } } ``` diff --git a/files/en-us/web/api/web_workers_api/functions_and_classes_available_to_workers/index.md b/files/en-us/web/api/web_workers_api/functions_and_classes_available_to_workers/index.md index 6f0bda99a158e94..457bad5fe3f8d47 100644 --- a/files/en-us/web/api/web_workers_api/functions_and_classes_available_to_workers/index.md +++ b/files/en-us/web/api/web_workers_api/functions_and_classes_available_to_workers/index.md @@ -26,7 +26,7 @@ Some of the functions (a subset) that are common to all workers and to the main - {{domxref("WorkerGlobalScope.dump()", "dump()")}} {{non-standard_inline}} - {{domxref("WorkerGlobalScope/fetch", "fetch()")}} - {{domxref("queueMicrotask()")}} -- {{domxref("reportError()")}} +- {{domxref("WorkerGlobalScope.reportError()", "reportError()")}} - {{domxref("setInterval()")}} - {{domxref("setTimeout()")}} - {{domxref("structuredClone()")}} diff --git a/files/en-us/web/api/web_workers_api/index.md b/files/en-us/web/api/web_workers_api/index.md index 5c9b4339d1e6c4c..693a0b1ac1cffcf 100644 --- a/files/en-us/web/api/web_workers_api/index.md +++ b/files/en-us/web/api/web_workers_api/index.md @@ -50,7 +50,7 @@ Some of the functions (a subset) that are common to all workers and to the main - {{domxref("WorkerGlobalScope.dump()", "dump()")}} {{non-standard_inline}} - {{domxref("WorkerGlobalScope/fetch", "fetch()")}} - {{domxref("queueMicrotask()")}} -- {{domxref("reportError()")}} +- {{domxref("WorkerGlobalScope.reportError()", "reportError()")}} - {{domxref("setInterval()")}} - {{domxref("setTimeout()")}} - {{domxref("structuredClone()")}} diff --git a/files/en-us/web/api/webrtc_api/signaling_and_video_calling/index.md b/files/en-us/web/api/webrtc_api/signaling_and_video_calling/index.md index 725605b0b42b087..9b50a77548dc2cd 100644 --- a/files/en-us/web/api/webrtc_api/signaling_and_video_calling/index.md +++ b/files/en-us/web/api/webrtc_api/signaling_and_video_calling/index.md @@ -375,7 +375,7 @@ function handleNegotiationNeededEvent() { sdp: myPeerConnection.localDescription, }); }) - .catch(reportError); + .catch(window.reportError); } ``` @@ -397,7 +397,7 @@ We know the description is valid, and has been set, when the promise returned by - `sdp` - : The SDP string describing the offer. -If an error occurs, either in the initial `createOffer()` or in any of the fulfillment handlers that follow, an error is reported by invoking our `reportError()` function. +If an error occurs, either in the initial `createOffer()` or in any of the fulfillment handlers that follow, an error is reported by invoking our `window.reportError()` function. Once `setLocalDescription()`'s fulfillment handler has run, the ICE agent begins sending {{domxref("RTCPeerConnection.icecandidate_event", "icecandidate")}} events to the {{domxref("RTCPeerConnection")}}, one for each potential configuration it discovers. Our handler for the `icecandidate` event is responsible for transmitting the candidates to the other peer. @@ -462,7 +462,7 @@ Finally, the caller handles the answer message it received by creating a new {{d ```js function handleVideoAnswerMsg(msg) { const desc = new RTCSessionDescription(msg.sdp); - myPeerConnection.setRemoteDescription(desc).catch(reportError); + myPeerConnection.setRemoteDescription(desc).catch(window.reportError); } ``` @@ -506,7 +506,7 @@ The signaling server delivers each ICE candidate to the destination peer using w function handleNewICECandidateMsg(msg) { const candidate = new RTCIceCandidate(msg.candidate); - myPeerConnection.addIceCandidate(candidate).catch(reportError); + myPeerConnection.addIceCandidate(candidate).catch(window.reportError); } ``` diff --git a/files/en-us/web/api/window/index.md b/files/en-us/web/api/window/index.md index 3035129f6fbbf74..a7e055cae835a6f 100644 --- a/files/en-us/web/api/window/index.md +++ b/files/en-us/web/api/window/index.md @@ -221,7 +221,7 @@ _This interface inherits methods from the {{domxref("EventTarget")}} interface._ - : Returns a {{jsxref("Promise")}} that fulfills with an array of {{domxref("FontData")}} objects representing the font faces available locally. - {{domxref("queueMicrotask", "Window.queueMicrotask()")}} - : Queues a microtask to be executed at a safe time prior to control returning to the browser's event loop. -- {{domxref("reportError", "Window.reportError()")}} +- {{domxref("Window.reportError()")}} - : Reports an error in a script, emulating an unhandled exception. - {{domxref("Window.requestAnimationFrame()")}} - : Tells the browser that an animation is in progress, requesting that the browser schedule a repaint of the window for the next animation frame. diff --git a/files/en-us/web/api/window/reporterror/index.md b/files/en-us/web/api/window/reporterror/index.md index 04c061a17c6b11a..40523119c211dec 100644 --- a/files/en-us/web/api/window/reporterror/index.md +++ b/files/en-us/web/api/window/reporterror/index.md @@ -1,14 +1,14 @@ --- -title: reportError() global function +title: "Window: reportError() method" short-title: reportError() slug: Web/API/Window/reportError -page-type: web-api-global-function +page-type: web-api-instance-method browser-compat: api.reportError --- -{{APIRef("DOM")}} {{AvailableInWorkers}} +{{APIRef("DOM")}} -The **`reportError()`** global method may be used to report errors to the console or global event handlers, emulating an uncaught JavaScript exception. +The **`reportError()`** method of the {{DOMxRef("Window")}} interface may be used to report errors to the console or event handlers of global scopes, emulating an uncaught JavaScript exception. This feature is primarily intended for custom event-dispatching or callback-manipulating libraries. Libraries can use this feature to catch errors in callback code and re-throw them to the top level handler. @@ -41,24 +41,24 @@ None ({{jsxref("undefined")}}). Feature test for the method using: ```js -if (typeof self.reportError === "function") { +if (typeof window.reportError === "function") { // function is defined } ``` -The following code shows how you might create and report an error, and how it may be caught using either the global `onerror` handler or by adding a listener for the `error` event. +The following code shows how you might create and report an error, and how it may be caught using either the `onerror` event handler property or by adding a listener for the `error` event. Note that the handler assigned to `onerror` must return `true` to stop the event propagating further. ```js const newError = new Error("Some error message", "someFile.js", 11); -self.reportError(newError); +window.reportError(newError); window.onerror = (message, source, lineno, colno, error) => { console.error(`message: ${error.message}, lineno: ${lineno}`); return true; }; -self.addEventListener("error", (error) => { +window.addEventListener("error", (error) => { console.error(error.filename); }); @@ -77,6 +77,8 @@ self.addEventListener("error", (error) => { ## See also -- [`Window`](/en-US/docs/Web/API/Window) -- [`WorkerGlobalScope`](/en-US/docs/Web/API/WorkerGlobalScope) -- [error](/en-US/docs/Web/API/HTMLElement/error_event) event +- {{DOMxRef("Window")}} +- {{DOMxRef("WorkerGlobalScope.reportError()")}} +- {{DOMxRef("Window/error_event", "error")}} event +- {{DOMxRef("WorkerGlobalScope/error_event", "error")}} event +- {{DOMxRef("HTMLElement/error_event", "error")}} event diff --git a/files/en-us/web/api/workerglobalscope/index.md b/files/en-us/web/api/workerglobalscope/index.md index a7f60c0a0fba49f..9689bbd2f2211c0 100644 --- a/files/en-us/web/api/workerglobalscope/index.md +++ b/files/en-us/web/api/workerglobalscope/index.md @@ -74,7 +74,7 @@ _This interface inherits methods from the {{domxref("EventTarget")}} interface._ - : Schedules a function to execute in a given amount of time. - {{domxref("structuredClone()", "WorkerGlobalScope.structuredClone()")}} - : Creates a [deep clone](/en-US/docs/Glossary/Deep_copy) of a given value using the [structured clone algorithm](/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). -- {{domxref("reportError()", "WorkerGlobalScope.reportError()")}} +- {{domxref("WorkerGlobalScope.reportError()")}} - : Reports an error in a script, emulating an unhandled exception. ## Events diff --git a/files/en-us/web/api/workerglobalscope/reporterror/index.md b/files/en-us/web/api/workerglobalscope/reporterror/index.md new file mode 100644 index 000000000000000..d6bb11afd3d460f --- /dev/null +++ b/files/en-us/web/api/workerglobalscope/reporterror/index.md @@ -0,0 +1,84 @@ +--- +title: "WorkerGlobalScope: reportError() method" +short-title: reportError() +slug: Web/API/WorkerGlobalScope/reportError +page-type: web-api-instance-method +browser-compat: api.reportError +--- + +{{APIRef("Web Workers API")}}{{AvailableInWorkers("worker")}} + +The **`reportError()`** method of the {{DOMxRef("WorkerGlobalScope")}} interface may be used to report errors to the console or event handlers of global scopes, emulating an uncaught JavaScript exception. + +This feature is primarily intended for custom event-dispatching or callback-manipulating libraries. +Libraries can use this feature to catch errors in callback code and re-throw them to the top level handler. +This ensures that an exception in one callback will not prevent others from being handled, while at the same time ensuring that stack trace information is still readily available for debugging at the top level. + + + +## Syntax + +```js-nolint +reportError(throwable) +``` + +### Parameters + +- `throwable` + - : An error object such as a {{jsxref("TypeError")}}. + +### Return value + +None ({{jsxref("undefined")}}). + +### Exceptions + +- {{jsxref("TypeError")}} + - : The method is called without an error argument. + +## Examples + +Feature test for the method using: + +```js +if (typeof self.reportError === "function") { + // function is defined +} +``` + +The following code shows how you might create and report an error, and how it may be caught using either the `onerror` event handler property or by adding a listener for the `error` event. +Note that the handler assigned to `onerror` must return `true` to stop the event propagating further. + +```js +const newError = new Error("Some error message", "someFile.js", 11); +self.reportError(newError); + +self.onerror = (message, source, lineno, colno, error) => { + console.error(`message: ${error.message}, lineno: ${lineno}`); + return true; +}; + +self.addEventListener("error", (error) => { + console.error(error.filename); +}); + +// Output +// > "message:Some error message, lineno: 11" +// > "someFile.js" +``` + +## Specifications + +{{Specifications}} + +## Browser compatibility + +{{Compat}} + +## See also + +- {{DOMxRef("WorkerGlobalScope")}} +- {{DOMxRef("Window.reportError()")}} +- {{DOMxRef("Window/error_event", "error")}} event +- {{DOMxRef("WorkerGlobalScope/error_event", "error")}} event +- {{DOMxRef("HTMLElement/error_event", "error")}} event diff --git a/files/jsondata/GroupData.json b/files/jsondata/GroupData.json index 1bd627d2a20efb0..48211959cbdf45e 100644 --- a/files/jsondata/GroupData.json +++ b/files/jsondata/GroupData.json @@ -787,7 +787,7 @@ "Window", "WorkletGlobalScope" ], - "methods": ["reportError"], + "methods": [], "properties": [], "events": [ "Document: DOMContentLoaded", From f0e7d208e769a2c3dab1e7b722e6401d26693422 Mon Sep 17 00:00:00 2001 From: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:58:44 +0800 Subject: [PATCH 3/4] Update index.md --- files/en-us/web/api/workerglobalscope/reporterror/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/en-us/web/api/workerglobalscope/reporterror/index.md b/files/en-us/web/api/workerglobalscope/reporterror/index.md index d6bb11afd3d460f..6859340f440ffdc 100644 --- a/files/en-us/web/api/workerglobalscope/reporterror/index.md +++ b/files/en-us/web/api/workerglobalscope/reporterror/index.md @@ -14,8 +14,6 @@ This feature is primarily intended for custom event-dispatching or callback-mani Libraries can use this feature to catch errors in callback code and re-throw them to the top level handler. This ensures that an exception in one callback will not prevent others from being handled, while at the same time ensuring that stack trace information is still readily available for debugging at the top level. - - ## Syntax ```js-nolint From 57df204340c5fb098d379713a3fe94142095c594 Mon Sep 17 00:00:00 2001 From: skyclouds2001 <95597335+skyclouds2001@users.noreply.github.com> Date: Wed, 18 Sep 2024 14:59:24 +0800 Subject: [PATCH 4/4] Update index.md --- files/en-us/web/api/window/reporterror/index.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/files/en-us/web/api/window/reporterror/index.md b/files/en-us/web/api/window/reporterror/index.md index 40523119c211dec..b6e46763fc369eb 100644 --- a/files/en-us/web/api/window/reporterror/index.md +++ b/files/en-us/web/api/window/reporterror/index.md @@ -14,8 +14,6 @@ This feature is primarily intended for custom event-dispatching or callback-mani Libraries can use this feature to catch errors in callback code and re-throw them to the top level handler. This ensures that an exception in one callback will not prevent others from being handled, while at the same time ensuring that stack trace information is still readily available for debugging at the top level. - - ## Syntax ```js-nolint