Issue metadata
Sign in to add a comment
|
blob URLs with query params do not load properly
Reported by
w...@randybuchholz.com,
Nov 21
|
||||||||||||||||||||||||
Issue description
UserAgent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.140 Safari/537.36 Edge/17.17134
Steps to reproduce the problem:
1. Attempt to create a WebWorker from a Blob, passing parameters.
2. Receive failed to load error
3.
What is the expected behavior?
A WebWorker is created.
What went wrong?
I create "WebWorker Classes" using the pattern below, but using URL's not blobs. The query parameters become my constructor parameters. When creating from a `file.js` it works, but when using a blob, it fails.
```
class TestWorkerClass{
constructor(){
const blobVar = new Blob(["
const params = self.location.search.slice(1);
class WorkerClass{
constructor(params){
// …
}
}
"] , { type: "text/javascript" });
const params = new URLSearchParams();
params.append("constructorParam1", "paramValue");
const worker = new Worker(`${blobVar}?${params}`, { type:"module", name:"TestWorker" });
}
}
```
`new Worker(`/file.js?${params}`, { type:"module", name:"TestWorker" });` succeeds.
It seems you can't use query parameters with blob sources.
Did this work before? N/A
Chrome version: 64.0.3282.140 Channel: dev
OS Version: 10.0
Flash Version:
It would be nice if the dev tools showed the name of the worker (if provided) in the tree, and not #1
,
Nov 21
You're using a string, not a blob, in Worker constructor.
And a blob doesn't serialize to its contents.
A `${blob}` serializes to "[object Blob]"
The final value is "[object Blob]?constructorParam1=paramValue"
,
Nov 21
The initial code example may be wrong here, but there is an issue where query params make loading a blob URL fail. You can see it if you run this in the console: var b = new Blob(['foo']) var u = URL.createObjectURL(b); var q = u + "?q=bar"; await fetch(u) await fetch(q) Anne suggests that this should work according to the spec per step 4 here: https://url.spec.whatwg.org/#concept-url-parser
,
Nov 21
,
Nov 21
Marijn, what do you think?
,
Nov 21
As per 600074 this behavior is intentional. But now looking at the algorithms in URL and fetch again, I'm not sure where that is specified. Ah, the URL spec side changes never landed; I somehow forgot to follow up on https://github.com/whatwg/url/pull/371.
,
Nov 21
I left out a line in my example, sorry.
after
const blobVar = new Blob(["...
add
const blobConstructor = self.URL.createObjectURL(blobVar);
then
const worker = new Worker(`${blobConstructor }?${params}`,
{ type:"module", name:"TestWorker" });
btw- When I'm in workers, I get duplicate line of console output. Is this a known issue? Or should I create one? I'm using Visual Studio, and only get single lines there, but when I look in chrome, I'll see dups. Sometimes it shows the source as a .js that isn't even in the execution path.
,
Nov 21
Oh, and if you do want to pass extra data with a blob URL, you can use the URL fragment for that, i.e. appending #param=value should work just fine. |
|||||||||||||||||||||||||
►
Sign in to add a comment |
|||||||||||||||||||||||||
Comment 1 by wanderview@chromium.org
, Nov 21