Merge "docs: update web page debugging with info about page and line numbering in the log." into eclair
This commit is contained in:
@@ -58,8 +58,8 @@ Log.i("MyActivity", "MyClass.getView() — get item number " + position);
|
|||||||
<pre class="no-pretty-print">
|
<pre class="no-pretty-print">
|
||||||
I/MyActivity( 1557): MyClass.getView() — get item number 1
|
I/MyActivity( 1557): MyClass.getView() — get item number 1
|
||||||
</pre>
|
</pre>
|
||||||
<p>Logcat is also the place to look when debugging a web page in the Android browser. All
|
<p>Logcat is also the place to look when debugging a web page in the Android Browser app. See
|
||||||
browser bugs will be output to logcat with the {@code WebCore} tag.
|
<a href="#DebuggingWebPages">Debugging Web Pages</a> below.</p>
|
||||||
</dl>
|
</dl>
|
||||||
|
|
||||||
<p>For more information about all the development tools provided with the Android SDK, see the <a
|
<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>
|
<h2 id="DebuggingWebPages">Debugging Web Pages</h2>
|
||||||
|
|
||||||
<p>If you're developing a web application for Android devices, you can debug your JavaScript on
|
<p>If you're developing a web application for Android devices, you can debug your JavaScript in the
|
||||||
Android using the Console APIs, which will output messages to logcat. If you're familiar
|
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
|
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>
|
most of the same APIs.</p>
|
||||||
|
|
||||||
<p>When you call a function from the Console APIs (in the DOM's {@code window.console} object),
|
<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>
|
</pre>
|
||||||
<p>Then the logcat output from the Android Browser will look like this:</p>
|
<p>Then the logcat output from the Android Browser will look like this:</p>
|
||||||
<pre class="no-pretty-print">
|
<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>
|
</pre>
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> All Console messages from the Android
|
<p>All Console messages from the Android Browser are tagged with the name "browser" on Android
|
||||||
Browser are tagged with the name "browser" on Android platforms running API Level 7 or higher and
|
platforms running API Level 7 or higher. On platforms running API Level 6 or lower, Browser
|
||||||
tagged with the name "WebCore" for platforms running API Level 6 or lower.</p>
|
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>Not all of the Console APIs available in Firefox or other WebKit browsers are implemented
|
<p>The Android Browser (and {@link android.webkit.WebChromeClient}) does not implement all of the
|
||||||
on Android. Mostly, you need to depend on basic text logging provided by
|
Console APIs provided by Firefox or other WebKit-based browsers. Primarily, you need to depend
|
||||||
functions like {@code console.log(String)}, {@code console.info(String)}, {@code
|
on the basic text logging functions:</p>
|
||||||
console.warn(String)}, and {@code console.error(String)}. Although other Console functions may not
|
<ul>
|
||||||
be implemented, they will not raise run-time errors, but will simply not behave as you might
|
<li>{@code console.log(String)}</li>
|
||||||
expect.</p>
|
<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
|
<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
|
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>
|
<pre>
|
||||||
myWebView.setWebChromeClient(new WebChromeClient() {
|
myWebView.setWebChromeClient(new WebChromeClient() {
|
||||||
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
|
public void onConsoleMessage(String message, int lineNumber, String sourceID) {
|
||||||
Log.d("MyApplication", message);
|
Log.d("MyApplication", message + " -- From line " + lineNumber + " of " + sourceID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</pre>
|
</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
|
<p>When the "Hello World" log is executed through your {@link android.webkit.WebView}, it will
|
||||||
now look like this:</p>
|
now look like this:</p>
|
||||||
<pre class="no-pretty-print">
|
<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>
|
</pre>
|
||||||
|
|
||||||
<p class="note"><strong>Note:</strong> The {@link
|
<p class="note"><strong>Note:</strong> The {@link
|
||||||
android.webkit.WebChromeClient#onConsoleMessage(String,int,String) onConsoleMessage()} callback
|
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,
|
method was added with API Level 7. If you are using a custom {@link
|
||||||
then your Console messages will automatically be sent to logcat with the "WebCore" logging tag.</p>
|
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>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user