Autox.js v7 Documentation

repository·setup-v7·Indexed 23 days ago

https://github.com/aiselp/autox

An Android-based JavaScript runtime and development environment for automation and UI testing. It leverages Accessibility Services, provides a Selector API for interacting with on-screen controls, and supports Node.js integration via Javet, Shizuku, and a Vue3-based UI framework. The environment uses Rhino 1.8.0 with ES6+ syntax support.

Tokens
15K
Snippets
26
Records
127
Agent score
79%

What's inside Autox.js

  1. What is Autox.js v7

    setup-v7

    Autox.js v7 is a JavaScript runtime and development environment for the Android platform that leverages Accessibility Services to perform automated operations. It is designed for workflow automation and UI testing, similar to JsBox or Workflow.

    Key capabilities include:

    • Automated Operations: Simple functions for interacting with Android UI via Accessibility Services.
    • Selector API: A powerful API for finding, traversing, and interacting with on-screen controls (similar to Google's UiAutomator).
    • UI Development: Support for building interfaces using e4x or a new framework based on Vue3 and Jetpack Compose.
    • Scripting: Uses JavaScript (Rhino 1.8.0) with support for ES6+ syntax.
    • Advanced Features: Support for Shizuku, Root permissions for precise clicks/swipes, screen capture, image recognition (color/pattern finding), and Tasker integration.
    • Node.js Integration: Includes a Node.js engine (via Javet) allowing the use of many npm packages and Java interoperability.
  2. Introduction to AutoX.js v7

    setup-v7

    AutoX.js v7 is a JavaScript runtime and development environment for the Android platform. It is designed for automation and workflow tasks, similar to JsBox or Workflow. It uses accessibility services to implement automatic operations and can be used as a mobile UI testing framework (similar to Google's UiAutomator) or a small tool application development platform.

    Key capabilities include:

    • Control-based automation: Uses a professional selector API for searching, traversing, and interacting with screen controls (more robust than coordinate-based methods).
    • UI Development: Supports writing interfaces using e4x or a new framework based on Vue3 and Jetpack Compose.
    • Scripting: Uses JavaScript (Rhino 1.8.0) with support for ES6+ syntax.
    • Node.js Integration: Includes a NodeJS engine that supports running many NPM packages and interoperability with Java.
    • Advanced Features: Supports Shizuku for dynamic debugging, Root permissions for precise clicks/slides, and image-based search/color detection.
  3. Error handling in bluebird-co

    setup-v7

    bluebird-co supports standard error handling patterns (top-level, nested, and deep errors) within async functions and generators.

    Performance Note: bluebird-co is slightly slower at error handling compared to co because errors must pass through the Bluebird.coroutine circuitry rather than being thrown directly. However, this is typically negligible unless your application is throwing an extremely high volume of errors.

    //Top level error
    async function() {
        await undefined;
    }
    
    //nested error
    async function() {
        await function*() {
            yield undefined;
        }
    }
    
    //deep error
    async function() {
        let i = 0;
    
        await function*() {
            if(i++ > 2000) throw new Error();
    
            yield Promise.resolve(i);
        }
    }
  4. How bluebird-co handles Iterables

    setup-v7

    bluebird-co provides automatic traversal for ES6 iterables (like Set, Map, and TypedArray). It behaves similarly to Array.from but automatically resolves any asynchronous values encountered during traversal.

    Note: While native for..of loops in modern environments can iterate through iterables, they do not automatically resolve asynchronous values; bluebird-co's approach handles this resolution for you.

    let mySet = new Set( [Promise.resolve( 1 ), 2, [Promise.resolve( 3 ), 4], 5] );
    
    async function() {
        let values = await mySet.values();
    
        console.log(values); //[1, 2, [3, 4], 5]
    }
  5. How Vue UI works in Autox.js v7

    setup-v7

    In the Autox.js v7 second-generation API, UI construction has moved away from traditional XML and E4X. Instead, it uses a system where Vue 3 (specifically @vue/runtime-core) and htm are used as the template engine on the JavaScript side, which then renders to Jetpack Compose on the Android side.

    Key architectural points:

    • It is not a standard web Vue environment; you cannot use all Vue features or standard web UI frameworks.
    • It uses a custom renderer that maps Vue Vnodes to Jetpack Compose components.
    • The script thread is always separated from the UI thread, meaning you do not need to include 'ui'; at the top of your script as you did in the 1st generation API.
    • You can launch multiple Activities by calling startActivity with different app instances.
  6. Add custom yieldable types with .addYieldHandler()

    setup-v7

    You can extend bluebird-co to handle custom types by registering a yield handler. This allows you to yield (or await) custom objects, and the handler will resolve them into promises.

    Example: Automatically fetching data from a model instance

    import {coroutine} from 'bluebird-co';
    
    class MyModel {
        async fetch() {
            // do stuff
            return data;
        }
    }
    
    coroutine.addYieldHandler(function(value) {
        if(value instanceof MyModel) {
            return value.fetch();
        }
    });
    
    async function test() {
        let model = new MyModel();
        let data = await model; // calls model.fetch() and waits on it.
    }

    Caveats:

    • It will NOT work if the class inherits from Object or if Object is in the prototype chain for the value's constructor. If it inherits from Object, it will be treated as a standard object and processed by the default object handler.
    • Values without a constructor property are also treated as standard objects.
    import {coroutine} from 'bluebird-co';
    
    class MyModel {
        async fetch() {
            // do stuff
            return data;
        }
    }
    
    coroutine.addYieldHandler(function(value) {
        if(value instanceof MyModel) {
            return value.fetch();
        }
    });
    
    async function test() {
        let model = new MyModel();
    
        let data = await model; //calls model.fetch() and waits on it.
    }
  7. Run Debug Version via Android Studio

    setup-v7

    If you prefer using Android Studio to manage the deployment:

    1. Run the template build command in the terminal:
      ./gradlew app:buildDebugTemplateApp
    2. Click the Run button in Android Studio to deploy to your device.