Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9800adf2 authored by Scott Main's avatar Scott Main Committed by Android (Google) Code Review
Browse files

Merge "docs: update web page debugging with info about page and line numbering...

Merge "docs: update web page debugging with info about page and line numbering in the log." into eclair
parents 196ec566 7b02e924
Loading
Loading
Loading
Loading
+30 −20
Original line number Diff line number Diff line
@@ -58,8 +58,8 @@ Log.i("MyActivity", "MyClass.getView() — get item number " + position);
<pre class="no-pretty-print">
I/MyActivity( 1557): MyClass.getView() &mdash; get item number 1
</pre>
      <p>Logcat is also the place to look when debugging a web page in the Android browser. All
browser bugs will be output to logcat with the {@code WebCore} tag.
      <p>Logcat is also the place to look when debugging a web page in the Android Browser app. See
<a href="#DebuggingWebPages">Debugging Web Pages</a> below.</p>
</dl>

<p>For more information about all the development tools provided with the Android SDK, see the <a
@@ -148,10 +148,10 @@ following options (among others):</p>

<h2 id="DebuggingWebPages">Debugging Web Pages</h2>

<p>If you're developing a web application for Android devices, you can debug your JavaScript on
Android using the Console APIs, which will output messages to logcat. If you're familiar
<p>If you're developing a web application for Android devices, you can debug your JavaScript in the
Android Browser using the Console APIs, which will output messages to logcat. If you're familiar
debugging web pages with Firefox's FireBug or WebKit's Web Inspector, then you're probably familiar
with the Console APIs. The Android Browser (and {@link android.webkit.WebChromeClient}) supports
with the Console APIs. The Android Browser (and the {@link android.webkit.WebChromeClient}) supports
most of the same APIs.</p>

<p>When you call a function from the Console APIs (in the DOM's {@code window.console} object),
@@ -162,19 +162,28 @@ console.log("Hello World");
</pre>
<p>Then the logcat output from the Android Browser will look like this:</p>
<pre class="no-pretty-print">
W/browser ( 202): Console: Hello World :0
W/browser ( 202): Console: Hello World http://www.example.com/hello.html :82
</pre>

<p class="note"><strong>Note:</strong> All Console messages from the Android
Browser are tagged with the name "browser" on Android platforms running API Level 7 or higher and
tagged with the name "WebCore" for platforms running API Level 6 or lower.</p>

<p>Not all of the Console APIs available in Firefox or other WebKit browsers are implemented
on Android. Mostly, you need to depend on basic text logging provided by
functions like {@code console.log(String)}, {@code console.info(String)}, {@code
console.warn(String)}, and {@code console.error(String)}. Although other Console functions may not
be implemented, they will not raise run-time errors, but will simply not behave as you might
expect.</p>
<p>All Console messages from the Android Browser are tagged with the name "browser" on Android
platforms running API Level 7 or higher. On platforms running API Level 6 or lower, Browser
messages are tagged with the name "WebCore". The Android Browser also formats console messages
with the log message
preceded by "Console:" and then followed by the address and line number where the
message occurred. (The format for the address and line number will appear different from the example
above on platforms running API Level 6 or lower.)</p>

<p>The Android Browser (and {@link android.webkit.WebChromeClient}) does not implement all of the
Console APIs provided by Firefox or other WebKit-based browsers. Primarily, you need to depend
on the basic text logging functions:</p>
<ul>
  <li>{@code console.log(String)}</li>
  <li>{@code console.info(String)}</li>
  <li>{@code console.warn(String)}</li>
  <li>{@code console.error(String)}</li>
</ul>
<p>Although the Android Browser may not fully implement other Console functions, they will not raise
run-time errors, but may not behave the same as they do on other desktop browsers.</p>

<p>If you've implemented a custom {@link android.webkit.WebView} in your application, then in order
to receive messages that are sent through the Console APIs, you must provide a {@link
@@ -185,7 +194,7 @@ android.webkit.WebView} in your application, you can log debug messages like thi
<pre>
myWebView.setWebChromeClient(new WebChromeClient() {
  public void onConsoleMessage(String message, int lineNumber, String sourceID) {
    Log.d("MyApplication", message);
    Log.d("MyApplication", message + " -- From line " + lineNumber + " of " + sourceID);
  }
});
</pre>
@@ -195,13 +204,14 @@ within your {@link android.webkit.WebView}.</p>
<p>When the "Hello World" log is executed through your {@link android.webkit.WebView}, it will
now look like this:</p>
<pre class="no-pretty-print">
D/MyApplication ( 430): Hello World
D/MyApplication ( 430): Hello World -- From line 82 of http://www.example.com/hello.html
</pre>

<p class="note"><strong>Note:</strong> The {@link
android.webkit.WebChromeClient#onConsoleMessage(String,int,String) onConsoleMessage()} callback
method was added with API Level 7. If you are targetting platforms running API Level 6 or lower,
then your Console messages will automatically be sent to logcat with the "WebCore" logging tag.</p>
method was added with API Level 7. If you are using a custom {@link
android.webkit.WebView} on a platform running API Level 6 or lower, then your Console messages will
automatically be sent to logcat with the "WebCore" logging tag.</p>