1

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

saturngod
  • 24,649
  • 17
  • 62
  • 87

2 Answers2

1

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).

Mohamed Mansour
  • 39,445
  • 10
  • 116
  • 90
0

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.

Dominic Mitchell
  • 11,861
  • 4
  • 29
  • 30