sorin
sorin

Reputation: 170498

Chrome omnibox events without specific keywords?

I do want to check the content written in Chrome omnibox and redirect to the proper page.

Still, I cannot use specific keywords because I do want to redirect things like BUG-1234 to http://bugs.example.com/BUG-1234

I do have a regexp for this (as the BUG part can have lots of values).

How can I do this?

Upvotes: 3

Views: 1247

Answers (1)

Sudarshan
Sudarshan

Reputation: 18534

A chrome extension can help you, with help of Omnibox.

If i understood correctly when you enter BUG-1234 and hit Enter in Omnibox, your webpage URL Should be http://bugs.example.com/BUG-1234

Demonstration

I have used keyword as

"keyword": "BUG"

BUG, you can change it as per functionality. So when you enter B+U+G in chrome Omnibox , the search provider adds a custom layer as shown here

Image 1)

Beginning Screen

and when you enter 1234 and hit Enter or Select the suggested URL Open Bug %s ? in Omnibox, as shown here

Image 2)

enter image description here

It opens a web page with URL as shown here, where i used http://bugs.example.com as a test URL, which can be extended further.

Image 3)

enter image description here

manifest.json

Registered background Page and Omnibox with Chrome Extension, and added related permissions.

{
    "name": "Bug Tracker",
    "description": "This integrates chrome omnibox with bug search",
    "version": "1",
    "manifest_version": 2,
    "background": {
        "scripts": [
            "background.js"
        ]
    },
    "omnibox": {
        "keyword": "BUG"
    },
    "permissions": [
        "<all_urls>"
    ]
}

background.js

Script for Custom Suggestions

//Set Text to show for custom suggested URL(s)
chrome.omnibox.setDefaultSuggestion({
    "description": "Open Bug %s ?"
});

//Fired when Enter or a suggested Link is selected
chrome.omnibox.onInputEntered.addListener(function (bugId) {
    //Use your custom URL
    chrome.tabs.update({
        "url": "http://bugs.example.com/BUG-" + bugId
    }, function () {
        console.log("Bug Page is open");
    });
    console.log("Input Entered is " + bugId);
});

References

Upvotes: 4

Related Questions