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

Related tags

stetho
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.

Issues
  • 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
  • Implement Console tab support with Rhino

    Implement Console tab support with Rhino

    This is an implementation of issue facebook/stetho#81 using Mozilla's Rhino JavaScript library.

    CLA Signed enhancement 
    opened by potyl 21
  • 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
  • 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
  • typo fix

    typo fix

    changing bsd to mit and header files typo fix

    CLA Signed 
    opened by surajsahani 0
  • Fixing markdown formatting for github-pages

    Fixing markdown formatting for github-pages

    CLA Signed 
    opened by eapen 0
  • How fix this?

    How fix this?

    image

    opened by cislone 1
  • DevTools inspect window doesn't render properly

    DevTools inspect window doesn't render properly

    Hello everyone,

    I've been using Stetho for over a year in my Macbook Pro (Intel Chip). Since yesterday after I try to inspect my app through the device via Chrome. A badly rendered DevTool window appears which doesn't show anything.

    Here's a screenshot: Screenshot 2021-03-04 at 16 34 03

    I've tried to use another device already. Restarted my Laptop, re-installed Chrome. Nothing appears to be working anymore. 😞

    Any ideas? Thank you in advance.

    opened by AresProductions 39
  • How to user Discover network targets mode inspect app

    How to user Discover network targets mode inspect app

    How to use Discover network targets mode inspect app

    opened by zs1973 0
  • Stetho protobufs - Documentation request

    Stetho protobufs - Documentation request

    I found this issue here: https://github.com/facebook/stetho/issues/250 that suggests that there is a way to log protobuf files. Clearly there has been some work done on this, but it doesn't look like there are any docs or a description on how to use it. So my question - how do we log protobufs with stetho? How do we use this tool you built? @jasta

    Thanks!

    opened by Ryanauger95 1
  • Use https instead of http

    Use https instead of http

    Note that the Stetho site is rated as "not secure" for including content from HTTP sources. This pull-request fixes this and prevents any possible attempts at intrusion.

    CLA Signed 
    opened by gmarcos87 0
  • it seems Facebook is collecting device data even it is initialised in debug mode

    it seems Facebook is collecting device data even it is initialised in debug mode

    Hi Team, Are you collecting device data in production environment even if we initialise in debug mode only ?

    opened by tmehta813 0
  • Use debugImplementation in code example

    Use debugImplementation in code example

    Because Stetho exposes Shared Prefs and SQLite, which may contain sensitive information, and since many devs will just copy / paste from the README, I thought I'd throw in my $0.02 that the code examples be changed such that it is a bit less susceptible to Murphy's Law.

    CLA Signed 
    opened by duncancarroll 3
  • Test improvement: removed Magic Number test smell

    Test improvement: removed Magic Number test smell

    This is a test refactoring

    Problem: The Magic Number Test occurs when assert() statements in a test method contain numeric literals (i.e., magic numbers) as parameters.

    Solution: As magic numbers do not indicate the meaning/purpose of the number, they should be replaced with constants or variables, thereby providing a descriptive name for the input.

    Results:

    Before:

    private final int HTTP_OK = 200;
    .
    .
    .
    Response reply = new Response.Builder()
            .request(request)
            .protocol(Protocol.HTTP_1_1)
            .code(200)
            .body(ResponseBody.create(MediaType.parse("text/plain"), originalBodyData))
            .build();
    

    After:

    Response reply = new Response.Builder()
            .request(request)
            .protocol(Protocol.HTTP_1_1)
            .code(HTTP_OK)
            .body(ResponseBody.create(MediaType.parse("text/plain"), originalBodyData))
            .build();
    
    CLA Signed 
    opened by gvma 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
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 7.8k Jul 26, 2021
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 218 Jul 21, 2021
RxJava 2.x extension to provide meaningful Stack Traces

RxJava2Debug A library to make StackTraces involving RxJava2 more meaningful (they will always point to your code!). Rationale If you use RxJava2, you

Mikel 674 May 11, 2021
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 149 Jul 18, 2021
RxDisposableWatcher — find leaked subscriptions in RxJava code 🐞

Monitoring leaked Disposable subscriptions in RxJava code ??

Andrey Fomenkov 9 Apr 20, 2021
🔪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 844 Jul 25, 2021
Colored logcat script which only shows log entries for a specific application package.

PID Cat An update to Jeff Sharkey's excellent logcat color script which only shows log entries for processes from a specific application package. Duri

Jake Wharton 4.4k Jul 30, 2021
一款神奇宝贝信息查看app

Pukedex2 一款神奇宝贝信息查看app 帮助自己更好的了解架构组件和协程的使用: apk下载地址:(https://github.com/chenqi5256969/Pukedex2/blob/master/apk/app-debug.apk) 协程这一块主要是用到flow来更好进行流式调用,

一个努力成为大牛程序猿 33 Jun 22, 2021
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 139 Aug 3, 2021
A view that makes it easy to debug response data.(一个可以方便调试响应数据的视图。)

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

TanJiaJun 24 Jul 30, 2021
A surgical debugging tool to uncover the layers under your app.

Scalpel DEPRECATED! Android Studio 4.0's layout inspector now includes a live-updating 3D view. Use it! A surgical debugging tool to uncover the layer

Jake Wharton 2.8k Aug 1, 2021
This app will show grid overlay over whole system which helps you to verify your excellent app design.

GridWichterle for Android This app will show grid overlay over whole system which helps you to verify your excellent app design. Download: What is the

Inmite s.r.o. 409 Dec 17, 2020