Thanks - I decided to move all the logic into an automation, so the script is now pretty simple and only triggers a webhook if I’m holding down the alt/option key.
document.onkeydown = function (evt) {
evt = evt || window.event;
if (evt.altKey) {
const xhr = new XMLHttpRequest();
xhr.open("POST", '/api/webhook/INSERT_YOUR_ID', true);
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.send(JSON.stringify({ "key": evt.key }));
}
};