標籤:
1. 安裝
需要Node.js平台, 先安裝好後, 開啟Node.js command prompt, 通過NPM來安裝 weinre
2. 啟動
安裝完成後, 我們接著啟動 weinre
|
| weinre -httpPort 8081 -boundHost -all- |
可以配置 .weinre/server.properties 讓啟動 weinre 變得更方便, 具體方法請參考官網, 配置好後, 以後想啟動 weinre, 直接運行weinre命令即可, 無需每次都追加那些參數了.
3. Instrumenting your web page to act as a debug target
將如下指令碼追加到你將要調試的頁面上
<script src="http://你的IP地址:8081/target/target-script-min.js#anonymous"></script>
4. 折騰這麼久, 快點讓我遠端偵錯吧
在手機上開啟要調試頁面的地址
在 weinre Access Points 中開始遠端偵錯
|
| 點擊anonymous Access Points |
終於可以調試了! 接下來隨便怎麼玩都可以了, 大家應該都很熟練了吧...
以上為http://www.douban.com/note/289846168/ 測試過程中發現的問題及解決:1 .ipconfig看ip:10.62.0.173
cmd下輸入:weinre --httpPort 8080 --boundHost 10.62.0.173
手機訪問:http://10.62.0.173:8080/www/2.html
電腦也訪問:http://10.62.0.173:8080/www/2.html
[注意:若是使用無線則需要是同一個熱點。。手機和電腦都訪問同一個網址。。](www是我建立的目錄:C:\Users\lenovo\AppData\Roaming\npm\node_modules\weinre\web\www)
這隻是手機訪問電腦ip的網址而已。。並沒有將手機和電腦串連到一起調試,一開始以為這就行了,後來才發現是錯的。
2. 若:cmd下輸入:weinre --httpPort 8080 --boundHost -all- [8080為連接埠號碼。。]
【注意:若為weinre --httpPort 8080 --boundHost all,則報錯weinre: unable to resolve boundHost address:all】
則電腦直接存取 http://127.0.0.1:8080/client/
訪問檔案:http://127.0.0.1:8080/www/2.html
(本地路徑:C:\Users\lenovo\AppData\Roaming\npm\node_modules\weinre\web\www)
3.測試是否成功。。
訪問:http://localhost:8080/client/#anonymous
然後頂部有一個:Targets: 若後面為none之類的資訊代表沒有完成。。。 a.手機訪問(注意是Google或safari瀏覽器才可以):10.62.0.172:8081/www/1.html (我的ip10.62.0.172:8081) b.電腦訪問:http://localhost:8080/client/#anonymous。。出現類似 10.200.108.11 [channel: t-5 id: anonymous] - http://10.62.0.173:8081/www/1.html 代表已經手機和電腦連上去了,主要:上面的文字顏色是藍色,還需要滑鼠點擊一下,使其變成綠色,才代表可以最終調試手機上的頁面。 c.變成綠色後,則點擊elements選項卡,就會出現當前頁面的html結構,進行調試。。console中輸入alert(‘123‘),手機上馬上出現結果。。 1.html內容:
<!doctype html>
<html>
<head>
<script src="http://10.62.0.173:8080/target/target-script-min.js#anonymous"></script>
<script src="../target/target-script-min.js" /></script>
</head>
<body>
<style>
body{background:#ff7300}
h3{font-size:50px;padding:100px;}
</style>
<h3>測試內容。。。。。</h3>
</body>
</html>
補:有時會失敗,即target下為none。cmd下重新輸入命令,然後
訪問http://localhost:8080/,繼續:debug client user interface: http://localhost:8080/client/#anonymous
。。最終10.200.108.11 [channel: t-7 id: anonymous] - http://10.62.0.173:8080/www/1.html 方可。。。
遠程Just-in-Time 偵錯手機上的Web頁面