고급 권한 이해하기
`activeTab`, `scripting` 및 호스트 권한과 같은 민감한 권한을 살펴보고, 언제 어떻게 요청해야 하는지 학습합니다.
고급 권한 이해하기은(는) CoddyKit의 무료 Browser Extensions Development (Chrome & Edge) 강의입니다. 이것은 4개 중 1번째 강의입니다. 아래에서 전체 강의를 무료로 읽을 수 있으며, 내장 코드 에디터와 24/7 AI 튜터와 함께 브라우저에서 직접 실습할 수 있습니다. 이 강의는 Browser Extensions Development (Chrome & Edge) 학습 경로의 일부이며, 진행 상황이 웹과 CoddyKit 앱에 동기화됩니다. Browser Extensions Development (Chrome & Edge) 강의에는 총 4개의 강의가 포함되어 있습니다.
이 강의의 일부는 아직 번역되지 않았으며 영어로 표시됩니다.
Beyond Basic Permissions
Welcome! In this lesson, we'll dive into advanced browser extension permissions. These permissions grant powerful capabilities, allowing your extension to interact more deeply with web content and user data.
Understanding them is crucial for building robust extensions while maintaining user trust and security.
We'll cover:
- Host Permissions
activeTabPermissionscriptingPermission
Granting Web Access
Host permissions are fundamental. They define which websites your extension can interact with. This includes reading data, modifying content, or making network requests on those specific sites.
Think of them as "keys" that unlock access to certain web domains.
Manifesting Host Access
You declare host permissions in your manifest.json file under the host_permissions key. Each string is a URL pattern.
For instance, to allow access to all pages on google.com, you'd specify:
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"host_permissions": [
"https://www.google.com/*"
]
}Broad Access with Wildcards
You can use wildcards (*) for broader access. For example, "<all_urls>" (or "*://*/*") grants access to all URLs, on all schemes (HTTP, HTTPS).
While powerful, using broad wildcards should be done with extreme caution, as it grants your extension significant control over the user's browsing experience on any site.
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"host_permissions": [
"<all_urls>"
]
}Temporary Tab Privileges
The activeTab permission is a safer alternative to broad host permissions for one-off actions on the current page.
When the user invokes your extension (e.g., clicks its icon), activeTab grants your extension temporary host permissions to the currently active tab. These permissions last until the user navigates away or closes the tab.
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"activeTab"
]
}Getting Current Tab URL
With activeTab, your extension can access information about the current tab, like its URL or title, without needing permanent host permissions.
Try running this example. Imagine this code is in your extension's popup script:
// This script runs when the extension popup opens.
document.addEventListener('DOMContentLoaded', function() {
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
if (tabs.length > 0) {
const activeTab = tabs[0];
console.log('Active tab URL:', activeTab.url);
// Display in popup for demonstration
document.body.innerHTML = `<p>Current URL: ${activeTab.url}</p>`;
} else {
document.body.innerHTML = `<p>No active tab.</p>`;
}
});
});Programmatic Code Injection
The scripting permission allows your extension to programmatically inject JavaScript and CSS into web pages. This is how you modify a page's content or behavior.
It's an essential permission for content scripts, replacing the Manifest V2 tabs.executeScript API.
{
"name": "My Extension",
"version": "1.0",
"manifest_version": 3,
"permissions": [
"scripting"
],
"host_permissions": [
"https://www.example.com/*"
]
}Modifying a Page
Once you have scripting permission (and host permission for the target tab), you can inject code. This example injects a simple script to change the background color of the active tab.
Imagine this running in your background script or popup:
// This code would typically run from a background script
// or popup after a user action.
chrome.tabs.query({ active: true, currentWindow: true }, function(tabs) {
if (tabs.length > 0) {
const activeTabId = tabs[0].id;
chrome.scripting.executeScript({
target: { tabId: activeTabId },
function: () => {
// This function runs in the context of the web page
document.body.style.backgroundColor = 'lightblue';
console.log('CoddyKit: Page background changed!');
}
});
}
});Least Privilege Principle
Always follow the Principle of Least Privilege: request only the permissions your extension absolutely needs.
- Required Permissions: Declared in
manifest.jsonand requested at install. - Optional Permissions: Can be requested at runtime using
chrome.permissions.request()only when the user needs that specific feature. This gives users more control and builds trust.
Permission Scenarios
Which permission(s) would you need for an extension that, when its icon is clicked, reads the current page's title and then injects a custom CSS file into that same page?
Advanced Permissions Summary
Great job! You've learned about powerful advanced permissions:
- Host Permissions: Grant access to specific websites.
activeTab: Provides temporary host permissions to the active tab upon user invocation, ideal for one-off actions.scripting: Enables programmatic injection of JavaScript and CSS.
Always use the least privileged approach to ensure security and user trust. Next, we'll explore secure coding practices!
자주 묻는 질문
“고급 권한 이해하기” 강의는 무료인가요?
네 — “고급 권한 이해하기” 전체 내용을 이 웹사이트에서 무료로 읽을 수 있습니다. 인터랙티브하게 실습하려면(내장 코드 에디터와 24/7 AI 튜터), CoddyKit PRO로 업그레이드하면 Browser Extensions Development (Chrome & Edge) 강의 전체를 잠금 해제할 수 있습니다. Browser Extensions Development (Chrome & Edge) 강의에는 총 4개의 강의가 포함되어 있습니다.
“고급 권한 이해하기”에서 뭘 배우나요?
`activeTab`, `scripting` 및 호스트 권한과 같은 민감한 권한을 살펴보고, 언제 어떻게 요청해야 하는지 학습합니다. 브라우저에서 직접 실행하는 실습 코드로 Browser Extensions Development (Chrome & Edge)을(를) 배우며, 24/7 AI 튜터가 강의를 진행하면서 질문에 답변해줍니다.
Browser Extensions Development (Chrome & Edge)을(를) 시작하는 데 경험이 필요한가요?
사전 경험은 필요하지 않습니다. CoddyKit의 Browser Extensions Development (Chrome & Edge)은(는) 초급자부터 고급 학습자까지를 위해 구성되어 있으므로, 여기서 시작하거나 처음부터 시작할 수 있으며 자신의 속도대로 진행할 수 있습니다. 이것은 4개 중 1번째 강의입니다.
“고급 권한 이해하기” 강의는 얼마나 걸리나요?
대부분의 CoddyKit 강의는 약 5~10분이 소요됩니다. 각 강의는 간결하고 인터랙티브하여 꾸준한 진행이 가능하며, 웹과 앱에서 중단한 부분부터 바로 시작할 수 있습니다.
이 Browser Extensions Development (Chrome & Edge) 강의에서 코드를 작성하고 실행할 수 있나요?
네. 모든 Browser Extensions Development (Chrome & Edge) 강의에는 내장 코드 에디터가 포함되어 있으므로, 브라우저에서 바로 실제 코드를 작성하고 실행한 후 즉시 AI 피드백을 받을 수 있습니다 — 로컬 설정이 필요 없습니다.
이 강의의 모든 강의
- 고급 권한 이해하기
- 안전한 코딩 관행
- 콘텐츠 보안 정책(CSP)
- 선택적 권한과 실행 중 요청