Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.

Overview

Stetho Build Status

Stetho is a sophisticated debug bridge for Android applications. When enabled, developers have access to the Chrome Developer Tools feature natively part of the Chrome desktop browser. Developers can also choose to enable the optional dumpapp tool which offers a powerful command-line interface to application internals.

Once you complete the set-up instructions below, just start your app and point your laptop browser to chrome://inspect. Click the "Inspect" button to begin.

Set-up

Download

Download the latest JARs or grab via Gradle:

implementation 'com.facebook.stetho:stetho:1.5.1'

or Maven:

<dependency>
  <groupId>com.facebook.stetho</groupId>
  <artifactId>stetho</artifactId>
  <version>1.5.1</version>
</dependency>

Only the main stetho dependency is strictly required; however, you may also wish to use one of the network helpers:

implementation 'com.facebook.stetho:stetho-okhttp3:1.5.1'

or:

implementation 'com.facebook.stetho:stetho-urlconnection:1.5.1'

You can also enable a JavaScript console with:

implementation 'com.facebook.stetho:stetho-js-rhino:1.5.1'

For more details on how to customize the JavaScript runtime see stetho-js-rhino.

Putting it together

Integrating with Stetho is intended to be seamless and straightforward for most existing Android applications. There is a simple initialization step which occurs in your Application class:

public class MyApplication extends Application {
  public void onCreate() {
    super.onCreate();
    Stetho.initializeWithDefaults(this);
  }
}

Also ensure that your MyApplication Java class is registered in your AndroidManifest.xml file, otherwise you will not see an "Inspect" button in chrome://inspect/#devices :

<manifest
        xmlns:android="http://schemas.android.com/apk/res/android"
        ...>
        <application
                android:name="MyApplication"
                ...>
         </application>
</manifest>                

This brings up most of the default configuration but does not enable some additional hooks (most notably, network inspection). See below for specific details on individual subsystems.

Enable network inspection

If you are using the popular OkHttp library at the 3.x release, you can use the Interceptors system to automatically hook into your existing stack. This is currently the simplest and most straightforward way to enable network inspection:

new OkHttpClient.Builder()
    .addNetworkInterceptor(new StethoInterceptor())
    .build()

Note that okhttp 2.x will work as well, but with slightly different syntax and you must use the stetho-okhttp artifact (not stetho-okhttp3).

As interceptors can modify the request and response, add the Stetho interceptor after all others to get an accurate view of the network traffic.

If you are using HttpURLConnection, you can use StethoURLConnectionManager to assist with integration though you should be aware that there are some caveats with this approach. In particular, you must explicitly add Accept-Encoding: gzip to the request headers and manually handle compressed responses in order for Stetho to report compressed payload sizes.

See the stetho-sample project for more details.

Going further

Custom dumpapp plugins

Custom plugins are the preferred means of extending the dumpapp system and can be added easily during configuration. Simply replace your configuration step as such:

Stetho.initialize(Stetho.newInitializerBuilder(context)
    .enableDumpapp(new DumperPluginsProvider() {
      @Override
      public Iterable<DumperPlugin> get() {
        return new Stetho.DefaultDumperPluginsBuilder(context)
            .provide(new MyDumperPlugin())
            .finish();
      }
    })
    .enableWebKitInspector(Stetho.defaultInspectorModulesProvider(context))
    .build())

See the stetho-sample project for more details.

Improve Stetho!

See the CONTRIBUTING.md file for how to help out.

License

Stetho is MIT-licensed. See LICENSE file for more details.

