Synchronous mode in XMLHTTPRequest in Chrome extension

1,692 views
Skip to first unread message

Milind T

unread,
Jun 19, 2014, 12:46:24 AM6/19/14
to chromium-...@chromium.org

As per the link below, synchronous mode for XHR is being deprecated in Firefox.https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Here is what document says:

Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.

I wanted to know if Chrome is going to follow this? Would it be safe to use synchronous XMLHTTPReuquest in Chrome extension? (For business reason, it needs to synchronous in my case)

Marc Fawzi

unread,
Jun 19, 2014, 1:03:35 AM6/19/14
to Milind T, chromium-...@chromium.org
Why can't you wait for the success callback and call whatever code that needs to execute after from there?


--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/ca7d3728-de2e-4a29-9e6b-596ba7f467c1%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

Message has been deleted

Milind T

unread,
Jun 19, 2014, 1:48:14 PM6/19/14
to chromium-...@chromium.org, mili...@gmail.com
I am looking forward to use synchronous XHR in Webrequest.beforeWebRequest callback. I have business logic that requires XHR response before current WebRequest could be allowed or cancelled. I can't really use success callback for this purpose. 


On Thursday, June 19, 2014 10:33:35 AM UTC+5:30, Marc Fawzi wrote:
Why can't you wait for the success callback and call whatever code that needs to execute after from there?
On Wed, Jun 18, 2014 at 9:46 PM, Milind T <mili...@gmail.com> wrote:

As per the link below, synchronous mode for XHR is being deprecated in Firefox.https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Here is what document says:

Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.

I wanted to know if Chrome is going to follow this? Would it be safe to use synchronous XMLHTTPReuquest in Chrome extension? (For business reason, it needs to synchronous in my case)

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

Marc Fawzi

unread,
Jun 19, 2014, 2:13:48 PM6/19/14
to Milind T, chromium-...@chromium.org, mili...@gmail.com
Sorry I don't follow why you couldn't 

Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Milind T

unread,
Jun 19, 2014, 3:18:10 PM6/19/14
to chromium-...@chromium.org, mili...@gmail.com
Sure. Let me try to clarify a bit. 
  • I am using webRequest in blocking mode with "webRequestBlocking" permission
  • Want to handle the event "onBeforeRequest" hence I have registered an event handler 
  • In this event handler, I use synchronous  XHR to contact a web service and based on the XHR response I need to return webRequest.BlockingResponse from the event handler. It could be cancel or allow. (This is business logic) To be able to cancel the Web request, I need to get synchronous response from XHR. Once I return from the event handler, I won;t get chance to cancel this request again.
  • If I use XHR success callback, it become asynchronous. I am not aware of any way to wait within onBeforeRequest event handler for the response and then cancel the WebRequest. 


On Thursday, June 19, 2014 11:43:48 PM UTC+5:30, Marc Fawzi wrote:
Sorry I don't follow why you couldn't 

Sent from my iPhone

On Jun 19, 2014, at 10:48 AM, Milind T <mili...@gmail.com> wrote:

I am looking forward to use synchronous XHR in Webrequest.beforeWebRequest callback. I have business logic that requires XHR response before current WebRequest could be allowed or cancelled. I can't really use success callback for this purpose. 

On Thursday, June 19, 2014 10:33:35 AM UTC+5:30, Marc Fawzi wrote:
Why can't you wait for the success callback and call whatever code that needs to execute after from there?


On Wed, Jun 18, 2014 at 9:46 PM, Milind T <mili...@gmail.com> wrote:

As per the link below, synchronous mode for XHR is being deprecated in Firefox.https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest

Here is what document says:

Starting with Gecko 30.0 (Firefox 30.0 / Thunderbird 30.0 / SeaMonkey 2.27), synchronous requests on the main thread have been deprecated due to the negative effects to the user experience.

I wanted to know if Chrome is going to follow this? Would it be safe to use synchronous XMLHTTPReuquest in Chrome extension? (For business reason, it needs to synchronous in my case)

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/ca7d3728-de2e-4a29-9e6b-596ba7f467c1%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.

--
You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

Marc Fawzi

unread,
Jun 19, 2014, 9:18:31 PM6/19/14
to Milind T, chromium-...@chromium.org, mili...@gmail.com
let's start with the naive assumption that you can decompose your logic as follows

1. Send an asynchronous XHR request to find out whether you should send the webRequest or not

2. In the success callback decide based on result if you want to send the webRequest or not

Why couldn't that work for you?

I'm curious


Sent from my iPhone
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.

To post to this group, send email to chromium-...@chromium.org.
Visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/.

jack

unread,
Dec 28, 2015, 10:52:52 AM12/28/15
to Chromium-Extensions-Announce, mili...@gmail.com, marc....@gmail.com
I totally understand what Milind T wants to say... ;)  

Btw, @Milind T: don't you see some errors when you make synchronous requests? I need to do exactly the same as you but in case of some redirects. For example, in case of visiting timesofindia.com, i see "NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'http://timesofindia.com/'."

Btw, just out of curiosity, can we also use fetch api synchronously?

merijn....@gmail.com

unread,
Oct 19, 2017, 7:20:22 AM10/19/17
to Chromium-Extensions-Announce
Hi All,
It's an old thread. But did any of you find a satisfactory solution to the problem? I.e., to perform a XHR request inside an onBeforeRequest handler in order to decide whether to continue or block the web request. Since the onBeforeRequest doesn't support asynchronous calls at all, the XHR request must be synchronous. BTW, i the implementation of FireFox onBeforeRequest, does support asynchronous calls (https://developer.mozilla.org/en-US/Add-ons/WebExtensions/API/webRequest/onBeforeRequest). onBeforeRequest can return a promise. Perhaps something to consider for chrome as well, since so many methods are asynchronous. 

Thanks for your help.

PhistucK

unread,
Oct 19, 2017, 7:54:26 AM10/19/17
to merijn....@gmail.com, Chromium-Extensions-Announce
Sounds like a reasonable feature request to me, perhaps file it at crbug.com if you cannot find something similar.


PhistucK

--
You received this message because you are subscribed to the Google Groups "Chromium-Extensions-Announce" group.

To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extensions+unsub...@chromium.org.

merijn....@gmail.com

unread,
Oct 19, 2017, 9:46:08 AM10/19/17
to Chromium-Extensions-Announce, merijn....@gmail.com
Reply all
Reply to author
Forward
0 new messages