Chrome extension message passing, when xhr call fails in jQuery -


i'm building extension in google chrome issues queries against websites.

the queries issued "background page" on request "content script"; when background page receives request issue query, sends query out, parses response , sends response content script, using sendresponse().

it works fine when using xmlhttprequest(); problem if want issue queries using jquery .get() or .load(), when queries fail, fail silently , response never sent content script.

if register event handler .ajaxerror() error catched, event handler apparently cannot call sendresponse() because following chrome error:

"attempting use disconnected port object"

searching error retrieves source code chrome text found, it's not helpful.

in short, question is: possible use jquery.get() in background script of chrome extension, , still able send response content script when request fails? (and if yes, how)

this hard address directly without code sample (how passing sendresponse error handler?), think there alternatives building xhr yourself.

  • respond asynchronously: send empty response content script , later initiate new connection content script send response. content script need add listener messages. if you're making multiple of these requests you'll want token passed , forth can match responses original requests.
  • use $.ajax(): allows specify both success , error callback inline; if can sendresponse success callback, should able error callback.
  • create long-living port: long-living connections let post message content script @ time.

i'd think call sendresponse separate function if stored sendresponse function accessible error handler, maybe you've proven false (would love have seen code). documentation makes sound request open until it's responded to.


Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -