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
})
Related
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:
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.
This question already has answers here:
Open Browser Action's Popup with keyboard shortcut
(3 answers)
Closed 5 years ago.
Is it possible to specify a hotkey that will activate a Google Chrome browser action?
No, you can manipulate almost every other aspect of the browserAction and the popup (including closing it) but it cannot be triggered programatically.
#hamczu is right that the only way to bind global keyboard shortcuts is to inject a Content Script that listens for keystrokes in every page.
However you will not be able to make those keystrokes (or anything else) trigger the browserAction.
I think you should look to Vimium project source. Global hotkeys are done by binding keyboard events in content script and communicate to background page. As authors say in Wiki there is no way "to add global keyboard shortcuts (without using a content script)".
Unfortunately I have found related issue in the bugtracker and it seems there is no way to so so.
The chrome.commands api enables the user to bind hotkeys (with your suggestion for the hotkey) that will trigger commands such as opening the browser action.
Duplicate of answer.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Detect focus on browser address bar?
Simple question. My guess is that it isn't possible, but still doesn't hurt to ask:
Does anyone know if it is possible to detect the following events:
click in the URL bar
URL bar text is selected
URL bar text keypress
URL bar text copy to clipboard
None of these are possible. You can't detect events on the browser window as event handling is limited to the document.
You can somehow intercept this kind of events in Firefox, using XUL, but only in the context of an extension (maybe it's possible to do the same in Chrome too).
see:
Responding to address bar key events in Firefox Add-on
There's no way to intercept these events from the loaded page.
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
javascript detect browser close tab/close browser
Does anyone know a reliable way to listen out for a window closing event in javascript/ jQuery?
The window is the parent and not any child instances. I.e. if a window is closed by mistake and the visitor launches their browser again and loads the url previously visited once more.
You can use the window.unload event to set a cookie or use local storage to save the time using new.date(), then see if the visitor returned within a set amount of time.
Something like:
$(window).unload(function() {
localStorage.setItem(“theyLeft”, new Date());
}
then on load check for :
$(window).load(function() {
var timeGoneBy = new Date() - localStorage.getItem(“theyLeft”);
//calculate time gone by, and do something if visitor returned within given time etc.
}
Would need to be refined a lot, and local storage should have cookies as fallback, but just to show the jist of it.
Try the unload method.
The unload event is sent to the window element when the user navigates
away from the page. This could mean one of many things. The user could
have clicked on a link to leave the page, or typed in a new URL in the
address bar. The forward and back buttons will trigger the event.
Closing the browser window will cause the event to be triggered. Even
a page reload will first create an unload event.
You can also try playing with the JS onunload and onbeforeunload events.