Hooks
Choose where your command appears
Last updated
Choose where your command appears
Last updated
By default, all commands appear at the Command Bar root. However, in some cases, you may want your command to show up in another context, e.g. when there is an active web page in focus.
Hooks let you achieve this. There is currently only one hook supported – URL Hook.
URL hook allows you to "attach" your command to the "Active Tab" group in the Command Bar. This group appears at the top of the Command Bar root when there is a browser tab in focus.
When your command is run, the page URL will be passed in the url
parameter.
A URL Hook is a JSON object with the following properties:
Property | Description |
---|---|
type | required. The type of the hook. Must be |
url |
Show the command for any URL
You can define Hooks using HTTP Headers for Cloud Commands or code comments for Local Commands. In both cases, the hooks must be string representations of the JSON object. You can define a single Hook or multiple Hooks using an array.
Your endpoint can define Hooks by sending a custom HTTP header – X-Slapdash-Hooks
. For example, in NodeJS this can look like:
Note, you also need to set Access-Control-Expose-Headers
to the list of custom hooks that you want to expose. This ensures Slapdash can access X-Slapdash-Hooks
when making a request to your endpoint.
To specify Hooks for Local Commands, you can use code comments in the following format:
The URL match pattern. Allows showing the command only when the page URL matches this pattern. For example, https://
github.com/*
matches HTTPS URLs only at "github.com", with any URL path and URL query string. Check out for more examples.