I'm writing a Chrome extension that modifies the Gmail Compose window to add a control that allows the user to choose between sending the message using our proprietary protocol or as regular email. My question is, once the extension determines the state of the control, how does it intercept the event sent by the Send button?
The easiest way to do that with Javascript:
A quick example I tried in the console (use it when the ComposeView is open):
// find the original button
const originalSendButton = document.querySelector('.mt-send');
// clone it
const fakeSendButton = originalSendButton.cloneNode(true);
fakeSendButton.addEventListener('click', () => alert('Fake Send Button clicked'));
// show fake button
originalSendButton.parentNode.replaceChild(fakeSendButton, originalSendButton);
// show original button if needed
// fakeSendButton.parentNode.replaceChild(originalSendButton, fakeSendButton);