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

Optional Permissions & Runtime Requests

Request permissions on demand instead of upfront to build trust, pass reviews faster, and minimize your attack surface.

Optional Permissions & Runtime Requests is a free Browser Extensions Development (Chrome & Edge) lesson on CoddyKit — lesson 4 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Browser Extensions Development (Chrome & Edge) learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.

The Problem With Asking for Everything

Requesting many permissions at install time scares users and slows store review. The principle of least privilege says request only what you need, when you need it.

Optional permissions let you ask at runtime, in context.

Required vs Optional

The manifest separates permissions (granted at install) from optional_permissions (requested later). Move anything non-essential into optional.

{
  "permissions": ["storage"],
  "optional_permissions": ["bookmarks", "history"]
}

Optional Host Permissions

Site access can also be optional. Declare it under optional_host_permissions so users grant access to specific sites only when they choose.

{
  "optional_host_permissions": ["https://*/*"]
}

Requesting at Runtime

Call permissions.request in response to a user gesture, such as a button click. The browser shows a prompt.

const granted = await chrome.permissions.request({
  permissions: ['bookmarks']
})
console.log('Granted: ' + granted)

Must Come From a User Gesture

The request prompt only appears if triggered by a direct user action. Calling it on startup or from a timer will silently fail.

Wire it to a click handler.

button.addEventListener('click', async () => {
  await chrome.permissions.request({ permissions: ['history'] })
})

Checking Before Using

Before calling an API, check whether the permission is currently granted with permissions.contains.

const has = await chrome.permissions.contains({
  permissions: ['bookmarks']
})
if (has) loadBookmarks()

Removing Permissions

Let users revoke access they no longer want with permissions.remove. This shrinks your attack surface.

await chrome.permissions.remove({ permissions: ['history'] })

Reacting to Grants and Revokes

Listen for onAdded and onRemoved to enable or disable features as permissions change.

chrome.permissions.onRemoved.addListener((p) => {
  console.log('Removed: ' + p.permissions)
})

Designing the Request Flow

Explain why you need a permission before prompting. A short sentence and a clear button earns far more grants than a surprise system dialog.

Faster Store Review

Extensions with broad install-time permissions face deeper review. Moving sensitive scopes to optional often speeds approval and reduces warning banners.

Graceful Degradation

Always handle the case where a permission is denied. Disable or hide the feature rather than throwing errors, so the rest of the extension keeps working.

if (!granted) showFallbackMessage()

Quick Check

Test your optional permissions knowledge.

Recap

You learned runtime permission requests:

  • Split required and optional_permissions
  • Request from a user gesture with permissions.request
  • Check with contains, revoke with remove
  • React to onAdded and onRemoved
  • Degrade gracefully when denied

Least-privilege design builds trust and eases store review.

Frequently asked questions

Is the “Optional Permissions & Runtime Requests” lesson free?

Yes — the full text of “Optional Permissions & Runtime Requests” is free to read here on the web, and the Browser Extensions Development (Chrome & Edge) course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Browser Extensions Development (Chrome & Edge) course, upgrade to CoddyKit PRO.

What will I learn in “Optional Permissions & Runtime Requests”?

Request permissions on demand instead of upfront to build trust, pass reviews faster, and minimize your attack surface. You practise Browser Extensions Development (Chrome & Edge) with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.

Do I need any experience to start Browser Extensions Development (Chrome & Edge)?

No prior experience is required. Browser Extensions Development (Chrome & Edge) on CoddyKit is structured for beginners through advanced learners; this is — lesson 4 of 4, so you can start here or from the beginning and move at your own pace.

How long does the “Optional Permissions & Runtime Requests” lesson take?

Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.

Can I write and run code in this Browser Extensions Development (Chrome & Edge) lesson?

Yes. Every Browser Extensions Development (Chrome & Edge) lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.

All lessons in this course

  1. Understanding Advanced Permissions
  2. Secure Coding Practices
  3. Content Security Policy (CSP)
  4. Optional Permissions & Runtime Requests
← Back to Browser Extensions Development (Chrome & Edge)