> ## Documentation Index
> Fetch the complete documentation index at: https://docs.extractbase.com/llms.txt
> Use this file to discover all available pages before exploring further.

# evaluate

Executes a JavaScript function or predicate within the page's context and returns the result.
The function receives 'arg' as its first argument.
Example: `evaluate(functionOrPredicate: "() => document.title")`
Example with argument: `evaluate(functionOrPredicate: "selector => document.querySelector(selector).innerText", arg: "#myElement")`
Returns the JSON representation of the function's return value.

## Definition

```graphql theme={null}
evaluate(
  functionOrPredicate: String!
  arg: JSON
): JSON!
```

## Arguments

### `functionOrPredicate`

[String!](/reference/graphql/scalars/string)

A string containing the JavaScript function or predicate to execute.
Example: `"() => ({ width: window.innerWidth, height: window.innerHeight })"`
Example: `"element => element.tagName"` (if an element is the context)

### `arg`

[JSON](/reference/graphql/scalars/json)

An optional JSON serializable argument to pass to the function.

## Returns

[JSON!](/reference/graphql/scalars/json)

The `JSON` scalar type represents JSON values as specified by [ECMA-404](http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf).
