# Javascript Code Block

<figure><img src="/files/s9QjP43dPgD817VRZy68" alt=""><figcaption></figcaption></figure>

This block executes javascript code on the site page.

Below is a screenshot of the block settings.

<figure><img src="/files/KUnEHTDs21CSuEYb7KAT" 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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.goless.com/blocks/web-interaction/javascript-code-block.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
