Script
Manage Scripts

Manage Scripts

Similar to remote proxy providers and rule providers, you need script-providers to manage scripts. After declaring a script, you can use it in rewrites, panels, and scheduled tasks.

The simplest example:

script-providers:
  your-fancy-script:
    url: https://your-fancy-script.com/your-fancy-script.js
    interval: 86400

Stash periodically downloads the script from the specified URL (based on interval) and caches it on disk. During downloads, Stash honors Etag and Last-Modified headers to avoid unnecessary updates.


💡
Available only in Stash 3.2.5 and later.

For temporary debugging and testing, you can use the payload field to embed a script directly in the configuration file. For example:

script-providers:
  your-fancy-script:
    interval: 86400
    payload: |
      console.log("This is a test script");
      $done();

When both url and payload are present, Stash writes the payload content to the local cache at startup and then attempts to download the script from url to overwrite the cache during subsequent updates.

⚠️

Using payload for complex scripts is not recommended because it significantly slows down config parsing.

To make local cache management easier, you can use the path field to specify the cache location. For example:

script-providers:
  your-fancy-script:
    url: https://your-fancy-script.com/your-fancy-script.js
    path: ./fancy/script.js
    interval: 86400
    payload: |
      console.log("This is a test script");
      $done();

On startup, Stash checks whether ./fancy/script.js exists. If it does, Stash uses that file as the script; otherwise it writes the payload content. During subsequent updates, Stash downloads the script from url to overwrite the local cache.

⚠️

To avoid path traversal, Stash limits path to the directory containing the configuration file and its subdirectories.


You can declare a script-providers entry with only path and no url to disable scheduled updates. For example:

script-providers:
  local-debug-script:
    path: ./fancy/script.js

With iCloud enabled, you can edit the script on Mac and let iCloud sync it to iPhone. Once synced, the script takes effect immediately, which is very efficient for local debugging.