WLJS LogoWLJS Notebook

FrontFetchAsync

Wolfram Kernel

asynchronously evaluates (aka FrontSubmit) and fetches the resulting expression back to the Wolfram Kernel from the frontend (browser)

FrontFetchAsync[expr_, opts___] 

and returns Promise object.

Options

"Window"

specifies a window object, on which an expression will be evaluated. Use CurrentWindow to fetch a window object from the evaluation context explicitly.

"Format"

The default expression form used to import raw data acquired from the frontend. It effectively applies ImportString on raw JSON data. The possible values

  • "RawJSON" (the default)
  • "JSON"
  • "ExpressionJSON"
  • "Raw" bypasses parser and returns a string

Usage with FrontInstanceReference

Using an extension FrontInstanceReference, one can execute an expression in the context of instance of a specified frontend symbol and fetch the result back

FrontFetchAsync[expr_, m_FrontInstanceReference, opts___] _Promise

See examples on FrontSubmit

Examples

To read the selected text from a cell and print it to another cell. Here we use FrontEditorSelected which is a frontend-only symbol:

With[{notebook = EvaluationNotebook[]},
  EventHandler[InputButton["Read selected text"], Function[Null, 
    
      Then[FrontFetchAsync[FrontEditorSelected["Get"]], Function[result,
        NotebookWrite[notebook, Cell[result, "Input"]]
      ]
    ]
  ]]
]

or to read a clipboard

With[{notebook = EvaluationNotebook[]},
  EventHandler[InputButton["Read clipboard"], Function[Null, 
    
      Then[FrontFetchAsync[ReadClipboard[]], Function[result,
        NotebookWrite[notebook, Cell[result, "Input"]]
      ]
    ]
  ]]
]

On this page