Skip to content
Browser Actions icon Home Browser Actions 2024.0.3 › Actions

Browser Actions › Actions › Run Javascript (β)

Runs Javascript in the context of the web page.

Parameters

Browser

The browser to work with.

Selecting "frontmost browser" will only work if the application currently in the foreground is a supported browser.

Only available if Target tab isn’t set to "specific tab".

Type: Browser

Target tab

Specify which tab you want to work with. The option "active tab of frontmost window" will target the currently active tab at the time this action is executed, while "specific tab" will let you target an existing browser tab.

Options:

  • active tab of frontmost window
  • specific tab

Specific browser tab

If Target tab is set to "specific tab", this parameter expects a browser tab reference.

Type: Browser Tab

Javascript

Pass in a block of JS which will be executed in the context of the target tab. If you want to return anything back to Shortcuts, use a return statement with a simple value (text, number, string, boolean). You can also return an array of simple values (e.g., return ["my", 123, true]), which will turn the action's result into a list of texts.

To return more complex values, it's recommended to pass them as a JSON string, e.g., return JSON.stringify({ a: "my", b: 123, c: true }). The action's result will be a single string, which can then be decoded by any Shortcuts JSON-related action.

If the JS code contains syntax errors, an error will be raised. If the syntax is sound but it causes a runtime error, the error message will be returned as string.

Type: Text

Return Value

Text (list)