Comments
  • Screencasting support

    Screencasting support

    Tries to implement screencasting support as described in #189 It is still a bit janky but works. I'll try to get it improved.

    screen shot 2015-05-14 at 11 44 36 pm

    Still needs to be fixed:

    • When the app is closed while the screencast is running, we get a crash since the bitmap is disposed and we never got a chance to set mIsRunning to false. Need to find a way to detect that the activity is closing, maybe isFinishing() would do.
    • Jankiness

    Nice to have:

    • Touch support
    CLA Signed 
    opened by felipecsl 45
  • Chrome doesn't see my device

    Chrome doesn't see my device

    Hi, I followed all the steps for setting up Stetho. But my Chrome just flashes

    Pending authentication: please accept debugging session on the device.

    Please advise.

    opened by IgorGanapolsky 41
  • Chrome only shows a white screen

    Chrome only shows a white screen

    Trying to inspect using Chrome only shows a white screen. This is Chrome 54.0.2840.98 (64-bit) on OSX 10.11.6

    screen shot 2016-11-30 at 8 09 30 pm

    Looking at logcat I can see that stetho was initialized and that is supposed to be listening.

    com.facebook.stetho.sample I/SampleDebugApplication: Stetho initialized in 5 ms
    com.facebook.stetho.sample I/stetho: Listening on @stetho_com.facebook.stetho.sample_devtools_remote
    

    Any tips on debugging this issue?

    opened by carlospaulino 27
  • OkHttp3 Interceptor crash

    OkHttp3 Interceptor crash

    I just upgraded OkHttp to version 3.0.1 and Stetho to version 1.3.0 (and its corresponding new OkHttp3 network interceptor).

    I'm experiencing the following NullPointerException when inspecting HTTP traffic:

    E/stetho: com.facebook.stetho.inspector.elements.android.DialogFragmentDescriptor.getChildren() emitted a null child at position 0 for element LayoutFragment{3a8b2dd3 #0 id=0x7f0c00dc}
    E/AndroidRuntime: FATAL EXCEPTION: OkHttp Dispatcher
             Process: com.artech.androidbasictest.testgxsalto, PID: 29855
             java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Object.hashCode()' on a null object reference
             at com.facebook.stetho.okhttp3.StethoInterceptor$OkHttpInspectorResponse.connectionId(StethoInterceptor.java:229)
             at com.facebook.stetho.inspector.network.NetworkEventReporterImpl.responseHeadersReceived(NetworkEventReporterImpl.java:143)
             at com.facebook.stetho.okhttp3.StethoInterceptor.intercept(StethoInterceptor.java:73)
             at okhttp3.internal.http.HttpEngine$NetworkInterceptorChain.proceed(HttpEngine.java:681)
             at okhttp3.internal.http.HttpEngine.readResponse(HttpEngine.java:563)
             at okhttp3.RealCall.getResponse(RealCall.java:241)
             at okhttp3.RealCall$ApplicationInterceptorChain.proceed(RealCall.java:198)
             at okhttp3.RealCall.getResponseWithInterceptorChain(RealCall.java:160)
             at okhttp3.RealCall.access$100(RealCall.java:30)
             at okhttp3.RealCall$AsyncCall.execute(RealCall.java:127)
             at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:33)
             at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
             at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
             at java.lang.Thread.run(Thread.java:818)
    
    opened by juandiana 27
  • Can't get it to work on main application

    Can't get it to work on main application

    Hi,

    Thanks for this librarie that opens new perspectives. I can make the sample application work perfectly but can't make my main application.

    I can inspect the application, but instead of seeing the

     Welcome to Stetho
              Attached to com.facebook.stetho.sample
    

    I see in red

    Not implemented: Profiler.setSamplingInterval
    

    And nothing available in the resources tab.

    On the application logcat I have the exact same things as the sample application :

    D/ChromeDevtoolsServer﹕ onOpen
    

    Then

    D/ChromeDevtoolsServer﹕ Method not implemented: Not implemented: Page.canEmulate 
    

    and some others.

    Then finally the

    D/ChromeDevtoolsServer﹕ onClose: reason=1011 EOF while reading 
    

    when I close the inspect window.

    No error or nothing so hard to understand the problem.

    opened by Tolriq 25
  • Support target SDK version of android-MNC for android m release

    Support target SDK version of android-MNC for android m release

    What's the timeline for an Android M compatible release?

    Apache HTTP client is going away and I see various classes (DumpappHandler.java, ChromeDiscoveryHandler.java, etc.) using it.

    enhancement 
    opened by gpolak 22
  • NullPointerException

    NullPointerException

    I'm can't reproduce it every time (version 1.3.1)

    Process: com.adoriasoft.quietping, PID: 9303
    java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.Integer.intValue()' on a null
    at com.facebook.stetho.inspector.elements.Document$4.store(Document.java:388)
    at com.facebook.stetho.inspector.elements.ShadowDocument$Update.getChangedElements(ShadowDocument.java:297)
    at com.facebook.stetho.inspector.elements.Document.applyDocumentUpdate(Document.java:372)
    at com.facebook.stetho.inspector.elements.Document.updateTree(Document.java:327)
    at com.facebook.stetho.inspector.elements.Document.access$1200(Document.java:30)
    at com.facebook.stetho.inspector.elements.Document$ProviderListener.onPossiblyChanged(Document.java:682)
    at com.facebook.stetho.inspector.elements.android.AndroidDocumentProvider$1.run(AndroidDocumentProvider.java:67)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:145)
    at android.app.ActivityThread.main(ActivityThread.java:5951)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
    
    bug 
    opened by droidandrew 18
  • Memory leak in Stetho 1.2.0

    Memory leak in Stetho 1.2.0

    We've experienced a severe memory leak after we integrated Stetho into our app. Through bisection we could pin down the exact revision when we did this and could verify that - once Stetho was removed - the memory leak was gone.

    The leak showed up in Android's Memory Monitor, where constantly around 20KB/s have been added on top until the limit was reached and GC kicked in. Then, from the lower level onwards, memory consumption raised again.

    The way we integrated Stetho was fairly basic, we only enabled it in our custom Application instance via Stetho.initializeWithDefaults(this) for DEBUG builds.

    enhancement 
    opened by realdadfish 18
  • Implements support for DOM.setAttributesAsText()

    Implements support for DOM.setAttributesAsText()

    Fixes #145

    This is my initial stab at implementing a new DOM request setAttributesAsText().

    Right now this correctly calls any setter that has a single argument of type int, float, boolean, String or CharSequence of View (and subclasses) using the MethodInvoker. Examples are setTex()t, setId(), setAlpha(), etc. More types can be supported by extending TypedMethodInvoker.

    Question:

    • Do we need to send a response back after completed?
    CLA Signed 
    opened by felipecsl 18
  • Fix importClass and importPackage not finding external classes

    Fix importClass and importPackage not finding external classes

    For external packages, the package name needs to be prefixed with Packages. per https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java#External_Packages_and_Classes

    Mostly fixes #405

    CLA Signed 
    opened by paour 17
  • Incompatibility with Java 8

    Incompatibility with Java 8

    Hi, when I try to integrate your library, my Android Studio throws Java 8 compile errors. As a result, I cannot use Stetho if my IDE/project is setup to use Java 8.

    Please advise.

    opened by IgorGanapolsky 17
  • Inspect Devices UI is distorted

    Inspect Devices UI is distorted

    Everything was working fine until chrome version - 86.0.4240.75 (Official Build) (x86_64). Attached are the screenshots below.

    Screenshot 2022-09-17 at 3 20 33 AM Screenshot 2022-09-17 at 3 20 15 AM

    On the latest version of the Google Chromes Version 105.0.5195.125 (Official Build) (x86_64)

    The network section moved to the complete right side and we can't see anything or we can't drag too. Screenshot 2022-09-17 at 3 23 52 AM

    opened by pradeepkommu 2
  • exempt a disk read from StrictMode as stetho is strictly a debug orie…

    exempt a disk read from StrictMode as stetho is strictly a debug orie…

    Violation:

    StrictMode policy violation; ~duration=5 ms: android.os.strictmode.DiskReadViolation
        at android.os.StrictMode$AndroidBlockGuardPolicy.onReadFromDisk(StrictMode.java:1596)
        at libcore.io.BlockGuardOs.fstat(BlockGuardOs.java:174)
        at libcore.io.ForwardingOs.fstat(ForwardingOs.java:106)
        at libcore.io.IoBridge.open(IoBridge.java:481)
        at java.io.FileInputStream.<init>(FileInputStream.java:160)
        at java.io.FileInputStream.<init>(FileInputStream.java:115)
        at com.facebook.stetho.common.ProcessUtil.readProcessName(ProcessUtil.java:49)
        at com.facebook.stetho.common.ProcessUtil.getProcessName(ProcessUtil.java:38)
        at com.facebook.stetho.server.AddressNameHelper.createCustomAddress(AddressNameHelper.java:20)
        at com.facebook.stetho.Stetho$Initializer.start(Stetho.java:449)
        at com.facebook.stetho.Stetho.initialize(Stetho.java:134)
    

    But "/proc/self/cmdline is a memory file and won't actually hit disk" thus it can be exempted.

    CLA Signed 
    opened by jijichen 0
  • Usage of weak crypto algorithms like SHA-1 in Stetho

    Usage of weak crypto algorithms like SHA-1 in Stetho

    Summary

    Our Penetration testing team has identified usage of weak crypto algorithms like SHA-1 in Stetho and logged security vulnerability. What are the plans to migrate to the latest crypto algorithms? Can you please migrate to the latest crypto algorithms to mitigate this?

    Recommendation: Utilize cryptographic hashing algorithms that are considered secure and advocated for in best practice recommendations. Guidance can be found for Android For more guidance on best practices in picking strong cryptography, please see OWASP's Cryptographic Storage Cheat Sheet.

    Motivations

    Security Vulnerability.

    opened by nidhi88 1
  • NoSuchMethodError issue

    NoSuchMethodError issue

    crash occurs on 1 user (from 1.29M active user) with device Samsung Galaxy A3(2016).

    Here is crashlytics log

    Fatal Exception: java.lang.NoSuchMethodError: No interface method nextRequestId()Ljava/lang/String; in class Lcom/facebook/stetho/inspector/network/NetworkEventReporter; or its super classes (declaration of 'com.facebook.stetho.inspector.network.NetworkEventReporter' appears in base.apk:classes2.dex) at com.facebook.stetho.okhttp3.StethoInterceptor.intercept(StethoInterceptor.java:40)

    can anyone tell me to fix the issue?

    opened by edtslib 0
  • Stetho doesn't capture network in network inspector

    Stetho doesn't capture network in network inspector

    description

    i'm using stetho for inspect network for release mode apk. but chrome devtool Netowrk tab doen't show anything.

    environment

    Chrome version: 88.0.4324.0(developer build) (x86_64) RN version: 0.53.2 stetho versino: 1.6.0 stetho-okhttp3: 1.6.0

    opened by Einere 2
