Omnibox Girdisine Yanıt Verme
Omnibox'tan gelen kullanıcı girdisini işleyin, öneriler sunun ve girilen metne göre özel mantık çalıştırın.
Omnibox Girdisine Yanıt Verme, CoddyKit'te ücretsiz bir Browser Extensions Development (Chrome & Edge) dersidir. Bu, 4 dersinin 3. dersidir. Aşağıdan dersin tamamını ücretsiz okuyabilir, sonra tarayıcıda yerleşik kod editörü ve 7/24 yapay zeka koçu ile uygulamalı olarak pratik yapabilirsin. Bu, Browser Extensions Development (Chrome & Edge) öğrenme yolunun bir parçasıdır ve ilerlemeniz web ve CoddyKit uygulaması arasında senkronize olur. Browser Extensions Development (Chrome & Edge) kursu toplamda 4 dersten oluşur.
Bu dersin bazı bölümleri henüz çevrilmemiş olup İngilizce olarak gösterilmektedir.
Responding to Omnibox Input
Welcome to the lesson on making your extension smart! We've learned how to set up an omnibox keyword. Now, let's make it respond to user input.
The omnibox (address bar) is a powerful place. Your extension can listen for what users type after your keyword and react in two main ways:
- Provide suggestions: Guide the user as they type.
- Execute actions: Perform tasks when they press Enter.
The Omnibox API
To interact with the omnibox, we use the chrome.omnibox API. This API lives in your extension's background script (service worker).
Remember to declare the "omnibox" permission in your manifest.json file for your extension to use this API.
Listening for Input Changes
As a user types after your omnibox keyword, your extension can provide dynamic suggestions. This is handled by the chrome.omnibox.onInputChanged event.
- It fires every time the user's input changes.
- You receive the current
textthe user has typed. - You get a
suggestcallback function to send suggestions back to the omnibox.
Structuring Your Suggestions
The suggest callback expects an array of suggestion objects. Each object needs an "content" field, which is the actual text that will be inserted if the user selects the suggestion.
You can also add a "description" field for richer suggestions:
content: The text to use if the suggestion is selected.description: (Optional) Rich HTML text displayed next to the suggestion.
Code: Dynamic Suggestions
Let's create a background script that suggests a prefix based on the user's input. Make sure your manifest.json has "omnibox": { "keyword": "go" } and the "omnibox" permission.
chrome.omnibox.onInputChanged.addListener(
(text, suggest) => {
const suggestions = [
{ content: text + " search", description: "Search for: " + text },
{ content: text + " docs", description: "Docs for: " + text }
];
suggest(suggestions);
}
);Executing Actions on Enter
Once the user types their input and presses the Enter key, the chrome.omnibox.onInputEntered event is triggered. This is where you perform the main action of your extension.
- It provides the final
textentered by the user. - It also gives a
disposition, indicating how the user wants the action to be handled (e.g., new tab, current tab).
Code: Opening a New Tab
Here's how to open a new tab with a search query based on the user's input. This code would typically be in the same background script as onInputChanged.
chrome.omnibox.onInputEntered.addListener(
(text, disposition) => {
const searchUrl = `https://www.google.com/search?q=${encodeURIComponent(text)}`;
if (disposition === 'newForegroundTab') {
chrome.tabs.create({ url: searchUrl });
} else if (disposition === 'newBackgroundTab') {
chrome.tabs.create({ url: searchUrl, active: false });
} else {
// currentTab
chrome.tabs.update({ url: searchUrl });
}
}
);Setting a Default Suggestion
You can provide a default suggestion that appears even before the user types anything. This is useful for guiding users or showing a common action.
Use chrome.omnibox.setDefaultSuggestion() with a description to set this initial hint.
chrome.omnibox.setDefaultSuggestion({
description: 'Type a query to search Google'
});Rich Suggestions with Descriptions
For even more helpful suggestions, you can use HTML within the description field. This allows you to highlight parts of the text, use different colors, or make it more readable.
- Use
<match>tags to highlight matching text. - Use
<dim>tags for less important text. - Remember to escape special characters like
<and>if they are part of your literal text.
Quick Check: Omnibox Events
Consider an extension that uses the omnibox keyword 'wiki'. Which event listener is primarily responsible for updating suggestions as the user types 'wiki cats'?
Recap: Responding to Omnibox Input
You've learned how to make your extension truly interactive with the omnibox!
- We use
chrome.omnibox.onInputChangedto provide dynamic suggestions as the user types. - Suggestions are an array of objects with
contentand optionaldescriptionfields. chrome.omnibox.onInputEnteredallows your extension to execute a specific action when the user presses Enter.- You can also set a
setDefaultSuggestionfor initial guidance.
This powerful API lets users interact with your extension directly from the browser's address bar, making common tasks quicker and more efficient.
Sıkça Sorulan Sorular
“Omnibox Girdisine Yanıt Verme” dersi ücretsiz mi?
Evet — “Omnibox Girdisine Yanıt Verme” dersin tüm metni burada web'de ücretsiz olarak okunabilir. Etkileşimli olarak pratik yapmak (yerleşik kod editörü ve 7/24 yapay zeka koçu) ve Browser Extensions Development (Chrome & Edge) kursunun geri kalanını açmak için CoddyKit PRO'ya yükselt. Browser Extensions Development (Chrome & Edge) kursu toplamda 4 dersten oluşur.
“Omnibox Girdisine Yanıt Verme” dersinde ne öğreneceğim?
Omnibox'tan gelen kullanıcı girdisini işleyin, öneriler sunun ve girilen metne göre özel mantık çalıştırın. Browser Extensions Development (Chrome & Edge) ile uygulamalı kodu tarayıcıda doğrudan çalıştırarak pratik yaparsın ve 7/24 yapay zeka koçu dersi çalışırken sorularını yanıtlar.
Browser Extensions Development (Chrome & Edge) öğrenmeye başlamak için deneyim gerekli mi?
Önceden deneyim gerekmez. CoddyKit'te Browser Extensions Development (Chrome & Edge), başlangıçtan ileri seviyeye kadar yapılandırıldığı için buradan başlayabilir veya başından başlayıp kendi hızında ilerleme yapabilirsin. Bu, 4 dersinin 3. dersidir.
“Omnibox Girdisine Yanıt Verme” dersi ne kadar sürer?
Çoğu CoddyKit dersi yaklaşık 5–10 dakika sürer. Her biri kısa ve etkileşimli olduğu için sabit ilerleme yaparsın ve web ile uygulama arasında tam olarak bıraktığın yerden devam edebilirsin.
Bu Browser Extensions Development (Chrome & Edge) dersinde kod yazıp çalıştırabilir miyim?
Evet. Her Browser Extensions Development (Chrome & Edge) dersi yerleşik bir kod editörü içerir, bu sayede tarayıcıda gerçek kod yazıp çalıştırabilir ve anlık yapay zeka geri bildirimi alırsın — yerel kurulum gerekli değildir.
Bu kursun tüm dersleri
- Bağlam Menüsü Öğeleri Ekleme
- Omnibox Anahtar Sözcüğü Entegrasyonu
- Omnibox Girdisine Yanıt Verme
- Commands API ile Klavye Kısayolları