javascript - Chrome Extension: Show loader between page changes -


i'm developing chrome extension specific web page hides elements of page avoid using functions of , put in kiosk, simple no?.

the thing is, page not "fast enough" when extension work (on document ready) there's seconds showing webpage.

i'm trying show loader when page still loading , when user click on of allowed links no success.

the thing i'm trying is:

catch before request event , inject loader:

chrome.webrequest.onbeforerequest.addlistener(     function (details) {         chrome.tabs.query({ active: true, currentwindow: true }, function (tabs) {             var activetab = tabs[0];             chrome.tabs.executescript(activetab.id, {                 file: 'injectloader.js',                 runat: 'document_start'             }, function(){              });         });     }, { urls: ["*://*/*url*"] } ); 

the injectloader.js like:

var div = document.createelement('div'); div.id = 'sstechloader'; div.innerhtml = '<h1>cargando</h1>'; document.body.appendchild(div) 

then try delete loader div in completed event:

chrome.webrequest.oncompleted.addlistener(     function (details) {         chrome.tabs.query({ active: true, currentwindow: true }, function (tabs) {             var activetab = tabs[0];             chrome.tabs.executescript(activetab.id, {                 code: "settimeout(function(){document.queryselector('#sstechloader').remove()},1000);",                 runat: 'document_end'             }, function(){             });         });     }, { urls: ["*://*/*url*"] } ); 

(i added timeout in case)

the thing is, it's not working, loader appears site can saw seconds. , loader never disappear don't know why oncompleted never called.

there's other way accomplish i'm trying do?

updated

i added relevant code in request of @woxxom , @sam

update solution

after @makyen suggestion found solution putting put loader logic in chrome.webnavigation.oncommitted:

chrome.webnavigation.oncommitted.addlistener(function(details){     chrome.tabs.executescript(details.tabid, {         file: 'injectloader.js',         runat: 'document_start'     }, function(){     }); }); 

thanks lot guys !.


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -