I have written a Chrome Extension to Clear TYPO3 CMS Caches right out of the browser's address bar.
Now I would like to add an optional feature, to clear the caches automatically on page refresh . That means, when the user presses F5, CTRL+R, clicks the reload icon in toolbar or clicks in context menu to "Reload", first my ajax script should be executed (to clear the CMS cache) and after it, the page may get reloaded.
Is there a possibility to do it with the Chrome API?
I tried first the window.onbeforeupdate event in content script - and this is triggered always when the page is reloading, but also if I close the window or switch to another website. And furthermore I can't tell the browser to wait for my ajax request here.
What works is to check in document.onkeydown event the keys 116 (F5) and 82 (R) with control key and use event.preventDefault(). But this will not cover the two other possible cases to refresh the cache.
Thanks!
onbeforeupdateas a solution? IMHO, it does not matter that the cache will be cleared as well if the window is closed, or a user moved to another site. Also it seems you have no need to wait ajax response. Do you mean the browser don't offer you enough time even to send ajax request? Did you consider background long polling or websockets connetions as live flags for keeping cache? As soon as connection is dropped, cache can be cleared up.onbeforeupdatebut for any reasons it has not been fired, when refreshing the page. No I would have enough time to start the ajax request, but it makes no sense to reload the page and clear the cache simulatiously. The reload must happen after clearing the cache.