question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Cancel request before it is sent

See original GitHub issue

Is it possible to cancel an action before the corresponding HTTP request is sent?

From the readme, here’s what we have to work with before a message is sent.

gmail.observe.before('send_message', function(url, body, data, xhr){ }

I was thinking it might be possible to cancel the xhr request, but it hasn’t even been sent yet.

The use case it to perform a check and prompt the user for confirmation if certain conditions are met.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:13

github_iconTop GitHub Comments

1reaction
Nateowamicommented, Feb 22, 2017

Thanks for the suggestions. I considered hooking into the click event, but I didn’t know how to get the list of email addresses from the To, CC, and BCC fields. Looking at the API a bit more though, I now see there’s a recipient_change event that does just that.

I’m a bit confused about the documentation though:

gmail.observe.on('recipient_change', function(match, recipients) {
  console.log('recipients changed', match, recipients);
});

I’m not sure what “match” refers to. From experimenting in the console it appears to be a large DOM element holding everything but the header in the compose dialog. I’m guessing this is in order to find this element in the DOM tree in order to track down which compose dialog it came from?

Actually, with this event handler, maybe I don’t even need to intercept a click–just change some styling or something as a warning.

Anyway, thanks so much for the help! Much appreciated. 😄

1reaction
Nateowamicommented, Jan 31, 2017

Thanks. I may investigate that route. I also just discovered the abort() method on the xhr object. Just experimenting in the console it appeared aborting it before it was sent would keep it from being sent at all (as long as it was open()ed before being abort()ed). It’s looking promising

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I cancel a friend request I sent to someone ... - Facebook
To cancel a friend request you sent: 1. Go to your Sent Friend Requests. 2. Tap Cancel next to a friend request to...
Read more >
I made a Facebook friend request. First it said cancel ... - Quora
“cancel request” it means you can cancel your friend request, “request” means your requested person has denied your request now you can send...
Read more >
How to Cancel a Request in JavaScript - Level Up Coding
The XMLHttpRequest.abort() method aborts the request if it has already been sent. When a request is aborted, its readyState is changed to XMLHttpRequest....
Read more >
Automatically Canceling Previous Requests in JavaScript
This way, each request will be automatically canceled when a new one of the same type is made. This is what happens in...
Read more >
How to Cancel Sent Friend Requests on Facebook - YouTube
When you send a Friend Request on Facebook, you need to wait for the other person to accept it until you can view...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found