2012-01-04 68 views
5

在Kindle Fire上運行我的網站時,我通過Chrome瀏覽器時遇到了一些不同的JavaScript行爲。爲了調試,我需要訪問Chrome Developer Tool或Firebug之類的東西。有什麼建議麼?如何在Kindle Fire上調試絲印瀏覽器?

+0

FWIW,我現在在需要時使用Weinre。 jsconsole很棒,但是weinre提供了和Chrome開發者工具條相同的調試工具。設置起來有點複雜,但值得:http://people.apache.org/~pmuellr/weinre/docs/latest/ – 2013-01-30 16:39:14

回答

5

在這裏的同一條船...希望adb logcat會有幫助,但是JavaScript控制檯消息似乎並沒有出現在那裏。也許有些東西需要在設備上設置才能將控制檯日誌導向logcat?

編輯:找到一個體面的解決方案:http://jsconsole.com - 允許您設置遠程調試/日誌記錄控制檯。非常簡單(僅限控制檯日誌記錄,因此您需要將很多內容轉儲到日誌中)......但它運行良好。至少幫助我追蹤我的問題的根源!

如何做:http://jsconsole.com/remote-debugging.html

+0

:O jsconsole.com是我的一生?非常有幫助。謝謝! – Meekohi 2012-02-28 15:06:22

+0

這很棒。 – mckamey 2012-10-03 00:13:05

0

我採取了不同的方法,並創建了一個彈出對JavaScript對話框的包裝機應用程序。

我的包裝代碼很大,所以我拿了一些相關的部分。它實際上工作,並會顯示任何JavaScript錯誤。

// registers the debugger to catch errors 
WebView engine = (WebView) findViewById(R.id.web_engine); 
engine.setWebChromeClient(new DebugClient(this)); 

// the class that manages the errors 
private class DebugClient extends WebChromeClient { 
     Activity activity; 

     public DebugClient(Activity activity) { 
      this.activity = activity; 
     } 

     @Override 
     public boolean onConsoleMessage(ConsoleMessage consoleMessage) { 
      if (consoleMessage.messageLevel() == MessageLevel.ERROR 
        || consoleMessage.messageLevel() == MessageLevel.WARNING) { 
       String title="Javascript error on line " 
         + String.valueOf(consoleMessage.lineNumber()) 
         + " of " + consoleMessage.sourceId(); 
       AlertBox alertBox=new AlertBox(activity, (ActionListener)null, title, consoleMessage.message(), "OK"); 
       alertBox.show(); 
       alertBoxes.add(alertBox); 
      } 
      return true; 
     } 
    } 

要編譯這個,您需要在您的計算機上安裝Android SDK,並且可能需要在ADT上安裝Java IDE(Eclipse?)。然後,您只需執行以下操作:創建新項目,將WebView組件添加到layout/main.xml中,然後粘貼代碼。編譯並安裝在Kindle Fire上。