Trying to detect Top Url in chrome.webNavigation.onBeforeNavigate

1,083 views
Skip to first unread message

Eli Tchernitski

unread,
Jun 10, 2013, 9:55:33 AM6/10/13
to chromium-...@chromium.org
Hi,

I created extension that uses webNavigation.onBeforeNavigate
currently I just use alert for testing.
The problem is that it fires many times for each page and I need only  top url.

How to detect it ?

(for ex. in C++ API for IExplore there is get_TopLevelContainer for IWebBrowser2)

chrome.webNavigation.onBeforeNavigate.addListener(
  function (object) {
      if ( object.url.indexOf("http") > -1)
      {
          //if (  topUrl ) /  
 alert('object.url - '+object.url);

     }
  });
May be anybody can help ?

Simon Knott

unread,
Jun 10, 2013, 11:08:54 AM6/10/13
to chromium-...@chromium.org
The object which has the URL property, also has a frame ID (see documentation at http://developer.chrome.com/extensions/webNavigation.html#event-onBeforeNavigate):

frameId ( integer )
0 indicates the navigation happens in the tab content window; a positive value indicates navigation in a subframe. Frame IDs are unique for a given tab and process.

Krishna Singh

unread,
Jun 10, 2013, 11:17:25 AM6/10/13
to chromium-...@chromium.org
Hi,


In which file you wrote the code, backgrund.js or navigation_collector.js,

A single url sometimes call hidden background navigation for website navigations, check for only google.co.in, and tell me how much time it shows alert.

I may help you because I just done a this like project with a lot of r & d and problems.


Thanks

Mostafa Elsaie

unread,
Jun 19, 2013, 9:01:44 AM6/19/13
to chromium-...@chromium.org
Thats true, if you check for the "framId" == 0, you'll be insuring that this is infact the top URL. However, the problem with onBeforeNavigate is that its still experimental. It fires not only if you navigate to a different URL, but if you try typing in your omni box a URL, as soon as the autocomplete functionality kicks in, it triggers a onBeforeNavigate event as well. Unfortunate i have no solution for this issue.
Reply all
Reply to author
Forward
0 new messages