Run Javascript

Runs Javascript in the context of the web page in the active tab of the frontmost window of the selected browser.

You can use return statements to return values.


Returns

Using a JS return statement will make the action return a value. Some simple rules apply:

  • The result will always be a list. Nested arrays will be flattened.
  • String, number, booleans, and arrays containing those types will always be returned as strings.
  • Any other types will be replaced by empty strings.

See the section Examples below.


Examples

return [true, "yes", 1, [false], {a: 1}] will yield a list with the strings:

  • "true"
  • "yes"
  • "1"
  • "false"
  • ""

For more complex data structures, you can use JSON.stringify()! Let's say you're passing an object to the function:

return JSON.stringify(myObject)

Let's further assume that myObject's structure isn't too weird, then this action's result will be a native dictionary, and you'll be able to access its keys using a native "Get Dictionary Value" action, like so:

A native Text action containing the text `return JSON.stringify({a: "hello", b: true, c: 1, d: ["yo"], e: { f: "deep down" }})`, followed by a Run Javascript action using the result of the Text action as input parameter, followed by a "Get Dictionary Value" action (get [value] for "e.f" in [result of Run Javascript]), resulting in the output "deep down", i.e. the value of the input object's nested "e.f" key.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Carlo Contact Carlo