Skip to content

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.

AlexTrotsenko/j2v8-debugger

Repository files navigation

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 for communication with Chrome DevTools.

Features

  • Debugging embedded V8 in Android app using Chrome DevTools.
  • Support setting/removing breakpoints, step into, step out and step over, variables inspection, etc.
  • Debugging embedded V8 is similar to Remote Debugging WebViews.
  • Access debuggable V8 in the app via chrome://inspect.

SetUp

Add JitPack repository in your root build.gradle at the end of repositories:

allprojects {
    repositories {
        maven { url "https://jitpack.io" }
    }
}

Add dependency in gradle.build file of your app module

dependencies {
    implementation ('com.github.AlexTrotsenko:j2v8-debugger:0.2.3') // {
    //     optionally J2V8 can be excluded if specific version of j2v8 is needed or defined by other libs
    //     exclude group: 'com.eclipsesource.j2v8'
    // }
}

Note: current j2v8-debugger version is designed for J2V8 version 6.1+.

Use 0.1.2 when debugging of older J2V8 (4.6.0+) is required.

Usage

StethoHelper and V8Debugger are used for set-up of Chrome DevTools and V8 for debugging.

  1. Initialization Stetho in Application class.
    StethoHelper.initializeDebugger(context, scriptSourceProvider)
  1. Creation of debuggable V8 instance.

Use V8Debugger.createDebuggableV8Runtime() instead of V8.createV8Runtime()

    val debuggableV8Runtime : Future<V8> = V8Debugger.createDebuggableV8Runtime(v8Executor, globalAlias, enableLogging)

See sample project for more info.

Notes regarding J2V8 threads.

  • Creation and clean-up of V8 should run on fixed V8 thread.
  • Creation and clean-up of V8 Debugger should run on fixed V8 thread.
  • Debugging operation like set/remove breakpoint should run on fixed V8 thread.
  • Execution of any JS script/function should run on fixed V8 thread.

It's easier to implement such behaviour (especially from lib point of view) if single-threaded V8 executor is used.

This way all above mentioned operations would run on such executor.

Therefore lib api like V8Debugger.createDebuggableV8Runtime(v8Executor) is build with this concept in mind.

Later v8 executor will be passed to Chrome DevTools and used for performing debug-related operations.

If Guava is already used in project - MoreExecutors and ListenableFuture could be handy.

License

Copyright 2015 Alexii Trotsenko

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

About

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.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •  

Languages