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)
Summary
Functions
Executes JavaScript on the client by appending a script tag to the body.
Functions
@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"})