35.8.1 • Published 14 days ago

@automationcloud/engine v35.8.1

Weekly downloads
307
License
ISC
Repository
github
Last release
14 days ago

Automation Engine

Engine powers Automation scripts model and execution.

Quick Start Guide

This section describes the easiest way to run a script created in Autopilot using high-level abstraction called LocalRobot.

The code looks roughly as follows:

import { LocalRobot } from '@automationcloud/engine';

// Robot instance is initialized asynchronously
const robot = await Robot.create({
    script: '/path/to/my/script.json',
    chromePath: '/path/to/chromium/executable',
});

// Run the script and remember promise so we can wait till it finishes
const finish = robot.run({
    url: 'https://store-to-scrape.com',
    // other inputs ...
});

// Wait for outputs emitted by script
const [products, deliveryOptions] = await job.waitForOutputs('products', 'deliveryOptions');

// Wait until script finishes successfully
await finish;

Please refer to source docs for more info.

Embedding Engine

@automation/engine is a library which can be used as part of any Node.js application.

The application obviously needs to be architected to accomodate running the scripts. This includes not only the code setup, but also the surrounding environment (e.g. a runtime capable of running Chrome/Chromium, non-readonly filesystem, resource requests, etc).

This section describes embedding conceptually without going into too much details, which will be application-specific. For actual examples it's a good idea to look at the test setup (which mimics a minimal setup for running scripts and their parts) as well as the worker which is an example of a full-scale application.

Container setup

There are two essential components required to run an automation script:

  • Engine — an Inversify container which provides runtime services to scripts;
  • Script instance read from JSON, connected to engine.

Engine is typically configured as a singleton at application startup time.

Note: there's nothing in the code that forces the Engine being a singleton, so it's totally possible to create multiple engines and run multiple scripts in parallel. However, given the fact that scripts have an absolute control over the environment they run in (e.g. Chrome, File System, running servers on local network ports, etc) this will most likely result in script-level conflicts further down the line.

If the host application uses Inversify, it is advisable to merge the two containers so that the two can transparently access each other's components.

class App {
    container = new Container();

    constructor() {
        const engine = new Engine();
        const sharedContainer = Container.merge([this.container, engine.container]);
        engine.container = sharedContainer;
        this.container = sharedContainer;
        // Now both app and engine have shared containers, so you can bind/rebind stuff in either one
    }
}

Runtime setup

There are a couple of essential script runtime features that need to be configured using the following services:

  • FlowService defines how to obtain the inputs requested by a script and where to put the outputs emitted by a script
  • ReporterService defines how to deal with screenshots, HTML snapshots and events generated during script execution
  • ApiRequest is used to send the requests to Automation Cloud (at very least to fetch the extensions required for script execution)
  • Logger is used to log messages and can be configured to use a different logging destination and/or format.

Chrome Setup

Local setup requires Chromium executable to be available, so that the Robot can launch it with appropriate CLI flags (the most notable one is --remote-debugging-port which allows connecting to Chromium via Chrome DevTools Protocol).

Note: It is strongly recommended to avoid using your regular Chrome browser for performing automations. Doing so may cause data loss (Engine automatically cleans up browsing data to avoid polluted state) and may otherwise compromise your browsing data due to using unsafe CLI arguments. Additionally, your automation scripts will assume full control over browser lifecycle, which is simply not convenient.

Use the links from Chrome Image Repo to obtain the latest supported version of Chromium. Or, if you feel adventurous, just download a snapshot you prefer from https://commondatastorage.googleapis.com/chromium-browser-snapshots.

Running Chrome as child process

Chrome/Chromium are usually fine with being run as a child process. ChromeLauncher can be used to do that, but it's advisable to wrap it in a service.

Note: running non-headless Chrome in a container requires a graphical system setup (for example VNC).

Please refer to ChromeService from worker for an example.

Creating a script runner

A typical application will contain some kind of "Script runner" service with async run(script): Promise<void> method.

Here are a few tips for creating a decent script runner:

  • Create and use some sort of shared state service where relevant state/context can be stored and shared across components.
    • Store things like executionId or a current script in it, so that things like loggers have an easy access to it.
    • Avoid dependencies in shared state, instead have other components depend on it.
    • Make sure the state is restored and does not leak between consequtive runs.
  • Decide on when Chrome should be instantiated; it can be done either during application initialisation or immediately before running the script.
    • In either case make sure that Chrome is consistently available before running the script.
    • Chrome can crash, so if you run multiple scripts in the same runtime make sure to restart it if the engine is unable to connect.
  • Use try { prepareAndRunScript } catch (err) { handleError } finally { finalize } pattern. The handleError and finalize should never throw, so make sure to wrap those two in try/catch and log the corresponding errors. This is especially crucial for running multiple scripts in the same runtime.
  • Make sure BrowserService.connect is called before running the script.
35.8.1

14 days ago

35.8.0

15 days ago

35.7.5

3 months ago

35.3.0

10 months ago

35.4.0

9 months ago

35.5.0

7 months ago

35.6.4

7 months ago

35.6.5

7 months ago

35.6.0

7 months ago

35.6.1

7 months ago

35.6.2

7 months ago

35.6.3

7 months ago

35.7.3

6 months ago

35.7.4

6 months ago

35.7.0

7 months ago

35.7.1

7 months ago

35.7.2

7 months ago

35.2.2

10 months ago

35.2.0

1 year ago

35.2.1

1 year ago

35.0.1

1 year ago

35.1.0

1 year ago

34.38.1

1 year ago

34.38.0

1 year ago

34.38.3

1 year ago

34.38.2

1 year ago

34.38.5

1 year ago

34.38.4

1 year ago

34.38.7

1 year ago

34.38.6

1 year ago

35.0.0

1 year ago

34.36.0

2 years ago

34.37.2

2 years ago

34.37.1

2 years ago

34.37.0

2 years ago

34.34.11

2 years ago

34.34.10

2 years ago

34.33.15

2 years ago

34.34.0

2 years ago

34.34.1

2 years ago

34.34.8

2 years ago

34.34.9

2 years ago

34.35.0

2 years ago

34.35.2

2 years ago

34.35.1

2 years ago

34.33.12

2 years ago

34.33.13

2 years ago

34.33.11

2 years ago

34.33.14

2 years ago

34.33.0-4

2 years ago

34.33.0-5

2 years ago

34.33.0-2

2 years ago

34.33.0-3

2 years ago

34.33.0-0

2 years ago

34.33.0-1

2 years ago

34.33.0-6

2 years ago

34.30.0

2 years ago

34.31.0

2 years ago

34.28.0-mulo.3

2 years ago

34.28.0-mulo.2

2 years ago

34.28.0-mulo.1

2 years ago

34.27.2

2 years ago

34.27.1

2 years ago

34.32.0

2 years ago

34.32.6

2 years ago

34.32.4

2 years ago

34.32.5

2 years ago

34.32.3

2 years ago

34.28.0

2 years ago

34.33.7

2 years ago

34.33.8

2 years ago

34.33.5

2 years ago

34.33.6

2 years ago

34.33.3

2 years ago

34.33.4

2 years ago

34.33.1

2 years ago

34.33.2

2 years ago

34.33.10

2 years ago

34.33.9

2 years ago

34.29.0

2 years ago

34.29.0-mulo.2

2 years ago

34.29.0-mulo.3

2 years ago

34.29.0-mulo.0

2 years ago

34.29.0-mulo.1

2 years ago

34.29.0-mulo.4

2 years ago

34.25.4

2 years ago

34.25.5

2 years ago

34.25.3

2 years ago

34.25.6

2 years ago

34.26.0-rc1

2 years ago

34.26.0-rc2

2 years ago

34.26.0

2 years ago

34.26.0-rc3

2 years ago

34.26.0-rc4

2 years ago

34.26.0-rc5

2 years ago

34.27.0

2 years ago

34.24.0

2 years ago

34.21.0

2 years ago

34.21.1

2 years ago

34.25.1

2 years ago

34.21.2

2 years ago

34.21.3

2 years ago

34.22.0

2 years ago

0.1.0

2 years ago

34.22.3

2 years ago

34.22.1

2 years ago

34.22.2

2 years ago

34.23.0

2 years ago

34.20.5

2 years ago

34.20.6

2 years ago

34.20.4

2 years ago

34.20.1

2 years ago

34.20.2

2 years ago

34.20.0

2 years ago

34.20.3

2 years ago

34.20.0-alpha.1

2 years ago

34.19.1

2 years ago

34.19.0

3 years ago

34.18.2

3 years ago

34.18.0

3 years ago

34.18.1

3 years ago

34.17.5

3 years ago

34.17.4

3 years ago

34.17.3-ci.2

3 years ago

34.17.3

3 years ago

34.17.2

3 years ago

34.17.1

3 years ago

34.17.0

3 years ago

34.16.4

3 years ago

34.16.5

3 years ago

34.13.1

3 years ago

34.13.2

3 years ago

34.13.0

3 years ago

34.14.4

3 years ago

34.14.5

3 years ago

34.14.2

3 years ago

34.14.3

3 years ago

34.14.0

3 years ago

34.14.1

3 years ago

34.14.8

3 years ago

34.14.6

3 years ago

34.14.7

3 years ago

34.11.0

3 years ago

34.15.1

3 years ago

34.15.0

3 years ago

34.16.2

3 years ago

34.16.3

3 years ago

34.16.0

3 years ago

34.16.1

3 years ago

34.12.0

3 years ago

34.10.2

3 years ago

34.10.1

3 years ago

34.10.0

3 years ago

34.9.0

3 years ago

34.9.1

3 years ago

34.9.0-iso.2

3 years ago

34.9.0-iso.1

3 years ago

34.8.1-iso.0

3 years ago

34.8.0

3 years ago

34.7.0

3 years ago

34.7.1

3 years ago

34.6.2

3 years ago

34.6.1

3 years ago

34.6.0

3 years ago

34.5.0

3 years ago

34.4.5

3 years ago

34.4.4

3 years ago

34.4.3

3 years ago

34.4.2

3 years ago

34.4.1

3 years ago

34.4.0

3 years ago

34.3.0

3 years ago

34.2.11

3 years ago

34.2.3

3 years ago

34.2.2

3 years ago

34.2.0

3 years ago

34.2.1

3 years ago

34.1.0

3 years ago

34.1.1

3 years ago

34.1.2

3 years ago

34.0.7

3 years ago

34.0.6

3 years ago

34.0.5

3 years ago

34.0.4

3 years ago

34.0.2

3 years ago

34.0.3

3 years ago

34.0.1

3 years ago

34.0.0

3 years ago

33.10.12

3 years ago

33.10.13

3 years ago

33.10.10

3 years ago

33.10.11

3 years ago

33.10.9

3 years ago

33.10.8

3 years ago

33.10.7

3 years ago

33.10.6

3 years ago

33.10.5

3 years ago

33.10.4

3 years ago

33.10.3

3 years ago

33.10.2

3 years ago

33.10.1

3 years ago

33.10.0

3 years ago

33.9.0

3 years ago

33.8.2

3 years ago

33.8.1

3 years ago

33.7.0

3 years ago

33.8.0

3 years ago

33.6.0

3 years ago

33.5.0

3 years ago

33.4.0

3 years ago

33.3.0

3 years ago

33.2.0

3 years ago

33.1.1

3 years ago

33.1.0

3 years ago

33.0.2

3 years ago

33.0.1

3 years ago

33.0.0

3 years ago

33.0.0-alpha.3

3 years ago

33.0.0-alpha.2

3 years ago

33.0.0-alpha.1

3 years ago

33.0.0-alpha.0

3 years ago

32.22.0

3 years ago

32.21.0

3 years ago

32.20.1

3 years ago

32.20.2

3 years ago

32.20.0

3 years ago

32.19.0

3 years ago

32.18.1

3 years ago

32.18.0

3 years ago

32.16.0

3 years ago

32.17.0

3 years ago

32.15.2

3 years ago

32.15.1

3 years ago

32.15.0

3 years ago

32.14.3

4 years ago

32.14.2

4 years ago

32.14.1

4 years ago

32.14.0

4 years ago

32.13.0

4 years ago

32.12.0

4 years ago

32.11.0

4 years ago

32.10.1

4 years ago

32.10.0

4 years ago

32.9.0

4 years ago

32.8.1

4 years ago

32.8.0

4 years ago

32.7.1

4 years ago

32.7.0

4 years ago

32.6.0

4 years ago

32.5.1

4 years ago

32.5.0

4 years ago

32.4.0

4 years ago

32.3.0

4 years ago

32.2.6

4 years ago

32.2.5

4 years ago

32.2.4

4 years ago

32.2.2

4 years ago

32.2.3

4 years ago

32.2.1

4 years ago

32.2.0

4 years ago

32.1.3

4 years ago

32.1.2

4 years ago

32.1.1

4 years ago

32.0.3

4 years ago

32.1.0

4 years ago

32.0.2

4 years ago

32.0.1

4 years ago

32.0.0

4 years ago