Appearance
Javascript Code Block
Execute your javascript code on the website.
Timeout
Javascript code execution timeout, default to 20000ms (20 seconds). If it reaches the timeout, the routine will continue to execute the next block.
Execute Every New Tab
This will execute the javascript code every time Brainwrite Swift creates a new tab or switches a tab. When this option is enabled, the javascript code block no longer requires an active tab to work and built-in functions like bwswiftRefData
, bwswiftNextBlock
, etc; will not be available. For example
Execution Context
Refer to: Javascript Execution Context
JavaScript Code
There're several built-in functions that you can call within the code.
bwswiftNextBlock(data, insert?)
ts
bwswiftNextBlock(
data?: Object | Object[],
insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;
bwswiftNextBlock(
data?: Object | Object[],
insert?: boolean | { insert?: boolean; nextBlockId?: string; replaceTable?: boolean }
): void;
To tell the routine to continue to execute the next block.
Use the data
parameter to insert data into the table. This parameter can take an object or an array of objects data types. And the key of the object must be defined in the table.
The insert
parameter is used to control whether to insert the data in the data
parameter into the table, defaults to true
. Alternatively, you can pass an object that contains two optional properties:
insert
: whether insert data into the table.nextBlockId
: a string that specifies the ID of the next block to navigate to.replaceTable
: replace the routine table values with those passed on the first parameter.
Examples
js
bwswiftNextBlock({ title: 'Something', count: 200 });
//or
bwswiftNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])
// Continue execution to a specific block
bwswiftNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })
bwswiftNextBlock({ title: 'Something', count: 200 });
//or
bwswiftNextBlock([{ title: 'Foo', count: 300 }, { title: 'Bar', count: 200 }])
// Continue execution to a specific block
bwswiftNextBlock({ title: 'Hello' }, { nextBlockId: '4dxcxa3' })
bwswiftSetVariable(name, value)
Set the value of the routine variables.
Examples
js
bwswiftSetVariable('name', 'John Doe');
bwswiftSetVariable('prices', [200, 1000, 4000, 900, 200]);
bwswiftSetVariable('profile', { firstName: 'John', lastName: 'Doe' });
bwswiftSetVariable('name', 'John Doe');
bwswiftSetVariable('prices', [200, 1000, 4000, 900, 200]);
bwswiftSetVariable('profile', { firstName: 'John', lastName: 'Doe' });
bwswiftRefData(keyword, path)
Use this function to access routine data like the table, variables, etc.
Read more: Expressions
Examples
js
// Get the first row of the table
const firstRow = bwswiftRefData('table', '0');
// Get the last row of the table
const firstRow = bwswiftRefData('table', '$last');
// Get the "name" column on the first row of the table
const firstRow = bwswiftRefData('table', '0.name');
// Get the global data of the routine
const globalData = bwswiftRefData('globalData');
// Get the iteration data of the loop data block
const data = bwswiftRefData('loopData', 'loopId');
// Get the value of the "text" variable
const value = bwswiftRefData('variables', 'text');
// Get the first row of the table
const firstRow = bwswiftRefData('table', '0');
// Get the last row of the table
const firstRow = bwswiftRefData('table', '$last');
// Get the "name" column on the first row of the table
const firstRow = bwswiftRefData('table', '0.name');
// Get the global data of the routine
const globalData = bwswiftRefData('globalData');
// Get the iteration data of the loop data block
const data = bwswiftRefData('loopData', 'loopId');
// Get the value of the "text" variable
const value = bwswiftRefData('variables', 'text');
bwswiftFetch(type, resource)
Make an HTTP Request in the extension background, using it to avoid CORS.
type
: Response type of the request. Possible valuestext
&json
;resource
: The resource that you wish to fetch
Examples
js
bwswiftFetch('json', { url: 'https://api.example.com'}).then((result) => {
console.log(result);
})
bwswiftFetch('json', {
url: 'https://api.example.com',
method: 'POST',
body: JSON.stringify({
title: 'Hello world',
}),
})
bwswiftFetch('json', { url: 'https://api.example.com'}).then((result) => {
console.log(result);
})
bwswiftFetch('json', {
url: 'https://api.example.com',
method: 'POST',
body: JSON.stringify({
title: 'Hello world',
}),
})
bwswiftResetTimeout()
Reset the execution timeout.
Preload Script
Load a javascript file before executing the javascript code.
- URL
URL of the javascript file.