Skip to content
CheshireCaat edited this page Mar 9, 2020 · 2 revisions

You can send custom messages to your script using BasRemoteClient. It's very useful if you want to perform actions like:

  • Retrieve results/logs.
  • Set/get global variables.
  • Show/hide browsers. and other different actions.

If you want to send message and perform any action on result of this message, you can use sendAsync() method. This method returns Promise object as result, so you can create any logic as you want. It also means that you can use await keyword if you want to permofm sending asynchronously without catch() and then() methods which Promise contains.

Take a look at examples.

Send message and perform action

// Set global variable with name 'TEST_VARIABLE' and value 'Hello'.
client.sendAsync('set_global_variable', {
        name: 'TEST_VARIABLE',
        value: JSON.stringify('Hello')
    })
    .then(() => {
        // Retrieve actual variable value.
        return client.sendAsync('get_global_variable', {
            name: 'TEST_VARIABLE'
        });
    })
    .then((result) => {
        // Print the value.
        console.log(result);
    });

Send message and wait for result

// Set global variable with name 'TEST_VARIABLE' and value 'Hello'.
await client.sendAsync('set_global_variable', {
    name: 'TEST_VARIABLE',
    value: JSON.stringify('Hello')
});

// Retrieve actual variable value.
const variable = await client.sendAsync('get_global_variable', {
    name: 'TEST_VARIABLE'
});

// Print the value.
console.log(variable);

Just send message

Among other options, you can just send a custom message. For example, if you want to show the database manager window, you can run the following code:

client.send('show_database_manager');

After sending this message, you will see a manager window.

Clone this wiki locally