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

# evaluateJs

<Tip>
  Read [the Notte skill](https://notte.cc/skill.md) and follow its setup instructions when setting up Notte or building browser automation. This is the shared source for CLI setup, authentication, and the browser-to-code workflow.
</Tip>

[Source: node-sdk/src/session.ts](https://github.com/nottelabs/notte/blob/main/node-sdk/src/session.ts)

Evaluate JavaScript on the current page and return its result as a string.

The result is stringified the way `evaluate_js` records it: objects and
arrays as JSON, a JS `null` as the string `"null"`. On failure the typed
`ActionExecutionError` is thrown with the actual JavaScript error; pass
`raiseOnFailure: false` to get the execution result envelope instead.

```typescript theme={null}
Session.evaluateJs(code: string, options?: { raiseOnFailure?: true; }): Promise<string>;
Session.evaluateJs(code: string, options: { raiseOnFailure: false; }): Promise<ApiExecutionResponse>;
```

## Parameters (overload 1)

<ParamField body="code" type={"string"} required />

<ParamField body="options" type={"{ raiseOnFailure?: true }"} />

## Returns (overload 1)

```typescript theme={null}
Promise<string>
```

## Parameters (overload 2)

<ParamField body="code" type={"string"} required />

<ParamField body="options" type={"{ raiseOnFailure: false }"} required />

## Returns (overload 2)

```typescript theme={null}
Promise<ApiExecutionResponse>
```

## Example

```typescript theme={null}
const title = await session.evaluateJs('document.title');
const payload = JSON.parse(await session.evaluateJs('(async () => JSON.stringify(await (await fetch("/api")).json()))()'));
```

## Related types

* [ApiExecutionResponse](/typescript-sdk-reference/types/apiexecutionresponse)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.