0Pricing
Browser Extensions Development (Chrome & Edge) · Lekcja

Tworzenie interaktywnego interfejsu popup

Twórz dynamiczne i responsywne interfejsy popup za pomocą HTML, CSS i JavaScript, aby zapewnić użytkownikom szybką interakcję.

Tworzenie interaktywnego interfejsu popup to bezpłatna lekcja Browser Extensions Development (Chrome & Edge) na CoddyKit. To lekcja 1 z 4. Możesz przeczytać całą lekcję poniżej za darmo — a potem ćwiczyć ją interaktywnie w przeglądarce z wbudowanym edytorem kodu i tutorem AI dostępnym 24/7. To część ścieżki edukacyjnej Browser Extensions Development (Chrome & Edge), a Twój postęp synchronizuje się między webem a aplikacją CoddyKit. Kurs Browser Extensions Development (Chrome & Edge) zawiera 4 lekcji w sumie.

Części tej lekcji nie zostały jeszcze przetłumaczone i są wyświetlane po angielsku.

What are Extension Popups?

Browser extensions often need a small user interface to interact with. This is where popup pages come in!

  • A popup is a small window that appears when you click your extension's icon in the browser toolbar.
  • It's perfect for quick actions, displaying information, or simple settings.
  • Popups are temporary: they close automatically when you click outside them or switch tabs.

Declaring Your Popup UI

To tell your browser extension which HTML file to use as its popup, you specify it in your manifest.json file.

You use the "action" key, and then "default_popup" points to your HTML file.

{
  "manifest_version": 3,
  "name": "My Popup Extension",
  "version": "1.0",
  "action": {
    "default_popup": "popup.html",
    "default_icon": "icon.png"
  }
}

Popup's HTML Structure

Your popup is essentially a miniature web page. It uses standard HTML to define its structure and content.

Create a file named popup.html (or whatever you set in manifest.json) and add your HTML.

<!DOCTYPE html>
<html>
<head>
  <title>My Popup</title>
</head>
<body>
  <h1>Hello from Popup!</h1>
  <p>This is your extension's user interface.</p>
</body>
</html>

Styling Your Popup with CSS

Just like any web page, you can use CSS to style your popup. Link a CSS file in your popup.html's <head> section.

Keep popup styles concise for a small, focused UI.

/* popup.css */
body {
  font-family: sans-serif;
  width: 200px; /* Keep popups small */
  padding: 10px;
  background-color: #f0f0f0;
}
h1 {
  color: #333;
  font-size: 1.2em;
}

Adding Interactivity with JavaScript

To make your popup dynamic and responsive, you'll need JavaScript. Link your script file in your popup.html, usually before the closing </body> tag.

This script runs every time the popup is opened.

// popup.js
document.addEventListener('DOMContentLoaded', () => {
  console.log('Popup script loaded!');
  // Your interactive code goes here
});

Understanding Popup Script Execution

When a user clicks your extension icon, the browser loads and executes your popup.html and its linked JavaScript.

  • Each time the popup opens, the script runs from scratch.
  • It has access to standard web APIs (DOM, fetch) and specific browser extension APIs (chrome.*).
  • When the popup closes, its JavaScript context is destroyed.

Example: Simple Click Counter

Let's create a basic popup that counts how many times a button is clicked.

For this to work, your popup.html needs a <span id="count"> and a <button id="increment">.

// popup.js
let count = 0;
document.addEventListener('DOMContentLoaded', () => {
  const countDisplay = document.getElementById('count');
  const incrementButton = document.getElementById('increment');

  countDisplay.textContent = count;

  incrementButton.addEventListener('click', () => {
    count++;
    countDisplay.textContent = count;
  });
});

Accessing Browser Extension APIs

Popup scripts can directly use many chrome.* APIs to interact with the browser, tabs, and extension itself.

For example, you can get information about your extension using chrome.runtime.getManifest().

// popup.js
document.addEventListener('DOMContentLoaded', () => {
  const manifest = chrome.runtime.getManifest();
  const versionElement = document.getElementById('version');
  if (versionElement) {
    versionElement.textContent = `v${manifest.version}`;
  }
  console.log('Extension Name:', manifest.name);
});

Popup Best Practices

Since popups are temporary, it's crucial to keep them lightweight and performant.

  • Keep it small: A popup should have a clear, single purpose.
  • Fast loading: Avoid heavy images or complex computations.
  • Responsive design: Ensure it looks good on various screen sizes.
  • Minimize network requests: Fetch data efficiently or pre-fetch in the background script if possible.

Popup Knowledge Check

Let's test your understanding of extension popups.

Recap: Interactive Popups

Great job! You've learned the fundamentals of creating interactive popup UIs for your browser extensions.

  • Popups are small, temporary UIs linked in manifest.json via "action".
  • They use standard HTML, CSS, and JavaScript.
  • Popup scripts run when the popup opens and are destroyed when it closes.
  • They can access browser extension APIs for dynamic interactions.

Next, you'll explore how to build more persistent configuration UIs with Options Pages!

Często zadawane pytania

Czy lekcja „Tworzenie interaktywnego interfejsu popup” jest bezpłatna?

Tak — pełny tekst „Tworzenie interaktywnego interfejsu popup” jest dostępny za darmo tutaj w sieci. Aby ćwiczyć ją interaktywnie (wbudowany edytor kodu i tutor AI dostępny 24/7) i odblokować resztę kursu Browser Extensions Development (Chrome & Edge), przejdź na CoddyKit PRO. Kurs Browser Extensions Development (Chrome & Edge) zawiera 4 lekcji w sumie.

Co nauczysz się w „Tworzenie interaktywnego interfejsu popup”?

Twórz dynamiczne i responsywne interfejsy popup za pomocą HTML, CSS i JavaScript, aby zapewnić użytkownikom szybką interakcję. Ćwiczysz Browser Extensions Development (Chrome & Edge) z praktycznym kodem, który uruchamiasz bezpośrednio w przeglądarce, a tutor AI dostępny 24/7 odpowiada na Twoje pytania podczas pracy nad lekcją.

Czy potrzebuję doświadczenia, aby zacząć Browser Extensions Development (Chrome & Edge)?

Nie wymagamy żadnego doświadczenia. Browser Extensions Development (Chrome & Edge) w CoddyKit jest strukturyzowany dla początkujących i zaawansowanych użytkowników, więc możesz zacząć tutaj lub od początku i uczyć się w swoim tempie. To lekcja 1 z 4.

Ile czasu zajmuje lekcja „Tworzenie interaktywnego interfejsu popup”?

Większość lekcji CoddyKit trwa około 5–10 minut. Każda lekcja to mały, interaktywny krok, dzięki czemu robisz systematyczne postępy i zawsze wracasz dokładnie do tego samego miejsca — na webie i w aplikacji.

Czy mogę pisać i uruchamiać kod w tej lekcji Browser Extensions Development (Chrome & Edge)?

Tak. Każda lekcja Browser Extensions Development (Chrome & Edge) zawiera wbudowany edytor kodu, więc piszesz i uruchamiasz prawdziwy kod bezpośrednio w przeglądarce i od razu otrzymujesz sprzężenie zwrotne od AI — bez konfiguracji na komputerze.

Wszystkie lekcje w tym kursie

  1. Tworzenie interaktywnego interfejsu popup
  2. Tworzenie strony opcji
  3. Komunikacja między komponentami interfejsu
  4. Motywy CSS i obsługa trybu ciemnego
← Powrót do Browser Extensions Development (Chrome & Edge)