saturngod
saturngod

Reputation: 24949

Chrome extensions : How to know when a tab has ajax call finished

Now, I'm writing

function tabStatusOnChange(tabId, changeInfo)
  {
    if(changeInfo.status == "complete")
        chrome.tabs.executeScript(null, {file:"oneuniverse.js"});
  }
  chrome.tabs.onUpdated.addListener(tabStatusOnChange);

But it's not working for ajax page and gmail , too. How to write for ajax status complete

Upvotes: 1

Views: 1621

Answers (2)

Dominic Mitchell
Dominic Mitchell

Reputation: 12299

You can't override like that in a chrome extension as the extension operates in a different JavaScript context to the page. The only point of interoperability is the DOM. So you would need to look for a DOM event that is fired when the request completes. But I don't think that there is one.

Upvotes: 0

Mohamed Mansour
Mohamed Mansour

Reputation: 40169

You cannot use chrome.tabs.onUpdated for XHR because it only get fires when a tab is updated. When you send an XHR request, the tab is not updated (that is the whole point of "AJAX")

The only way to know if the AJAX call finished, is by overriding it. You can override the AJAX request (which uses XmlHTTPRequest), something like this:

var origXHR= window.XMLHttpRequest;
window.XMLHttpRequest = customImplementation;

An XMLHttpRequest could be Synchronous or Asynchronous, so you have to take into consideration both. When I meant customImplementation, it means you will use the same implementation but you will add hooks in some places (such as an Adapter Pattern).

Upvotes: 1

Related Questions