Failed to create Web Worker from local file in Chrome

Asked

Viewed 40 times

1

When trying to create a worker

var worker = new Worker('teste.js');

I receive the following message:

Uncaught Securityerror: Failed to Construct 'Worker': Script at 'file://C:/..... /js/teste.js' cannot be accessed from origin 'null'.

Agree with that answer in Soen, link, cannot load the local file. Is there any alternative way to run this?

Note: I use Google Chrome and Firefox

  • A comment on the answer there is saying that Firefox has no problem loading local files as long as its script is also local. Tried that?

  • It seems that in firefox runs even, but the problem is in Chorme, I have to make wheels in both s:

  • But this isn’t just for tests?

  • Yes but I intend to implement, but if it does not work in the main browsers becomes complicated

  • When you are hosted on a server it will work. It only happens locally. You can develop in Firefox or Safari without worries.

  • I was testing in Firefox, it error when a new Worker, returns following message, SecurityError: The operation is insecure.

  • I published a reply summarizing the solution to the general problem with a link to an example running in Firefox. Feel free to open up a new question for your specific case, as we are already heading in another direction here.

Show 2 more comments

1 answer

0

Currently, there is a disagreement between the browsers between what is considered a violation of the same origin policy for the Workers. Chrome and Opera don’t allow local addresses even running from a local script, which in my humble opinion is silly.

In the meantime, the Firefox supports running local Web Workers as long as the page is also running locally. This can be checked by running that example. Note that all paths are local.

If you have any problems even by following these steps, post a new question specific to your case with problematic code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.