This question already has answers here:
Check if page gets reloaded or refreshed in JavaScript
(14 answers)
How to check if a tab has been reloaded in background.js?
(2 answers)
Closed 4 years ago.
In chrome extension - chrome.tabs does not have any direct event to be fired when a page is refreshed on a particular tab.
We do have an onUpdated event which passes all the changes as arguments in its callback that has taken place since the last update when fired.
Is there any way of detecting through changes in the onUpdated event or in any other event to precisely detect the event of the page getting refreshed in a particular tab
Related
This question already has answers here:
Is there a way to detect if a browser window is not currently active?
(24 answers)
Closed 4 years ago.
Is there an event I can listen to when a browser tab becomes active.
By becoming active I mean all of the following things:
When user switches to the tab with my website form another tab.
When user switches back to the browser (with tab that contains my website open) from another App.
When user unminimizes the browser (with tab that contains my website open)
Basically when our tab becomes active from any other condition.
You could use the following event for this,
document.addEventListener("visibilitychange", function() {
console.log(`Your page is ${document.visibilityState}`);
});
You can check the browser compatibility of the above here.
This question already has answers here:
monitoring history.pushstate from a chrome extension
(3 answers)
How to detect page navigation on YouTube and modify its appearance seamlessly?
(2 answers)
Closed 7 years ago.
About the popstate, the documentation says this:
Note that just calling history.pushState() or history.replaceState()
won't trigger a popstate event. The popstate event is only triggered
by doing a browser action such as a click on the back button (or
calling history.back() in JavaScript).
So for example, at youtube, if you navigate to another video, the url is changed but how can i detect that change since it wasn't triggered by a browser action?
I would like to do this at the content script, but if impossible, i could do it in the background.
PS:Youtube is just the easiest example of this, so youtube specific solutions, or solutions that depend on youtube maintaining certain id's in the html are not what i'm looking for.
You can use webNavigation API and listen for onHistoryStateUpdated event in your background.
e.g:
chrome.webNavigation.onHistoryStateUpdated.addListener(function () {
// do something here
})
This question already has answers here:
Track when user hits back button on the browser
(7 answers)
Closed 9 years ago.
I want to track event which fire on, when user hits back button on the browser.
I found many post related this but all suggest use of .onbeforeunload event. but this event also fire on, when page is refresh or browser window is closed.
If there is any idea to track only browser back event.
Thanks for your help...!!!
You can use History.js:
http://balupton.github.io/history.js/demo/
History.js gracefully supports the HTML5 History/State APIs
(pushState, replaceState, onPopState) in all browsers
This question already has answers here:
Confirm message on browser page close
(2 answers)
Closed 5 years ago.
Preventing the browser to unload after clicking the close button. At the same time I want to display the popup window having "save" and "anotherFunction" buttons. Now, the popup window is displaying, but parent window is closed after clicking the "close" button in the browser. How to prevent the unloading?.
My Code:
window.onbeforeunload = function (e) {
openwindow(200, 100, 'Close.aspx');
};
onbeforeunload is a very strict event in which you cannot stop it from executing by no means. This is useful because if the developer of the site wanted to lock you in, what could you do?
If the assigned function to this event returns a non-void value, the user is shown a dialog box with the content (usually a string). If it returns a falsy value, no intervention happens.
Read your documentations, people.
https://developer.mozilla.org/en-US/docs/DOM/window.onbeforeunload
For your case, you are showing a html dialog box but since it cannot stop the page being closed it is rendering itself invalid.
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Event onBrowserClose for Google Chrome?
Is it possible to detect when the user exits the Chrome browser, so I can process some data right before they exit? I have looked into using chrome.windows.onRemoved.addListener(function(integer windowId) {...}); but it only listens for a window and not the entire browser.
Well, no.
There is no Close event, and Chrome doesn't guarantee that all others pending events will be fired before closing (will be fired at all).
I personally researched this topic while writing the "History Eliminator" extension, that would erase your browser history on close.