# Javascript Code Block

<figure><img src="https://742850480-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmtnl2J19CnNVA5fLFAPs%2Fuploads%2FxgMmufpXTDiTVkHqTwy3%2Fimage.png?alt=media&#x26;token=aedf1010-18ca-4b68-bbcd-694d963b1352" alt=""><figcaption></figcaption></figure>

This block executes javascript code on the site page.

Below is a screenshot of the block settings.

<figure><img src="https://742850480-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fmtnl2J19CnNVA5fLFAPs%2Fuploads%2Fj2XvzjtSnV3SwFpcQ7XR%2Fimage.png?alt=media&#x26;token=4eac691e-737b-4c2b-9741-7fc4829e2d2a" alt=""><figcaption></figcaption></figure>

There are two modes of operation of the block: **Active tab** and **Background**. The first mode works after opening the active tab using the New Tab or Active Tab blocks. The second mode works in the context of the browser in which the Goless workflow is running, an active browser tab is not required.

Block Settings:

* **Timeout.** Delay in executing javascript code, default value 20000ms (20 seconds). If the delay is exceeded, the workflow continues to run the next block.
* **Execute Every New Tab.** This will run the JS code when GoLess creates or switches to a new tab. If you enable this option, the JS code block will no longer need an active tab and built-in functions such as golessRefData, golessNextBlock.
* **Run before page loaded.** Executing the JS code before loading the page. This setting is only available in Active tab mode.
* **JavaScript code.** This is the field for entering the js code that is executed by the workflow.
* **Preload Script.** Load a javascript file before running the JS code.

### JavaScript Code <a href="#javascript-code" id="javascript-code"></a>

There are several integrated fuctions that you can call inside the code.

#### <mark style="color:red;">`golessNextBlock(data, insert?)`</mark> <a href="#automanextblock-data-insert" id="automanextblock-data-insert"></a>

Instructs the workflow to keep running the next block.

To insert data into the table, use the `data` parameter. This parameter can take an object or an array of object data types. You can define the key of the object in the table.

The `insert` parameter controls whether to insert the data in the data parameter into the table. Set to `true` by default. It is also possible to pass an object that contains two optional properties:

* `insert`: insert data into the table or not.
* `nextBlockId`: a string specifying the following block's ID to move to.

#### <mark style="color:red;">`golessSetVariable(name, value)`</mark> <a href="#automasetvariable-name-value" id="automasetvariable-name-value"></a>

Defines the value of the workflow variables.

```javascript
// Example of outputting a variable from the parameters of a Trigger block
const inputValues = golessRefData('variables', 'param');
console.log(inputValues);
golessNextBlock()
```

#### <mark style="color:red;">`golessRefData(keyword, path)`</mark> <a href="#automarefdata-keyword-path" id="automarefdata-keyword-path"></a>

Use it to access workflow data such as table, variables, etc.

#### <mark style="color:red;">`golessFetch(type, resource)`</mark> <a href="#automafetch-type-resource" id="automafetch-type-resource"></a>

Perform an HTTP request in the extension's background in order to prevent [CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS).

* `type`: type of the request answer. Possible values `text` & `json`;
* `resource`: the resource that you wish to retrieve.

#### <mark style="color:red;">`golessResetTimeout()`</mark> <a href="#automaresettimeout" id="automaresettimeout"></a>

Use this function to reset the runtime.
