Event fire on update with XMLHttpRequest in a htlm-page

Hi,

my problem:

I need a event that works in a contenscript (loadet by manifest) and is firing by loaded complet html-pages. After loadet ther is somthing to do in the page.

onActivated and onUpdate works but I think it dont work by XMLHttpRequest in Page.

I try many thinks, but with no result.

So this follow not work in contenscript:

document.addEventListener(“DOMContentLoaded”, function(event) {
console.log(“5. DOM fully loaded and parsed”);
});
window.addEventListener(“loadend”, loadEnd);

  document.addEventListener('DOMContentLoaded', handler);
  
  document.addEventListener('load', function( ) {
      console.info('4. Document has finished loading');
  });

Thanks

That’s likely due to the default value of run_at: https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/manifest.json/content_scripts#run_at

Thank you, but the default value is "document_idle". Is Ok. But the problem is:

Cs run at the first call of a page. Thats good.

On the page, in second step, I make a search on page and the content is loading new (httpXMLRequest I think) but the cs is not running again.

XHR does not trigger a content script. It loads a file and fires events on its instance. After that the raw file is available to you. The HTML is not parsed into DOM and no JS is ran on it. Only tabs and iframes run pages and trigger content scripts.

Thank you,

thats verry bad. You have a trick for another way (background or?)

Really depends on what exactly you’re trying to achieve.

I want in every times a page changed with my extension content highlighting something in the new content. In all other cases (onActiveded, onUpdate pages) it work

If you don’t have any better event like the page pushing a new URL or similar, you can always fall back to using a mutation observer, checking for changes in the DOM.

checking for changes in the DOM. Its not working on cs. I don’t know why.

window.addEventListener(“click”, ()=>{console.log(“click”);}); run, but not helpfull
all other are not running:
window.addEventListener(“DOMContentLoaded”, function(event) { });
window.addEventListener(“loadend”, loadEnd);
window.addEventListener(‘DOMContentLoaded’, handler);

  window.addEventListener('load', function( ) {
      console.info('4. Document has finished loading');
  });