# gf.executeScript

> Documentation index: https://frontend-tools.coherent-labs.com/llms.txt lists every page of this documentation as Markdown; the full text is in https://frontend-tools.coherent-labs.com/llms-full.txt.

Source: https://frontend-tools.coherent-labs.com/e2e/api/gf/page/executescript/

## gf.executeScript(fn: Function, args: ...any): Promise<any>

Runs a JavaScript function within the browser’s runtime context.

- **`fn`**: The function to execute in the runtime environment.
- **`args`**: Arguments to pass to the function during execution.
- Returns a promise that resolves with the function’s return value from the runtime.
- Throws an error if the function encounters an error during execution.

## Usage

```js
describe('Test script', function () {
    it('Test 1', async () => {
        // Retrieve the height of the Player's window
        const height = await gf.executeScript(() => window.innerHeight);

        // Change the background color of the body
        const color = 'red';
        await gf.executeScript((color) => {
            document.body.style.background = color;
        }, color);
    });
});
```
