New issue
Advanced search Search tips

Issue 907452 link

Starred by 2 users

Issue metadata

Status: Duplicate
Merged: issue 600074
Owner: ----
Closed: Nov 21
Cc:
Components:
EstimatedDays: ----
NextAction: ----
OS: Windows
Pri: 2
Type: Bug



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
 
Components: -Blink Blink>Storage
Its unclear to me if blob URL loading is designed to support query params in the spec or not.

Does this work in any other browser?  I checked edge and at least query param makes fetch() fail.
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"

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
Summary: blob URLs with query params do not load properly (was: WebWorker - Cannot Pass Parameters using Blob )
Cc: mek@chromium.org
Status: Untriaged (was: Unconfirmed)
Marijn, what do you think?
Mergedinto: 600074
Status: Duplicate (was: Untriaged)
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. 
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. 
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