遠程Just-in-Time 偵錯手機上的Web頁面

來源:互聯網
上載者:User

標籤:

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.手機訪問(注意是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頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.