Chrome extension, focus on page instead of omnibox after selected tab is updated?

I created an extension called quickmarks that will open a bookmark by keyword on the currently selected tab. I'm using omnibox to select bookmarks ( chrome.omnibox.onInputEntered), and the chrome.tabs.updateAPI to open the bookmark URL on the current tab, providing the URL in updateProperties. However, after the tab is updated, the focus still remains in omnibox, the experience is not as good as I wanted. So there is a way to install focus on the page, not omnibox.

Btw, I tried to open a new tab using chrome.tabs.create. the page will be focused instead of omnibox, which is my desired behavior.

Thank.

+5
source share
3 answers

Using chrome.tabs.update(tab.id, {url: url, selected: true});does the trick for me.

+6
source

The accepted answer no longer works in Chrome 31. I was hoping this simple property selectedis deprecated, but the replaceable property highlightedalso does not assign focus to the contents of the tab.

I could only steal focus from Omnibox by closing the current tab and then creating a new tab in its place. Here is the code that works in Chrome 31:

chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.remove(tab.id, function() {
        chrome.tabs.create({url:url, active:true});
    });
});

Although this, of course, is not ideal, the current tab is closed, and the new one is open so quickly that you hardly notice the difference.

0
source

, Chrome, . , chrome.tabs.create , .

iChrome Chrome, , , , , iChrome. , "selected: true".

, , , Chrome , onmibar, . :

chrome.tabs.create({url:url, active:true}, function(){
    chrome.tabs.remove(tab.id);
});

, , , , . .

0

All Articles