简体   繁体   English

Chrome远程调试-跨域

[英]Chrome Remote Debugging - Cross Domain

I debug Chrome remotely by opening it with the --remote-debugging-port switch, as described here . 我远程调试铬通过与打开它--remote-debugging-port开关,如所描述这里

I have another page running on a different port (on my localhost as well) and issuing an HTTP request to: http://localhost:9222/json . 我在另一个端口(也在我的本地主机上)上运行另一个页面,并将HTTP请求发布到: http://localhost:9222/json This fails due to a cross-domain problem ("No Access-Control-Allow-Origin"), since the request is issued from a different port. 由于跨域问题(“无访问控制允许来源”),此操作失败,因为请求是从其他端口发出的。

Can I somehow change the Chrome remote debugger's localhost server headers to support cross-domain? 我可以以某种方式更改Chrome远程调试器的localhost服务器标头以支持跨域吗? I just need to find a way to call that http://localhost:9222/json from a different host... 我只需要找到一种从其他主机调用该http://localhost:9222/json的方法...

You should launch Chrome at “allow-file-access-from-files” mode to resolve this issue. 您应该以“允许文件访问文件”模式启动Chrome,以解决此问题。

More detailed information about allow-file-access-from-files mode please see here: How to launch html using Chrome at "--allow-file-access-from-files" mode? 有关允许文件访问文件模式的更多详细信息,请参见此处: 如何在“ --allow-file-access-from-files”模式下使用Chrome启动HTML?

The way I did it was by running Chrome with the switch --disable-web-security that overrides the enforcement of the same origin policy. 我这样做的方法是通过使用--disable-web-security开关运行Chrome,该开关会覆盖执行相同的原始策略。 This solution obviously has its drawbacks (eg a notification bar saying that stability and security will suffer) but for my needs it seems good enough at the moment. 该解决方案显然有其缺点(例如,通知栏说稳定性和安全性将受到损害),但就我的需求而言,目前看来它已经足够好了。

I don't think this is possible. 我认为这是不可能的。 I am need of this feature too. 我也需要此功能。 I have tried to launch chrome (which I want to debug) using the flags "--disable-web-security" and "--allow-file-access-from-files". 我尝试使用标志“ --disable-web-security”和“ --allow-file-access-from-files”启动chrome(我想调试)。 When I try to access the page "localhost:9222/json" from another port say "localhost:8000" it throws error http://pastebin.com/JHYy8uLk 当我尝试从另一个端口访问页面“ localhost:9222 / json”时说“ localhost:8000”,它引发错误http://pastebin.com/JHYy8uLk

This can however be done using a middle-man(server) which entertains get requests. 但是,这可以使用招待get请求的中间人(服务器)来完成。 The page localhost:8000 can send "get" request to this middle-man, which will fetch json data from localhost:9222/json(No violation of same origin policy), and return this data to localhost:8000. 页面localhost:8000可以向此中间人发送“获取”请求,该中间人将从localhost:9222 / json获取json数据(不违反相同的原始策略),然后将此数据返回到localhost:8000。

Since my localhost:8000 was running on a Django server, I can use the server itself to fetch data from localhost:9222/json(ie the django controller). 由于我的localhost:8000运行在Django服务器上,因此我可以使用服务器本身从localhost:9222 / json(即django控制器)中获取数据。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM