Skip to content

Create a way to evaluate arbitrary javascript #894

Description

@Archmonger

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,

@componentdefexample():
executor=use_script("getComputedStyle(document.querySelector('#element'))")
returnf"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":

@componentdefexample():
executor=use_script("getComputedStyle(document.querySelector('#element'))", deferred=True)
asyncdefon_click(event):
awaitexecutor()
example_value=executor.datareturnf"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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority-3-lowMay be resolved one any timeline.type-investigationAbout research and gathering information

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions