I am working on a Chrome extension, I want to detect when the user has typed a URL. I know about:
chrome.tabs.onUpdated.addListener(eventLisenerObj.onUpdated);
But, it gets called whenever the URL is changed (e.g. when the page is auto reloads, or user clicks on a link, etc.)
I desire to be able to determine that the URL was changed only by the user typing a URL.
You can have a look at
$locationChangeSuccess
.You can get the path like this:
Then on change of
loc
you can attach your function.You can get this information using the
webNavigation.onCommitted
(MDN) event. The event listener receives a propertytransitionType
(MDN), which will be different values(MDN) based on the cause of the navigation. Which values you trigger on will depend on exactly what you are desiring. For what you describe, you will probably want'typed'
(MDN), but potentially also'generated'
(MDN),'keyword'
(MDN) and/or'keyword_generated'
(MDN).The list of possible values is explained on Chrome's History API page (they are listed on the Chrome
webNavigation
page, but not explained there) (On MDN:TransitionType
) (text from the Chrome History API page):To differentiate some types of transitions, in addition to the
transitionType
values, you will also want to look at theTransitionQualifier
(MDN). The possible values are (from the Chrome documentation, which are described somewhat differently on MDN):