PhoneGap Weinre无法找到目标。

3

我尝试启用weinre进行调试,但问题是weinre找不到目标。

以下是我的操作步骤:

  1. 通过nodejs命令安装weinre:npm install weinre -g

  2. 通过USB电缆连接我的安卓设备(华为智能手机)并在手机上启用调试模式。

  3. 启动weinre,命令为:weinre --boundHost 192.168.2.1

index.html看起来像这样:

<!doctype html>
 <html>
  <head>
   <title>tittle</title>

    <!-- Weinre testing for remote debug with physical device -->
     <script src="http://192.168.2.1:8080/target/target-script-min.js#anonymous"></script>  

    <script>window.location='./main.html';</script>
   <body>
   </body>
 </html>

在config.xml文件中,我添加了以下内容:
 <access origin="http://192.168.2.1:8080/*" />

最终,在主页面main.html(即真正的起始页面)中我添加了以下内容:
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
  • 然后我将应用所需的所有文件压缩并上传到PhoneGap Build。在PhoneGap Build完成后,我使用移动设备扫描条形码。现在设备开始下载应用程序。

我在设备上启动应用,并访问该网站。

http://192.168.2.1:8080/client/#anonymous

=> 应用程序启动得如愿,但 weinre-server 网站显示 "目标:无"

我是否遗漏了什么?我在 Firefox 和 Chrome 上尝试了这个过程。我非常确定移动设备不使用与我的桌面电脑相同的本地主机。

weinre 服务器属性为:

enter image description here


你有解决方案吗? - HardikT
2个回答

0

我遇到了同样的问题,因为在导入脚本时我使用了“localhost:8080/target/target-script-min.js#anonymous”而不是真实IP。当我使用真实IP时,目标被找到了。


当我发布这个问题时,很抱歉我无法帮助你。但在我的情况下,它并没有起作用...即使使用你提到的192.168.2.1而不是localhost:8080。 - Phil LA
当我尝试调试iOS Chrome并且无法找到目标(未连接)时,这对我很有用。我使用了192.168.1.102:8080而不是localhost:8080。IP地址:192.168.1.102是我的Mac的网络地址,可以在“系统偏好设置”->“网络”中找到。 - nicholaswmin

0

正确的白名单配置是<content src="http://192.168.2.1:8080/*" />

如果您有Content-Security-Policy元标记,您需要设置default-src *或至少添加http://*,如this phonegap framework doc所述。 <meta http-equiv="Content-Security-Policy" content="default-src * ; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *; media-src *; img-src * 'self' data: file: cdvfile: http: https:; frame-src http: https: gap: cdvfile:; connect-src *">

<meta http-equiv="Content-Security-Policy" content="default-src 'self' http://*; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *; media-src *; img-src * 'self' data: file: cdvfile: http: https:; frame-src http: https: gap: cdvfile:; connect-src *">

<meta http-equiv="Content-Security-Policy" content="default-src 'self' http://*; script-src 'self' 'unsafe-inline' 'unsafe-eval' *; style-src 'self' 'unsafe-inline' *; media-src *; img-src * 'self' data: file: cdvfile: http: https:; frame-src http: https: gap: cdvfile:; connect-src *">


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接