遠程實時調試手機上的Web頁面


1. 安裝
    需要Node.js平台, 先安裝好后, 打開Node.js command prompt, 通過NPM來安裝 weinre

npm -g install weinre



2. 啟動
    安裝完成后, 我們接着啟動 weinre

weinre -httpPort 8081 -boundHost -all-

 

能打開這個地址就說明weinre啟動成功了


    可以配置 .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

 

點擊一下激活target



    終於可以調試了! 接下來隨便怎么玩都可以了, 大家應該都很熟練了吧...


 
 
 以上為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.手機訪問(注意是谷歌或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 方可。。。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM