Search code examples
google-chrome-extensionmicrosoft-edge-extension

Where is `OnInputEnteredDisposition` set?


The Chrome doc and the Mozilla doc are clear on what OnInputEnteredDisposition is when writing a callback for omnibox.onInputEntered's event listener. The latter even has an example on how to process it - but where is it set?

What I mean by "where it's set":

A listener for omnibox.onInputEntered is passed:

  • the user's selection

  • a omnibox.OnInputEnteredDisposition: use this to determine whether to open the new page in the current tab, in a new foreground tab, or in a new background tab.

source: MDN, omnibox.onInputEntered

The MDN page of omnibox.OnInputEnteredDisposition only states that

It's passed into the omnibox.onInputEntered event listener, along with the selection itself.

The reason I'm confused is that none of the extension methods I saw so far are able to set omnibox.OnInputEnteredDisposition - they can only listen to it. In the official chrome-extensions-samples repo, I did a search, but these are the only uses I could find:

  1. In the omnibox/simple-example, but whenever I tested it, it was always set to currentTab (at least, I couldn't find a way to change it)

  2. The other 3 places in archived WebView examples, where it is actually set using the windowOpenDisposition attribute but that API has been deprecated since 2020. It says there that "It remains supported for Enterprise and Education customers on ChromeOS until at least Jan 2025", so I guess this is only for backwards compatibility?


I'm new to extensions, so I guess this specified by each user when they set up default behavior for their browser? Or did I manage to miss this part in either of the docs? I haven't written JavaScript in a long time, so it is more than possible that I am completely misunderstand the examples, so please don't hesitate to point these out.


Solution

  • omnibox.OnInputEnteredDisposition simply helps you listen for 3 scenarios: Open the selection in the current tab, new foreground tab or new background tab. You can choose to do something when it comes to each scenario, just like the MDN example:

    switch (disposition) {
        case "currentTab":
          browser.tabs.update({ url });
          break;
        case "newForegroundTab":
          browser.tabs.create({ url });
          break;
        case "newBackgroundTab":
          browser.tabs.create({ url, active: false });
          break;   }
    

    If you check chrome.omnibox.OnInputEnteredDisposition in the devtools: OnInputEnteredDisposition I'm afraid you won't be able to change it, and you don't need to change it.

    In the omnibox/simple-example, but whenever I tested it, it was always set to currentTab (at least, I couldn't find a way to change it)

    In this demo, left-click --> currentTab, middle-click --> newBackgroundTab, Alt+Enter --> newForegroundTab (It follows the browser design). It helps the extension to deal with all these 3 possible actions that users may take. You can even force to open in foreground regardless of how user chooses to open the tab. I don't see the point in changing them though.