1

I have the following code, trying to test out WebWorkers. I have an index.html file that looks like this:

<html> <head></head> <body> <script type='text/javascript'> var worker = new Worker('./myworker.js'); console.log('after creation'); worker.addEventListener('message', function(msg){ console.log(msg); }); worker.postMessage(); </script> </body> </html> 

The contents of myworker.js (which resides in the same directory as index.html) is:

this.onmessage = function(){ postMessage('got the msg, thanks'); }; 

When I load index.html (in Chrome 14), the 'after creation' console.log never happens. Nor anything else. Console.logs happen before the new Worker() creation, but nothing after seems to happen.

2 Answers 2

1

Well butter my biscuit, apparently WebWorkers do not work when loaded locally (e.g. from file://).

source: http://www.html5rocks.com/en/tutorials/workers/basics/ (bottom of content)

Sign up to request clarification or add additional context in comments.

1 Comment

To quote - """ Due to Google Chrome's security restrictions, workers will not run locally (e.g. from file://) in the latest versions of the browser. Instead, they fail silently! To run your app from the file:// scheme, run Chrome with the --allow-file-access-from-files flag set. NOTE: It is not recommended to run your primary browser with this flag set. It should only be used for testing purposes and not regular browsing. Other browsers do not impose the same restriction. """
0

If you are testing app in chrome you should start the chrome with --allow-file-access-from-files or test app using Local server

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.