|Summary:||Worker.constructor throws an exception when the url param is an empty string|
|Component:||WebCore Misc.||Assignee:||Chris Dumez <cdumez>|
|Severity:||Normal||CC:||achristensen, bugs-noreply, cdumez, darin, ggaren, mcatanzaro, sam, webkit-bug-importer, youennf|
|Version:||WebKit Local Build|
Description firstname.lastname@example.org 2021-06-04 02:58:42 PDT
Steps to reproduce: (1) Open a tab and navigate to any URL; (2) Run the following code in the Console of Devtools: ``` new Worker("") ``` (3) Then this code would throw a SyntaxError exception. Actual results: This code would throw a SyntaxError exception: `SyntaxError: The string did not match the expected pattern.` Expected results: For EventSource.constructor, as https://html.spec.whatwg.org/multipage/server-sent-events.html#dom-eventsource says, when the URL param is an empty string, it should be parsed as a relative URL to the API's URL. In fact, Firefox works as the spec says, and Chrome has fixed this problem following the spec nowadays too. I think the URL script param of Worker.constructor should be parsed as a relative URL to the API's URL too. In my test, both Chrome and Firefox would not throw the SyntaxError exception and would parse it as the relative URL when evaluating this code.
Comment 2 Alex Christensen 2021-06-04 16:00:14 PDT
Comment on attachment 430625 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=430625&action=review > LayoutTests/fast/workers/worker-constructor-expected.txt:1 > +CONSOLE MESSAGE: SyntaxError: Unexpected token '<' I saw this in Chrome. In Firefox I see this: Loading Worker from “http://example.com/” was blocked because of a disallowed MIME type (“text/html”).
Comment 3 Chris Dumez 2021-06-04 16:07:25 PDT
(In reply to Alex Christensen from comment #2) > Comment on attachment 430625 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=430625&action=review > > > LayoutTests/fast/workers/worker-constructor-expected.txt:1 > > +CONSOLE MESSAGE: SyntaxError: Unexpected token '<' > > I saw this in Chrome. In Firefox I see this: > Loading Worker from “http://example.com/” was blocked because of a > disallowed MIME type (“text/html”). Either way, the browser attempts treats the input as a relative URL and ends up trying to load the test page URL in a Worker. Looks like Blink and WebKit just ignore the fact that the response is text/html and still try to process it as a worker script, while Firefox gives up after seeing the Content-Type.
Comment 5 EWS 2021-06-04 21:39:46 PDT
Committed r278520 (238519@main): <https://commits.webkit.org/238519@main> All reviewed patches have been landed. Closing bug and clearing flags on attachment 430633 [details].