Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sandbox prevents creating web worker #1010

Closed
nametoolong opened this issue Jul 8, 2017 · 4 comments
Closed

Sandbox prevents creating web worker #1010

nametoolong opened this issue Jul 8, 2017 · 4 comments

Comments

@nametoolong
Copy link

nametoolong commented Jul 8, 2017

new Worker("worker.js") merely fails: Uncaught DOMException: Failed to construct 'Worker': Script at 'http://127.0.0.1:43110/[site address]/worker.js' cannot be accessed from origin 'null'.
No idea about whether disallowing web workers should be a bug or a feature.

@HelloZeroNet
Copy link
Owner

HelloZeroNet commented Jul 8, 2017

Probably more like a feature of iframe sandboxing, but as a workaround it works this way:

function createWebworker() {
	// via http://www.html5rocks.com/en/tutorials/workers/basics/#toc-inlineworkers
	var blob = new Blob([
	    "onmessage = function(e) { postMessage('msg from worker'); }"]);

	var blobURL = window.URL.createObjectURL(blob);
	console.log(blobURL)

	var worker = new Worker(blobURL);
	worker.onmessage = function(e) {
		document.getElementById('webworker_result').textContent = event.data;
	};
	worker.postMessage("hello");
}

@AnthyG
Copy link

AnthyG commented Jul 9, 2017

I know, this is closed, but don't service workers need https anyways?!

PS.: This can be achieved through visiting zeronet via localhost instead of 127.0.0.1 (at least as far as I remember (at least in chrome)).

@HelloZeroNet
Copy link
Owner

web worker is not same as service worker.
Web worker: Script runs in separate thread, but it's closed when you leave the site.
Service worker: Keep running when you close the site

@AnthyG
Copy link

AnthyG commented Jul 9, 2017

@HelloZeroNet Ah wow, I did so much research on workers, but till now, I didn't quite understand the differences 😅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants