-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new SharedWorker() should queue a task to fire an error when parse error occurs #5323
Comments
I was thinking this was done in part because there can be multiple |
Yes, Firefox will report parse/evaluation errors. (SharedWorkers' handling I believe lives here which has special cases for each of the 3 types of workers). And it seems appropriate for this to be in the spec. However, it looks like Blink doesn't report the error? I made a quick test case at https://worker-playground.glitch.me/shared-worker-top-level-error.html that does console.log() for Dedicated and Shared Workers on the same file, and Firefox reports both errors, but Chrome does not. (And Safari doesn't support SharedWorkers.) |
I think @elkurin wants to change that. I think the other thing we should clarify is what happens if you have multiple |
Yes, the spec should be changed. And in the case of multiple SharedWorker instances, it would seem to make sense that every I wonder if this should be handled by changing https://html.spec.whatwg.org/#runtime-script-errors-2 to treat shared workers similarly to dedicated workers? |
That would go even further and include errors beyond fetch/parse. Not entirely convinced that's desirable. (Also not sure it was a good idea for dedicated workers.) |
Notifying to all SharedWorker instance sounds reasonable. I thought current spec has already supported in that way but it seems not. I think we shouldn't change https://html.spec.whatwg.org/#runtime-script-errors-2 similarly to dedicated workers. All SharedWorker instances associated with the worker are guaranteed to be related to error events during fetching (fetch failure and parse error) because all of them attempt to fetch the script. On the other hand, runtime script errors are not necessarily related to the associated workers. |
This is true. Blink doesn't report parse errors nor evaluation errors. Only reports fetching failure errors. |
https://html.spec.whatwg.org/#runtime-script-errors-2 basically describes bubbling an error event from [WorkerGlobalScope, Worker, Worker's global scope] (unless handled). If the SharedWorker's global doesn't handle the error due to breakage, why wouldn't content want to be able to know that? A lot of recent discussion in the ServiceWorker WG relates to sites being paranoid about ServiceWorker and storage breakage, so providing a mechanism to detect unhandled errors seems useful, if duplicative. Coincidentally, Firefox also reports runtime errors. I created https://worker-playground.glitch.me/shared-worker-dynamic-error.html which logs both errors from |
In part it seems problematic because it's not robust. A shared worker might temporarily not have a document associated with it (although maybe it's event loop has to be frozen while that happens?). And it also doesn't seem particularly efficient to broadcast all errors. But I don't care too strongly. |
I took a deeper look at https://docs.google.com/document/d/1ot2GurRwSUlvAEB1_XlVPR9-7KT8lAmK1sAb8P11qZY/edit#heading=h.fo73cyj0hll and I'm not sure why it would be desirable to only do the #1 fix (throw on parse errors, step 12 of run a worker) versus #2 also (throw on errors running the script/top-level evaluation, step 13 of run a worker). Given the dynamic nature of JS and the precedent of ServiceWorker's Run Service Worker algorithm it seems weird to only return parse errors when many typos would equally manifest as runtime errors running the classic/module script. And I think this leads into Anne's point on robustness. The current spec would seem to dictate that if same-origin window A1 and A2 both create an equivalent SharedWorker with A1's request reaching the shared worker manager first, only A1 would receive any errors. And A1 might not actually remain alive long enough to process those errors. If we're not changing the runtime behavior to report all errors (which would admittedly have robustness issues), then it seems like we want Run a Worker to be more like Run a Service Worker, specifically persisting its "start status"/"startFailed" state and (hand-wavingly) allowing subsequent requests to join a pending request. This would be the basis for consistently returning errors whenever attempting to attach a new SharedWorker to the underlying worker. This would include both the fetch/parse step 12 and the run at step 23. A new spec decision is then what to do if there was a "run classic/module script" error that results in "startFailed" being true given that there's no Bug xlinks: https://bugzilla.mozilla.org/show_bug.cgi?id=1254125 is Firefox's bug on reporting all errors, and https://bugzilla.mozilla.org/show_bug.cgi?id=1619728 is the related bug that we close the SharedWorker binding down whenever we hear an error (oops!). |
It seems 3 discussions are on-going here.
As for the last issue, it is not only for error handling but the problem of shared worker construction algorithms. Currently, shared workers with same conditions which should point to the same global scope might be duplicated. This issue is actually out of scope in this spec issue title, so maybe we should rename the title or create another issue and move? |
I'm okay with not reporting all runtime errors, I intended to convey a de-scoping to just reporting those resulting from the top-level evaluation should be reported. Once this initial bootstrap is completed, the SharedWorker content code should be able to handle "error" events fired on its global. (It's still appropriate for devtools to relay all such errors, of course.) For typos I mainly mean mis-spelling an identifier name which results in ReferenceErrors. I made an example page at https://worker-playground.glitch.me/shared-worker-identifier-typo.html where Chrome doesn't report the error but Firefox obviously does (because we report everything). |
Thanks for the discussion. As I mentioned above, this thread is discussing the several issues at once, so let me focus on the issue 1 in the above comment. I think we reached at the consensus that it is natural to handle parse error similarly as fetch failure, so now I would like to move on to creating PR. |
This aligns the behavior of parse errors in a SharedWorker with fetch failures. See discussion in #5323, which has gone beyond that to also discuss other types of errors, but for now we have agreement on parse errors at least.
OK, I've merged #5347, and we're almost finished with the tests in web-platform-tests/wpt#22185. @elkurin, could you either:
|
This CL handles parse error events in modules shared workers. By this change, parse error events invoked by top-level scripts and statically imported scripts can be handled by AbstractWorker.onerror. The HTML spec defines script parsing should occur during the fetch step and invoke a parse error event at that point if needed. This CL obeys this behavior for module script workers, but not for classic script workers because of an implementation reason that classic script workers are supposed to parse the script during the evaluation step. Therefore, the timing to catch parse error events differs. In this CL, parse error handling is only implemented for module shared workers, not for classic. This is discussed in the html spec issue: whatwg/html#5323 The wpt to check this feature will be added from external github: web-platform-tests/wpt#22185 Bug: 1058259 Change-Id: I2397a7de8e2ae732fb0b29aea8d8703dd2a79a05 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2100058 Reviewed-by: Hiroki Nakagawa <[email protected]> Commit-Queue: Eriko Kurimoto <[email protected]> Cr-Commit-Position: refs/heads/master@{#753185}
According to the current spec, a shared worker doesn't fire an error event when parse error occurs while it does for fetch failure which fails in the same step as parse error. It would be nice to fire an error event for parse error as well so that developers can catch the error by AbstractWorker.onerror with the description of failure.
Fetch failure is caught here:
We get null as a result of fetching algorithm when fetch failure occurs but we get the result with |error to rethrow| when parse error occurs and it is treated as non-null. Therefore, I suggest to modify the spec by adding the condition to the error handling step like:
"If the algorithm asynchronously completes with null or script whose error to rethrow is not null, then: queue a task to fire an event named error at worker ..."
(As far as I know, FireFox has already implemented parse error handling as this.)
The similar change has done in worklets spec as well: w3c/css-houdini-drafts#509
The corresponding spec is here: https://drafts.css-houdini.org/worklets/#fetch-and-invoke-a-worklet-script
For more information if you need: https://docs.google.com/document/d/1ot2GurRwSUlvAEB1_XlVPR9-7KT8lAmK1sAb8P11qZY/edit#heading=h.fo73cyj0hll
The text was updated successfully, but these errors were encountered: