Uprawnienia i dopasowywanie hostów
Poznaj sposoby deklarowania i żądania niezbędnych uprawnień oraz dowiedz się, jak uprawnienia hostów kontrolują dostęp do witryn internetowych.
Uprawnienia i dopasowywanie hostów to bezpłatna lekcja Browser Extensions Development (Chrome & Edge) na CoddyKit. To lekcja 3 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.
Why Extensions Need Permissions
Just like apps on your phone, browser extensions often need special 'permissions' to do their job. These permissions define what your extension can and cannot do.
This system is crucial for user security and privacy. It prevents extensions from accessing information or performing actions they don't need, without your explicit consent.
Two Core Permission Types
In Manifest V3, permissions generally fall into two categories:
- API Permissions: Access to specific browser features (e.g., managing tabs, saving data).
- Host Permissions: Access to specific websites (e.g., reading content on example.com).
We'll look at how to declare both in your manifest.json file.
Declaring API Permissions
API permissions are listed under the "permissions" key in your manifest.json. Each string in the array corresponds to a specific browser API.
For example, "storage" lets your extension save user data, and "tabs" allows it to interact with browser tabs (like getting their URLs).
{
"manifest_version": 3,
"name": "My Extension",
"version": "1.0",
"permissions": [
"storage",
"tabs"
]
}The 'activeTab' Permission
The "activeTab" permission is unique. It's an API permission that grants your extension temporary host permissions to the currently active tab.
This access is granted only when the user *invokes* your extension (e.g., clicks its toolbar icon). It's a great way to reduce initial permission warnings, as access is only given when needed.
{
"manifest_version": 3,
"name": "ActiveTab Demo",
"version": "1.0",
"permissions": [
"activeTab"
]
}Understanding Host Permissions
Host permissions are crucial for defining which websites your extension can interact with. Without them, your extension cannot read or modify content on web pages.
This is a major security boundary. An extension with host permission for google.com cannot access facebook.com, protecting user data and ensuring privacy.
Specifying Host Permissions
Host permissions are declared in the "host_permissions" array in your manifest.json. You use URL match patterns to specify the domains.
A match pattern like "*://*.example.com/*" means access to all subdomains of example.com over HTTP or HTTPS.
{
"manifest_version": 3,
"name": "Host Access",
"version": "1.0",
"host_permissions": [
"*://developer.chrome.com/*",
"https://www.example.org/*"
]
}Match Pattern Wildcards
Match patterns use special characters:
*: Matches any string (except/in scheme/host, or#in path).<all_urls>: A special pattern that matches any URL (http,https,ftp,file). Use this with extreme caution as it grants wide access.
For example, "https://*.google.com/search?*" would match Google search results pages.
Combining API & Host Permissions
Often, your extension will need both API and host permissions. Here's an example for an extension that wants to execute a script on Wikipedia pages.
It needs the "scripting" API permission to run code, and host permission for Wikipedia to define where that code can run.
{
"manifest_version": 3,
"name": "Wiki Enhancer",
"version": "1.0",
"permissions": [
"scripting"
],
"host_permissions": [
"*://*.wikipedia.org/*"
]
}User Consent & Trust
When a user installs your extension, the browser displays a list of all requested permissions. This is their chance to understand what your extension can do.
Always request the minimum necessary permissions. Over-requesting can make users distrust your extension and choose not to install it. Be transparent!
Check Your Understanding
Which statements accurately describe host permissions in Manifest V3 extensions?
Permissions & Host Matching Recap
Great job! You've learned about the vital role of permissions in Manifest V3 extensions.
- API Permissions: Access browser features (e.g.,
"storage","tabs"). - Host Permissions: Control website access using URL match patterns (e.g.,
"*://*.google.com/*"). "activeTab"is a special API permission that grants temporary host access.- Always request the minimum necessary permissions to build user trust.
Understanding these concepts is key to building secure and functional extensions!
Często zadawane pytania
Czy lekcja „Uprawnienia i dopasowywanie hostów” jest bezpłatna?
Tak — pełny tekst „Uprawnienia i dopasowywanie hostów” 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 „Uprawnienia i dopasowywanie hostów”?
Poznaj sposoby deklarowania i żądania niezbędnych uprawnień oraz dowiedz się, jak uprawnienia hostów kontrolują dostęp do witryn internetowych. Ć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 3 z 4.
Ile czasu zajmuje lekcja „Uprawnienia i dopasowywanie hostów”?
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
- Poznawanie struktury Manifest V3
- Background service workery
- Uprawnienia i dopasowywanie hostów
- Action, ikony i przycisk na pasku narzędzi