content script/XMLHttpRequest issue

327 views
Skip to first unread message

dashman

unread,
Jan 28, 2010, 12:07:51 PM1/28/10
to Chromium-extensions
i've got a content script and i call a function in my background page
to do a XMLHttpRequest.

i don't want to return from the request until a result is received
from the remote server.

how can i stop the function from returning right away - i'll call
sendResponse from the
xml callback function.

thanks.

Adam Barth

unread,
Jan 28, 2010, 12:20:30 PM1/28/10
to dashman, Chromium-extensions
I don't think it's possible to get a synchronous response from your
background page. That would hang the renderer while we're waiting for
a response.

Adam

> --
> You received this message because you are subscribed to the Google Groups "Chromium-extensions" group.
> To post to this group, send email to chromium-...@chromium.org.
> To unsubscribe from this group, send email to chromium-extens...@chromium.org.
> For more options, visit this group at http://groups.google.com/a/chromium.org/group/chromium-extensions/?hl=en.
>
>

Brian Kennish

unread,
Jan 28, 2010, 12:54:48 PM1/28/10
to Adam Barth, dashman, Chromium-extensions
On Thu, Jan 28, 2010 at 9:20 AM, Adam Barth <aba...@chromium.org> wrote:
> I don't think it's possible to get a synchronous response from your
> background page.  That would hang the renderer while we're waiting for
> a response.

I think the poster was referring to making an XHR object within a
background page operate asynchronously, in which case, the third param
of the "open" method (the async flag) can just be set to "false".

Brian Kennish

unread,
Jan 28, 2010, 1:36:05 PM1/28/10
to Adam Barth, dashman, Chromium-extensions
On Thu, Jan 28, 2010 at 9:54 AM, Brian Kennish <bken...@chromium.org> wrote:
> I think the poster was referring to making an XHR object within a
> background page operate asynchronously, in which case, the third param
> of the "open" method (the async flag) can just be set to "false".

Oops, I meant making an XHR object operate "synchronously". That's
what the setting I gave will do.

Adam Barth

unread,
Jan 28, 2010, 1:43:11 PM1/28/10
to Brian Kennish, dashman, Chromium-extensions
On Thu, Jan 28, 2010 at 9:54 AM, Brian Kennish <bken...@chromium.org> wrote:

Ah, I misunderstood the question. Thanks!

Adam

dashman

unread,
Jan 28, 2010, 6:53:31 PM1/28/10
to Chromium-extensions

thanks - that setting fit the bill.

on a related architecture note - the fact that contents
scripts have to call background scripts for XHR, would
necessitate most to implement as synchronous.

or else a fancy double messaging system.

Adam Barth

unread,
Jan 28, 2010, 7:17:32 PM1/28/10
to dashman, Chromium-extensions
You don't have to reply to the message synchronously. You can reply
when the asynchronous XHR returns.

You can see an example of how to do this in one of my extensions:
https://chrome.google.com/extensions/detail/ahinhccldaefdhieflgmecppompikcnn

Adam

Reply all
Reply to author
Forward
0 new messages