Super Engineer
Super Engineer

Reputation: 1976

Getting active window url in crossrider

I've been trying to track users current tab url, but I'm having some trouble doing this.

My current code

var activeTabUrl = null;
appAPI.tabs.onTabSelectionChanged(function(tabInfo) {
  activeTabUrl = tabInfo.tabUrl;
});

This code tracks active tab when user changes tab, but the problem is it doesn't track when a user changes url in the same tab. How can I track that?

Upvotes: 0

Views: 509

Answers (2)

ueg1990
ueg1990

Reputation: 1033

i hope you can help me. i am using crossrider for the first time and need to write a plugin that detects images in the current webpage like imgur and pinterest. can you provide some starting point and API functions that i look at to implement my functionality, maybe like some high-level structure on how to approach this. would really appreciate ur help in this. :)

Upvotes: 0

Shlomo
Shlomo

Reputation: 3753

I can see you are acquiring the URL in the extension's background scope and I presume you want to track the URL in the same scope. In this situation, I would use appAPI.webRequest.onBeforeNavigate using the same activeTabUrl variable to supplement your existing code, as follows:

appAPI.webRequest.onBeforeNavigate.addListener(function(details) {
    // Where:
    //   * details.pageUrl is the URL of the tab requesting the page

    // Track Url
    activeTabUrl = details.pageUrl;
});

Disclaimer: I am a Crossrider employee

Upvotes: 1

Related Questions