Javascript not resolving worker path relative to current script

Actually, it should be relative to the embedded document path

For example,

I have

pathDoc\docA.html
js\b.js
js\worker\c.js

then code should be

var worker = new Worker('..\js\worker\c.js')

From http://www.w3.org/TR/workers/:

When the Worker(scriptURL) constructor is invoked, the user agent must run the following steps:

  1. Resolve the scriptURL argument relative to the entry script's base URL, when the method is invoked.

Note, you can still get the script url within the worker using the self.location and just prepend it to the paths to make them relative from the worker script rather than html base url.

const workerUrl = location + '';
const basePath = workerUrl.replace(/\/[^/]+$/, '/');

self.importScripts(basePath + '/fooWorker.js');

Btw, if you include your worker via blob, you can still pass meta info like it's url via # hash params.