Webworker served from the local filesystem not working - javascript

I am trying to make the web worker example from MDN to work when it is not served from a server but opened directly open from my local filesystem (via a via file:// URL)
The example works fine when served from Apache at http://localhost/1/simple-web-worker-gh-pages/index.html
but it doesn't when it is read locally at file:///var/www/html/1/simple-web-worker-gh-pages/index.html
The developer console shows that messages are posted but there is no answer from the worker. (I tried both Firefox and Chromium.)
How can I make it to work ?
(There's a similar question failed to load script - Webworker (PDF.JS) , but my problem is different, as I don't see a "Failed to load script" error.)

Avoid developing using file:/// - you'll waste time debugging, as not everything is supposed to work there.
In case of Worker() in Firefox, this was supported a year ago, but was apparently disabled in Firefox 68.
See Firefox 68: local files now treated as cross-origin; is there a way to override? - if you set privacy.file_unique_origin to false in about:config, the example should work.

Related

Chrome SecurityError loading jQuery Mobile page from local file system

I get the following error in Chrome when loading a trivially simple html file with a jQuery Mobile reference. The error is not present with just the jQuery reference.
Uncaught SecurityError: Failed to execute 'replaceState' on 'History':
A history state object with URL 'http://stacksnippets.net/js' cannot
be created in a document with origin 'null'.
<html>
<head>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
</head>
<body></body>
</html>
You can also "Run code snippet" and see the error in the console.
This error did not happen before today. I have not changed my code or method of loading the html file in the browser. It used to work perfectly - I use the same code for all my PhoneGap apps.
Does anyone know if there was a Chrome security update that causes this SecurityError or whether I'm missing something? How would you go about debugging this? Thank you.
UPDATE
This discussion I think points out what is going on, which I suspected, since the error does not appear when running with a web server: Origin null is not allowed by Access-Control-Allow-Origin .
But I am still wondering why this changed in the past day, whether Chrome has had a change in their security policy, or why it was working before, and whether any of my PhoneGap apps will be affected.
This error is same as the origin is null error. This error occurs because of the security feature of Chrome.
A simple solution to test the application is to bypass this security on chrome.
Steps:
create a chrome browser shortcut on desktop.
Close all the instances of chrome on your machine.
Right click on the desktop shortcut of chrome and click on Properties.
in Target field, append " -allow-file-access-from-files" at the end.
Save and close properties.
Open chrome via this shortcut only.
Hurry, the error has gone. App works perfectly.
NOTE: This is just a work-around I use to test my cordova apps on desktop browser for UI testing.
Temporary solution: I've commented out all history.replaceState calls in jquery mobile, didn't need to manipulate browser history in my app anyways.
I wonder if it's chrome security bug or model and future behavior.
On a Mac I was able to fix this by running a webserver instead of loading it from a "file://" url:
http://lifehacker.com/start-a-simple-web-server-from-any-directory-on-your-ma-496425450?utm_expid=66866090-49.VYy4WCNHSyuP6EmjnM93MQ.0&utm_referrer=https%3A%2F%2Fwww.google.com%2F
python -m SimpleHTTPServer 8000
In the directory should make it available from Chrome via 0.0.0.0
I don't seem to have the same problem, not on the stable version of Chrome (45) or the Dev version (47).
However, I have personally seen issues with the CORS header, too. If you can cause the problem to happen reliably, I suggest filing a bug at crbug.com and a Chrome developer will have a look at it.

Web worker won't start in IE unless the cache is cleared

I'm having a really weird bug in my HTML5 script. I wrote a sharepoint app completely in OData which uses a few HTML 5 webworker to do the number crunching in the background. This works perfect on all major browsers (FF, IE10+ Chrome, ...). However, when I perform a refresh or browse to the page again. The script still works as intended on FF and Chrome, but hangs on IE.
In my network view I see a request for the Worker.js file, but with a 304 NOT MODIFIED response. IE then just hangs there on that request with a status of (Pending). This issue only gets resolved when I clear my browser cache.
I correctly close all my threads with self.close().
Any idea what the issue could be? I'm not sure if it's a code issue, a browser issue or a server side issue but I can replicate the bug on Sharepoint online as well as on a local server. The whole project is JS only, so I can't modify headers as a workaround either.
UPDATE: I ran exactly the same code outside of a sharepoint environment, and it worked perfectly. Issue is Sharepoint related.
using a time based querystring parameter prevents caching showing http status 200 on each refresh. tested on latest chrome, ie, ff;
var opus = new Worker("worker.js?q=" + new Date().getTime().toString() );
to be honest this a long shot as i do not have sharepoint right now
SharePoint sends the header:
Content-Disposition: attachment; filename="xyz.js"
X-Download-Options: noopen
and the IE Web Worker Implantation then does not run this web worker. (Tested in IE11) In the IE Network Monitor the request still on pending, even the Response text is visible.
I know so fare two workarounds:
Place the web worker js in the layouts folder (needs a Farm Solution, with the downside of this)
Set the Browser File Handling for the Web application to Permissive (maybe your security is not amused)

mozIndexedDB.open() from a local file (ie. via file:// protocol)

In FF4 (I'm using MacOS), when calling mozIndexedDB.open() through a local file, an exception is being thrown (IDBDatabaseException.UNKNOWN_ERR)...
The operation failed for reasons unrelated to the database itself and not covered by any other error code." code: "1
It obviously works fine in a normal http/https scenario (ie. the file is being served from a web server).
Is there any workaround or config flag that I can set in FF to be able to utilize indexed DB from a local file?
Thanks in advance...
This is a known issue in Firefox. As of today, there is no solution. Please follow https://bugzilla.mozilla.org/show_bug.cgi?id=643318 for updates on this problem.
And this bug seems to have been fixed with the latest Firefox nightly.

Same Javascript code but not same act

//Edit
Hello.
I have made a website and uploaded to the host. So, the codes what are in my localhost and in the website host are same. Everything works except one JavaScript(jQuery) action(A dropdown menu). On my localhost it works perfect, on the website host, it drops and rises again and than doesn't drop again.
site : http://www.hastahakki.com/index.php?page=anasayfa
The problem on the big buttons like "Doğru Hastane Seçimi" , "Hasta Şikayetleri"
How do I do?
It's rare for pure client code to work differently in a hosted environment provided it is uploaded properly and the same browser is used.
First I would check it's not a cache issue by clearing my browser cache.
Then I would view it in a browser with modern developer tools, which is most browsers with the latest version (Firefox requires the excellent Firebug plugin). In Chrome for instance, looking at the Network output will show you if any resources are failing to load, and the Scripts view will show you any local JavaScript errors that might be triggered by the hosted version.

Why do Chrome & Firefox slowly render my home page using MathJax?

This is my experimental site using MathJax.
I browse it using Chrome, Firefox, and IE.
I notice that IE renders slowly. But Chrome and Firefox do more slowly. :-)
Is there any secret tip to speed up the rendering?
Edit 1
I am still uploading the MathJax using FileZilla now to the remote server.
It needs much time to complete.
Even I use my development machine as a server with MathJax libraries installed, the result is the same as what I did above in remote server.
Your site is returning 404 requests for these files:
http://www.begolu.com/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_Size4-Regular.otf
http://www.begolu.com/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_Main-Regular.otf-
http://www.begolu.com/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_Math-Italic.otf
http://www.begolu.com/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_Size1-Regular.otf
http://www.begolu.com/MathJax/fonts/HTML-CSS/TeX/otf/MathJax_Main-Bold.otf
Look at the net tab with Firebug

Categories

Resources