Search code examples
androidgoogle-chromegoogle-chrome-devtoolsandroid-debugstetho

Stetho and chrome:inspect pending REST petitions


I'm using Stetho, Retrofit and OkHttp with Chrome Developer Tools for debug purposes, all seems to work OK, I see my local database content, I can inspect my UI, but if I do some REST petitions to my server with the Network Inspection enabled the petitions remains as "Pending", but if I copy the URL and paste on a Chrome tab the petition executes correctly and I don't know what is happening.

enter image description here

These are my gradle imports:

compile 'com.squareup.retrofit2:retrofit:2.1.0'
compile 'com.squareup.okhttp3:logging-interceptor:3.9.1'
compile 'com.squareup.retrofit2:converter-gson:2.1.0'

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

Solution

  • I found the answer here https://github.com/facebook/stetho/issues/346

    I accidentally used a regular interceptor instead of a network interceptor.

    So this is my WRONG version

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);
            httpClient.addInterceptor(new StethoInterceptor());
    

    And this is the CORRECT version:

            HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
            logging.setLevel(HttpLoggingInterceptor.Level.BODY);
            OkHttpClient.Builder httpClient = new OkHttpClient.Builder();
            httpClient.addInterceptor(logging);
            httpClient.addNetworkInterceptor(new StethoInterceptor());