Create a way to evaluate arbitrary javascript
Author: ArchmongerCreated Jan 29, 2023Updated Feb 22, 2026
Labelspriority-3-lowtype-investigation
Current Situation
Currently, there is no method to transmit the results of a JavaScript function to the backend.
Proposed Actions
This might look like a use_script hook that operates similarly to html.script, but can return a result.
For example,
@component
def example():
executor = use_script("getComputedStyle(document.querySelector('#element'))")
return f"CSS Style Attributes: {executor.data}"Since this hook would need to operate asynchronously, the interface would likely be heavily inspired by our Django use_query hook.
And perhaps it could be used as an executor within event contexts to be more "reactive":
@component
def example():
executor = use_script("getComputedStyle(document.querySelector('#element'))", deferred=True)
async def on_click(event):
await executor()
example_value = executor.data
return f"CSS Style Attributes: {script.data}"See this comment for traceability.
Note: If possible, we should try pre-populate this keyword with something that makes sense, depending on where the JavaScript was executed.
Source: reactive-python/reactpy