facebookarchive / stetho

Stetho is a debug bridge for Android applications, enabling the powerful Chrome Developer Tools and much more.
http://facebook.github.io/stetho/
MIT License
12.66k stars 1.13k forks source link

Stetho does not load custom dev tool domain #609

Closed ghost closed 5 years ago

ghost commented 5 years ago

I have been exploring Stetho and I find it quite interesting. Tried to create my own custom:

public class AmazingAndCustomDevTool implements ChromeDevtoolsDomain {

    @ChromeDevtoolsMethod
    public void enable(JsonRpcPeer peer, JSONObject params) {
        System.out.println();
    }

    @ChromeDevtoolsMethod
    public void disable(JsonRpcPeer peer, JSONObject params) {
        System.out.println();
    }
}

and I add it with:

Stetho.initialize(Stetho.newInitializerBuilder(this) .enableWebKitInspector(() -> new ArrayList() {{ add(new Console()); add(new Page(getBaseContext())); add(new AmazingAndCustomDevTool());; }}) .build());

However it's never loaded, enable is never reached. (Sorry for the formatting)

Thank you.

jasta commented 5 years ago

I think you're looking for DefaultInspectorModulesBuilder. You can provide(...) additional devtools domain files if you'd like but note that these need to actually be referenced by the Chrome devtools. In theory you could extend this yourself by forking the devtools UI and adding whatever you want but this was not explicitly a design goal of Stetho.

That said, it would be very possible with Stetho's design to actually just add an entirely new, third protocol implementation and create your own entirely custom UI. This is very similar to the approach taken by another developer tool released by Facebook called Flipper: https://github.com/facebook/flipper.