Releases(v1.6.0)
Owner
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
Facebook
Under the Hood is a flexible and powerful Android debug view library. It uses a modular template system that can be easily extended to your needs, although coming with many useful elements built-in.

Under the Hood - Android App Debug View Library Under the Hood is a flexible and powerful Android debug view library. It uses a modular template syste

Patrick Favre-Bulle 217 Nov 25, 2022
A view that makes it easy to debug response data.(一个可以方便调试响应数据的视图。)

JSONRecyclerView 该控件可以方便调试响应数据,如下图所示: 控件的样式参考以下这个网站: JSON在线解析解析及格式化验证 项目的GitHub:JSONRecyclerView 项目Demo的GitHub:JSONRecyclerViewDemo 概述 控件是以RecyclerVie

TanJiaJun 28 Oct 7, 2022
Pluto: An on-device debugging framework for Android applications

Pluto is an on-device debugging framework for Android applications, which helps in the inspection of HTTP requests/responses, captures Crashes, and ANRs, and manipulates application data on the go.

Pluto 550 Dec 27, 2022
A library for debugging android databases and shared preferences - Make Debugging Great Again

Android Debug Database Android Debug Database is a powerful library for debugging databases and shared preferences in Android applications Android Deb

AMIT SHEKHAR 8.1k Dec 29, 2022
🔪Swiss-army knife for Android testing and development 🔪 ⛺

