I've been using chrome.webNavigation.onCommitted
and onCompleted
listeners successfully to detect page changes, but now there are some websites that loads new pages entirely with just URL hash part changed.
And those changes don't fire these two listeners.
Is there any way to instruct chrome.webNavigation API to listen to these changes in URL as well? Or is there any other method in Chrome extension to do it?
Asked
Active
Viewed 2,832 times
2

Vuk Djapic
- 816
- 13
- 29
-
can you provide an example of just the URL hash part changing? – Noam Hacker Nov 04 '16 at 14:04
-
u doubt those cause navigation as are client only. you might need to use tabs or content script to periodically check – Zig Mandel Nov 04 '16 at 14:06
-
Some related questions have been answered by using [mutation observers](https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver) in a content script. This handles ajax requests and DOM changes – Noam Hacker Nov 04 '16 at 14:12
1 Answers
6
chrome.tabs.onUpdated - for all URL changes, needs
"permissions": ["tabs"]
in manifestchrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) { if (changeInfo.url) { console.log('Tab %d got new URL: %s', tabId, changeInfo.url); } });
chrome.webNavigation.onHistoryStateUpdated - for changes made via History API
See also: JS methods of detecting page changes available in a content script.
-
chrome.tabs.onUpdated is just what I needed. The other event is not triggered, guess the page doesn't use history api. Thanks for nicely formatted log line! – Vuk Djapic Nov 04 '16 at 14:38
-
-
Direct hash changes via assigning `location.href` won't be caught by webNavigation. – wOxxOm Nov 16 '16 at 16:35