Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Set/Change active tab

I'm requesting functionality to set/change the currently active tab using the tabId.
What I'd like to do is that browserAction onclick will open a new tab of domain.com IF there isn't already a tab with that domain open. If there is already a tab with the domain, then switch to the tab instead of opening new. Essentially providing a quick link to the page, whether open or not.

Example code (Requesting something like the setCurrentTab function):
appAPI.browserAction.onClick(function(){
var found = false;
appAPI.tabs.getAllTabs(function(tabs){
for (var i=0; i < tabs.length; i++) {
if(tabs[i].tabUrl.indexOf('domain.com') != -1) {
appAPI.tabs.setCurrentTab(tabs[i].tabId);
found = true;
break;
}
}
});
if(!found) appAPI.tabs.create('http://domain.com');
}
1 person likes
this idea
+1
Reply
  • This reply was removed on 2013-06-23.
    see the change log
  • Shlomo (Official Rep) June 23, 2013 19:23
    Hello cyberdude,

    Currently you can do this for Chrome and Firefox using [appAPI.tabs.setActive]. We hope to have support for IE added within the next month.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Thanks Shlomo :)
    I guess you just updated docs for this today, after I put out this question? I am 100% sure it wasn't in the documentation before, am I right?
    Looking forward to seeing this implemented in IE (And hopefully Safari, though I wouldn't be surprised if Safari has some security restriction on this?)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Shlomo (Official Rep) June 24, 2013 07:01
    Hello cyberdude,

    You're right ... we added it just for you ;-)

    BTW: It was in the pipeline to be released. Originally we were going to wait for IE to be released before adding it, but in light of your request we decided to release it earlier.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Haha thanks :)
    Additional Question then:
    Are there any ETA for both setActive IE support (And maybe Safari support)
    And also getActive (Currently only supported in Chrome), any ETA for this in FF and IE (And maybe Safari?)?

    I'm currently planning on testing whether I can work around the lack of support for getActive, by using the onTabSelectionChange to test when the tabs changes to the domain in question, and then store that, to use in the onclick.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Shlomo (Official Rep) June 24, 2013 10:48
    Hello cyberdude,

    At the moment, as mentioned previously, we hope to have IE support within the month.

    Regarding getActive, we also hope to release them in the same time frame.

    As for Safari support for both, at this time there is no set date for when they will be implemented but they are on our roadmap.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Thank you for the information Shlomo, within the/a month is a fair time frame, that'll definitely mean it's useful for me.
    A shame on the safari issue, there are a few too many obstacles with Safari.
    So I'm contemplating on waiting with Safari support on my extension.
    Or at least not cater to Safari, but maybe still support Safari with limited functionality..
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hey Shlomo:
    Any updates on this issue? Are you any closer to supporting getActive and setActive in Chrome, FF and IE?
    Any ETA?
    1 Month have passed, and I'm looking for an update, as I'm starting to miss this feature greatly :(..
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Shlomo (Official Rep) July 28, 2013 12:46
    Hello cyberdude,

    The dev team have advised that appAPI.tabs.getActive will hopefully be released within the next couple of weeks. However, they ran into issues trying to support these features in IE and hence it may not be supported for the foreseeable future.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Really bad news for me :(
    Can you clarify which appAPI.tabs methods supporting, and in which browsers?
    Unsupported getActive, getAllTabs made useless IE version.

    We already done alot of work to redo our extension with your API
    Support of the IE was the main benefit of Crossrider ( we already have versions for FF and Chrome ).

    PS. Can you mark somehow methods that didn't suported by all browsers in API docs.

    Anyway, cool api. Thanks for your work :)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hello Anton,

    Thanks for the compliment and I'm sorry to hear the methods you require are not available in IE at the moment.
    In general, you can see the supported browsers for each method in the relevant docs topic (http://docs.crossrider.com/#!/api/app...).
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • I'm trying to workaround this problem.

    Here is what i need in result:
    - create new tab ( this should be done from BG script )
    - when content script will be ready, BG send message to this tab

    That how I done it in Chrome and FF:
    - create new tab
    - getActive and save tabId in BG
    - wait until content script was ready ( content script will pass message to BG when ready )
    - send message to content script

    Here is my idea about workaround for IE (didn't implemented yet, so this is just a idea):
    - set onCreated listener ( maybe better use onSelectionChanged )
    - create new tab
    - get tabId from onCreated ( maybe better use onSelectionChanged ) and store tabId in BG
    - wait until content script was ready ( content script will pass message to BG when ready )
    - send message to content script

    The main problem: onCreated or onSelectionChanged can't be removed, that is not good. Maybe crossrider already has 'removeListener' functionality?

    Thanks for reply :)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hello Anton,

    If I understand you correctly, I think you are overthinking this. Since in your CH & FF algorithms you are sending a message from your new tab to the BG and then responding from the BG, I don't understand your need for the appAPI.tabs API at all. Perhaps you can explain the need for it and provide a code snippet and/or the extension id.

    Based on the information available at the moment, something like:

    background.js:
    appAPI.ready(function() {
    var newTabId=null;

    appAPI.message.addListener({channel:'newTab'}, function(msg) {
    newTabId = msg.tabId;
    });
    appAPI.message.toActiveTab({some:msg}, {channel:'bgMsg'});
    });


    extension.js (OR resourceHTML crossriderMain function):
    appAPI.ready(function($) {
    appAPI.message.addListener({channel:'bgMsg'}, function(msg) {
    // Do something
    });

    // Send message if new tab
    if(newTab)
    appAPI.message.toBackground({tabId:appAPI.getTabId()}, {channel:'newTab'});
    });
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly

  • Hi,

    Under IE, i'm trying to :
    - call appAPI.openURL with focus option set to false and where option set to "tab",
    - wait until script loaded in new tab just created
    - set the focus the tab just created with appAPI.tabs.setActive when script loaded.

    Unfortunatelly appAPI.tabs.setActive is not working under IE.

    Is there any workaround to set a tab active when needed under IE ?

    Thx in advance,
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly