显示 Javascript“同源策略”违规行为
我正在开发一个运行简单 HTTP 服务器和 WebView 的移动应用程序。 WebView 显示一个外部网站,该网站应通过 javascript (GET) 访问服务器。不幸的是,这不起作用,我认为这是由于同源策略所致,但控制台没有显示任何错误。之前我遇到过类似的错误,需要我在服务器端定义“Access-Control-Allow-Origin: *”。这个错误已经花了一段时间才能找到,因为没有错误消息(Firebug“Net”选项卡显示已完成的 GET 请求,但“响应”数据为空)。现在,我假设外部脚本中存在同源策略违规,但由于缺少错误消息,因此很难判断。我看到的唯一“提示”是在 Firebug“网络”选项卡中,显示“永远不会完成”的连接。我检查了发送到本地主机的包,但甚至没有连接尝试 =>因此我认为浏览器正在阻止它。
如何在 Firefox(ext:Firebug、Webdeveloper)中显示 Javascript“同源策略”违规错误?
I'm developing a mobile app which runs a simple HTTP server and a WebView. The WebView displays an external website which should access the server via javascript (GET). Unfortunately this doesn't work and I assume it's due to the same origin policy but the console doesn't show any errors. I had a similar error before which required me to define "Access-Control-Allow-Origin: *" on the server side. This error already took a while to find because there were no error messages (Firebug "Net" tab showed a completed GET request with empty "response" data). Now I assume a same origin policy violation in the external script, but it's hard to tell because of the missing error messages. The only "hint" I see is in Firebug "Net" tab, showing a connection which "never completes". I checked the packages sent to localhost but there wasn't even a connection attempt => thus I assume the browser is holding it back.
How do I display Javascript "same origin policy" violation errors in Firefox (ext: Firebug, Webdeveloper)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Firefox(3.6.20 和 Chrome)在 XMLHttpRequest 跨域违规时引发错误。这些错误可以通过
try{...} catch(ignore){}
块消除。如果您知道请求的实际路径,您可以在 Firebug 的“Net”选项卡中检查,所有请求(甚至是被“同源策略”拒绝的请求)都显示在“All”部分中,并且在“XHR”部分中显示被“同源政策”拒绝的则不然。Firefox(3.6.20 and Chrome) throws an error on XMLHttpRequest cross domain violations. These errors can being silenced by
try{...} catch(ignore){}
blocks. If you know the actual path of the request you can check in the Firebug's "Net" tab, all the requests(even those denied by "same origin policy") show in the "All" section, and in the "XHR" section those denied by "same origin policy" don't.