# Can I call a JavaScript function or extract a value from the page?

> Loadster's Evaluate Blocks can run custom JavaScript inside the bot's browser. Here's how to evaluate a simple value or promise.

Source: https://loadster.com/faqs/evaluating-a-value-or-promise-inside-the-browser/

Sure thing! You can supply your Browser Bots with custom JavaScript code to run *inside* the browser. Your custom
JavaScript can call functions, compute values, grab properties from the page or browser window, manipulate DOM elements,
and even perform asynchronous programming and return a promise.

The way to do this is with [Evaluate Blocks](https://loadster.com/manual/browser-scripts/evaluate-blocks/).

Evaluate Blocks, or eval blocks, are similar to [Code Blocks](https://loadster.com/manual/code-blocks/) except that they run
*inside* the browser, while code blocks control your script's from execution outside the browser. Because eval blocks
run inside the browser, they have access to the DOM and to variables and functions within the page itself.

## Using JavaScript to call a function or extract a value

You can use an eval block to [extract a value](https://loadster.com/manual/browser-scripts/evaluate-blocks/#extracting-a-simple-value) from
the page, which is mostly useful when you are debugging your script. You can also
[call a function on the page](https://loadster.com/manual/browser-scripts/evaluate-blocks/#calling-a-function-on-the-page), which might
be necessary if you need to imitate drag-and-drop or something like that that is difficult to do with ordinary browser
automation.

## Using JavaScript to manipulate DOM elements

Once in a while, you might need to test a web application with an element that isn't easily manipulated with normal
Browser Bot steps, so you'll need to execute JavaScript in the bot's browser window to do it. Examples of when this
might be necessary are for [range sliders or color pickers](https://loadster.com/faqs/manipulating-range-sliders-and-other-unusual-inputs/).

## Using JavaScript for custom validation

One use for eval blocks is to write custom validation, throwing an error if expected content on the page isn't found.

```javascript
var welcomeMessage = document.querySelector('.welcome-message');

if (!welcomeMessage) {
    throw new Error("No welcome message found after logging in!");
}
```


Learn more and check out the examples in [Evaluate Blocks](https://loadster.com/manual/browser-scripts/evaluate-blocks/).

