Safari iOS not loading Javascript file?

前端 未结 2 1811
被撕碎了的回忆
被撕碎了的回忆 2020-12-20 17:51

I have just upgraded my iOS because of the recent security bug, and I find that my website is no longer loading properly on my phone!

I\'ve boiled the problem down t

相关标签:
2条回答
  • 2020-12-20 18:15

    I had exactly same issue when implementing web server functionality for my Arduino project. My web server implementation worked fine with desktop browsers and with Chrome in iOS (9.3.5). I had problems both with Firefox (5.1 (1)) and Safari in iOS. My web pages use scripts including jQuery. Scripts are used for transferring data from Arduino with AJAX/JSON.

    The problem was in the examples I used as a basis for my implementation. In those examples, web server's reply to browser's HTTP GET request in OK case doesn't contain anything else than the actual document requested. In that case web browser thinks that the web server is using HTTP/0.9. In addition, Content-Type is missing. Most of the browsers can "guess" what is the Content-Type of the reply although it is not included.

    In my case, Safari reported two errors

    1. Blocked script execution in http://myip because the document's frame is sandboxed and the 'allow-scripts' permission is not set.
    2. Sandboxing http://myip/image.jpg' because it is using HTTP/0.9.

    The first error causes browser to refuse loading my javascript and also jquery.js. Of course after that AJAX won't work. Firefox in desktop also nagged about not well-formed JSON replies but still worked fine.

    I simply changed the implementation so that HTTP replies will always include HTTP version, status code and Content-Type before the actual data. For example, when browser sends request GET / HTTP/1.1, the server doesn't just send the default web page but includes

    HTTP/1.1 200 OK
    Content-Type: text/html
    

    After that all errors disappeared. It seems new versions of Safari don't like to receive HTTP/0.9 and will sandbox what it gets back.

    0 讨论(0)
  • 2020-12-20 18:25

    Had the same issue (iOS 9.3.3 Safair/Chrome and on OSX with Safari 9.1.2).

    The reason was that we used a javascript library to try to load retina versions of all our images. Somehow the request sent using HTTP/0.9 and not HTTP/1.1 which made Safari automatically sandbox the whole page on all following requests (the error message said something like "automatically sandboxed ... because of HTTP/0.9"). The security changelog of iOS 9.3.3 (https://support.apple.com/en-us/HT206902) mentions something related under CVE-2016-4651.

    Make sure your web server supports HTTP/1.1 and that you request the page using HTTP/1.1

    0 讨论(0)
提交回复
热议问题