ADB Enhanced ADB-Enhanced is a Swiss-army knife for Android testing and development. A command-line interface to trigger various scenarios like screen

Ashish Bhatia 938 Dec 20, 2022
A Read-Eval-Print-Loop server for Android and SQLite

Android DebugPort Android DebugPort is a drop-in utility which allows you to write and execute code within your app's context, at runtime, and from th

Jason Feinstein 148 Nov 14, 2022
Easy android exception tracer and handler.

Introduction Lup is a small android library that can help you to tracking bug that causes application stopped working (force close). Whiting this libr

icodeu 4 Sep 29, 2022
Cordova plugin for Android Serial USB communication (easily connect an Arduino board to an Android device).

PR-DC cordova-plugin-serialusb Cordova plugin for Android Serial USB communication. This plugin makes a connection to the external board trivial, for

PR-DC 3 May 8, 2022
Android library to record the network calls through the interceptor mechanism of the http clients.

Android Snooper Introduction Android Snooper is a library which helps in debugging issues while running the applications on android devices. One of th

Prateek 151 Nov 25, 2022
traffic debugging library for android

TrafficMonitor About Display traffic per Activity.Observing traffic is used by TrafficStats API. OkHttp Interceptor observer is implementing. Demo Bai

Tetsuya Masuda 17 Feb 4, 2022
Sources for the LiveBoot app for rooted Android devices

