如何强制 Chrome/Firefox/Opera 从本地主机发出跨域请求?
嘿,
所以我遇到了这个问题:我正在尝试在本地主机上开发 HTML 文件,而我安装的所有浏览器都阻止我发送跨域请求。
我想做的是将我用Python(使用Mechanize、pyquery和lxml)编写的脚本转换为Javascript,原因并不重要(我认为在Javascript中模拟某些东西会更容易)。
来自本地文件的跨域请求过去可以工作,并且仍在最新的 Safari(稳定)上工作,但我无法在这台计算机上安装 Safari(它是一个 Linux 机器)。
编辑
我发现了 Firefox 的升级权限,例如:
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
// among others
问题是,我还尝试访问 iFrame 中加载的内容...正如我所说,我正在尝试模拟浏览器会话,就像我使用像 Mechanize 这样的库一样,但是来自 Javascript。我的脚本在 Safari 中仍然有效。
那么如何强制 Chrome / Firefox / Opera 绕过本地存储文件的所有安全限制?
我对浏览器命令行选项感兴趣,我什至会考虑给浏览器打补丁(我'我是用户,而不是试图将其分发给其他任何人)。
谢谢,
Hy,
So I've got this problem: I'm trying to develop an HTML file on my localhost, and all the browsers I have installed are preventing me to send cross-domain requests.
What I'm trying to do is to convert a script I wrote in Python (with Mechanize, pyquery and lxml) to Javascript, the reasons don't really matter (I thought in Javascript it would be easier to simulate something).
Cross-domain requests from local files used to work, and are still working on the latest Safari (stable), but I can't install Safari on this machine (it's a Linux box).
EDIT
I discovered the escalated privileges of Firefox, e.g.:
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
// among others
Problem is, I'm also trying to access the content loaded in an iFrame ... as I said, I'm trying to simulate a browser session, like I would with a library like Mechanize, but from Javascript. My script still works in Safari.
So how to force Chrome / Firefox / Opera to bypass all security restrictions from locally stored files?
I'm interested in a browser command-line option, I would even consider a patch to the browser (I'm the user, not trying to distribute this to anyone else).
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我不确定您是否可以控制 IFrame 中的内容,但既然您谈论的是本地文件,我想您可以控制。 这篇关于 Ajaxian 的文章应该涵盖您的用例。
由于您的目标是 A 级浏览器(ei 不是 IE),您可以使用 html5 window.postMessage 而不是 IFrame。
干杯,乔恩。
我没有 Python Mechanize lib 的工作知识。
I'm unsure whether or not you have control of the content in the IFrames but since you are speaking of local files I guess you do. This article on Ajaxian should cover your use case.
Since you are targeting grade A browsers (e.i. not IE) you could use html5 window.postMessage instead of IFrames.
Cheers, Jon.
I have no working knowledge of Python Mechanize lib.
为什么不启动一个简单的 http 服务器来解决您的问题呢?
此 python 代码将启动一个简单的 http 服务器,侦听端口 8000 或第一个参数,并从此脚本处理文件夹中的所有文件。
Why don't you start a simple http server instead to solve your problem?
This python code will start a simple http server listening on port 8000 or the first argument and handles all files in the folder from this script.
我不确定当页面位于本地主机上时这是否有效,但可能值得一试: http ://www.asual.com/jquery/address/
那个 jQuery 插件可以让你从任何域发出跨域请求...也许它可以与本地主机一起工作?不过还没有测试过。
I'm not sure if this works when the page is on localhost, but it might be worth a try: http://www.asual.com/jquery/address/
That jQuery plugin lets you make cross-domain requests from any domain... Perhaps it might work with localhost? Haven't tested it though.