# `PhoenixDatastar.Scripts`
[🔗](https://github.com/RicoTrevisan/phoenix_datastar/blob/v0.2.0/lib/scripts.ex#L1)

Executes JavaScript on the client via SSE.

Appends a `<script>` tag to the body using `datastar-patch-elements`.

    sse |> execute("alert('Hello!')")
    sse |> execute("console.log('debug')", auto_remove: false)

# `execute`

```elixir
@spec execute(PhoenixDatastar.SSE.t(), String.t(), keyword()) ::
  PhoenixDatastar.SSE.t()
```

Executes JavaScript on the client by appending a script tag to the body.

## Options

- `:auto_remove` - Remove script tag after execution (default: true)
- `:attributes` - Map of additional script tag attributes
- `:event_id` - Event ID for client tracking
- `:retry` - Retry duration in milliseconds

## Examples

    # Simple script execution
    sse |> execute("alert('Hello!')")

    # Keep script in DOM
    sse |> execute("window.myVar = 42", auto_remove: false)

    # ES module script
    sse |> execute("import {...} from 'module'", attributes: %{type: "module"})

---

*Consult [api-reference.md](api-reference.md) for complete listing*
