0Pricing
Browser Extensions Development (Chrome & Edge) · 강의

주소창 입력에 응답하기

주소창에서 받은 사용자 입력을 처리하고 제안 사항을 제공하며 입력된 텍스트에 따라 사용자 지정 로직을 실행합니다.

주소창 입력에 응답하기은(는) CoddyKit의 무료 Browser Extensions Development (Chrome & Edge) 강의입니다. 이것은 4개 중 3번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Browser Extensions Development (Chrome & Edge) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Browser Extensions Development (Chrome & Edge) 강의에는 총 4개의 강의가 포함되어 있습니다.

이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.

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 text the user has typed.
  • You get a suggest callback 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 text entered 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.onInputChanged to provide dynamic suggestions as the user types.
  • Suggestions are an array of objects with content and optional description fields.
  • chrome.omnibox.onInputEntered allows your extension to execute a specific action when the user presses Enter.
  • You can also set a setDefaultSuggestion for 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.

자주 묻는 질문

“주소창 입력에 응답하기” 강의는 무료인가요?

네 — “주소창 입력에 응답하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Browser Extensions Development (Chrome & Edge) 강의 전체를 잠금 해제할 수 있습니다. Browser Extensions Development (Chrome & Edge) 강의에는 총 4개의 강의가 포함되어 있습니다.

“주소창 입력에 응답하기”에서 뭘 배우나요?

주소창에서 받은 사용자 입력을 처리하고 제안 사항을 제공하며 입력된 텍스트에 따라 사용자 지정 로직을 실행합니다. 브라우저에서 직접 실행하는 실습 코드로 Browser Extensions Development (Chrome & Edge)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.

Browser Extensions Development (Chrome & Edge)을(를) 시작하는 데 경험이 필요한가요?

사전 경험은 필요하지 않습니다. CoddyKit의 Browser Extensions Development (Chrome & Edge)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 3번째 강의입니다.

“주소창 입력에 응답하기” 강의는 얼마나 걸리나요?

대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.

이 Browser Extensions Development (Chrome & Edge) 강의에서 코드를 작성하고 실행할 수 있나요?

네. 모든 Browser Extensions Development (Chrome & Edge) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.

이 강의의 모든 강의

  1. 컨텍스트 메뉴 항목 추가
  2. 주소창 키워드 통합
  3. 주소창 입력에 응답하기
  4. Commands API를 활용한 키보드 단축키
← Browser Extensions Development (Chrome & Edge)(으)로 돌아가기