This is the sauce for the LiveBoot app. License Copyright © 2011-2020 Jorrit Chainfire Jongma This code is released under the GPLv3. LICENSE, COPYING.

Chainfire 131 Jan 9, 2023
android logcat

android logcat

Ji Sungbin 3 Dec 2, 2022
A local ADB shell for Android!

LADB A local ADB shell for Android! How does it work? LADB bundles an ADB server within the app libraries. Normally, this server cannot connect to the

Tyler 1.1k Jan 2, 2023
btrace(AKA RheaTrace) is a high performance Android trace tool which is based on Systrace

btrace README 中文版 btrace(AKA RheaTrace) is a high performance Android trace tool

Bytedance Inc. 1.2k Jan 4, 2023
This project is an add-on for the excellent J2V8 Project. It allows users to debug JS running in V8 using Chrome DevTools. Uses Stetho for communication with Chrome DevTools.

J2V8-Debugger This project is an add-on for the excellent J2V8 Project. It allows users to debug JS running in V8 using Chrome DevTools. Uses Stetho f

Alex Trotsenko 76 Jan 3, 2023
🍼Debug Bottle is an Android runtime debug / develop tools written using kotlin language.

???? 中文 / ???? 日本語 / ???? English ?? Debug Bottle An Android debug / develop tools written using Kotlin language. All the features in Debug bottle are

Yuriel Arlencloyn 846 Nov 14, 2022
🍼Debug Bottle is an Android runtime debug / develop tools written using kotlin language.

???? 中文 / ???? 日本語 / ???? English ?? Debug Bottle An Android debug / develop tools written using Kotlin language. All the features in Debug bottle are

Yuriel Arlencloyn 846 Nov 14, 2022
Kotlin-phoenix - A set of tools aimed to bridge Phoenix with the Kotlin Multiplatform world

Kotlin Phoenix This project is aimed to allow developers to work with Phoenix Ch

Adrien Jacquier Bret 5 Sep 21, 2022