User Agents

Web browsers and everyday web tech, explained

Create Your Own Safari Extension: A Step-by-Step Guide

· 6 min read · Extensions

In this article
  1. Background: How Safari Extensions Have Evolved
  2. What You Need to Get Started
  3. Method 1: Converting an Existing Web Extension
  4. Method 2: Building a Safari Extension from Scratch
  5. How to Test Your Extension Locally
  6. Common Problems and How to Fix Them
  7. Distribution Options: App Store vs. Direct
  8. Comparing Safari Extensions to Other Browsers
  9. Frequently Asked Questions

Yes, you can create your own Safari extension, and the process is more accessible than you might think, especially with the introduction of Xcode 12 and later. This guide walks you through the two main approaches—using the modern Web Extension API or the older Safari App Extensions—and provides concrete steps, background, and troubleshooting advice.

Background: How Safari Extensions Have Evolved

For years, Safari extensions were built with a proprietary Objective-C or JavaScript framework that required a Mac developer certificate and often a paid Apple Developer Program membership to distribute outside the Mac App Store. In 2020, Apple aligned Safari with the web standard by adopting the Web Extension API, which is the same API used by Chrome, Firefox, and Edge. This shift means that if you already have a Chrome extension, you can port it to Safari with minimal changes. Apple also introduced App Extensions (a separate technology) for deeper system integration, but for most browser enhancements, the Web Extension API is the recommended path.

What You Need to Get Started

Before you begin, ensure you have the following:

  • A Mac running macOS Monterey (12.0) or later for the latest Xcode tools.
  • Xcode installed from the Mac App Store (free).
  • An Apple ID (free) for local testing; a paid Apple Developer Program membership ($99/year) is only required to distribute through the App Store.
  • Basic knowledge of HTML, CSS, and JavaScript.

You do not need a separate Safari developer account—Xcode handles the conversion and packaging.

Method 1: Converting an Existing Web Extension

If you already have a Chrome or Firefox extension, Apple provides a command-line tool called safari-web-extension-converter that does most of the work. Here’s the step-by-step process:

  1. Open Terminal on your Mac.
  2. Run the converter with the path to your extension folder: safari-web-extension-converter /path/to/extension. The tool creates a new Xcode project with the same name.
  3. Open the generated .xcodeproj in Xcode.
  4. Set your development team under the project’s Signing & Capabilities tab (use your Apple ID).
  5. Select the “Safari Extension” scheme (usually named after your extension) and run it. Safari will launch with the extension installed and enabled for development.

The converter automatically handles manifest conversion, but you may need to adjust permissions or API calls that Safari doesn’t support (e.g., chrome.tabs is supported, but some newer APIs like chrome.scripting require Safari 15.4+).

Method 2: Building a Safari Extension from Scratch

If you’re starting fresh, you can create a new Xcode project with the Safari Extension template:

  1. Open Xcode and choose “New Project.”
  2. Select “Safari Extension” under the “Extension” section (you’ll also get a containing app—this is required even if the app is just a shell).
  3. Name your project and ensure “Include UI Extension” is checked if you want a popover toolbar button.
  4. Xcode generates a folder structure with Resources (for your manifest.json, scripts, and styles) and a SafariWebExtensionHandler.swift file for native-to-web communication.
  5. Edit the manifest.json to define your extension’s permissions, content scripts, and background scripts. The structure is identical to Chrome’s manifest v2 or v3 (Safari supports both, but v3 is recommended).
  6. Write your JavaScript in the Resources folder. For example, a content script that changes page background color:
// content.js
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
  if (message.action === 'changeColor') {
    document.body.style.backgroundColor = 'lightblue';
  }
});

Remember to declare the content script in your manifest under content_scripts.

How to Test Your Extension Locally

Testing is straightforward:

  • In Xcode, run your extension scheme (the one with the Safari Extension name). This opens Safari with your extension loaded.
  • Enable the extension in Safari’s Preferences → Extensions tab (it may be off by default).
  • Use the Develop menu in Safari to inspect the extension’s popover or content scripts. You can also set breakpoints in Xcode for native code.
  • For debugging JavaScript, open Safari’s Web Inspector (Develop → Show Web Inspector) and select the extension’s context from the dropdown.

If your extension doesn’t appear, check that the containing app is running (it must be launched at least once) and that you’ve set the correct signing team.

Common Problems and How to Fix Them

Here are typical issues you might encounter:

  • Extension not showing in Safari: Ensure the containing app is not in the Trash and is running. Also, check that the extension is enabled in Safari’s Preferences.
  • Manifest errors: Safari is strict about certain keys. For instance, background.scripts (v2) is fine, but background.service_worker (v3) requires Safari 15.4+. Use the correct version for your target.
  • Permissions not working: If a content script isn’t injecting, verify the matches pattern in your manifest. For example, "https://*/*" matches all HTTPS pages.
  • Popover not appearing: If you have a toolbar popover, ensure the default_popup path in your manifest points to a valid HTML file.
  • Build fails with signing errors: Set your development team in the project settings. For local testing, you don’t need a paid account, but you must select your personal team.

Distribution Options: App Store vs. Direct

You have two main ways to share your extension:

  • Mac App Store: This is the only official way to distribute to the public without requiring users to enable “Allow unsigned extensions.” You must be a member of the Apple Developer Program ($99/year) and submit your containing app for review. The review process checks for privacy, security, and compliance with App Store guidelines.
  • Direct Distribution: You can share the built .app file directly, but users must right-click and choose “Open” to bypass Gatekeeper, and they must enable “Allow extensions from unidentified developers” in Safari’s settings. This is suitable for personal use or enterprise distribution.

Note that Safari extensions are only available on macOS; iOS/iPadOS support extensions but require a different packaging (App Extensions) and are always distributed via the App Store.

Comparing Safari Extensions to Other Browsers

The Web Extension API is largely cross-browser, but there are differences:

  • API Support: Safari supports most chrome.* APIs, but some like chrome.identity (OAuth) are not available. You’ll need to use native code for authentication.
  • Manifest Version: Safari 14 supports manifest v2; Safari 15.4+ supports v3. Chrome is phasing out v2, so plan accordingly.
  • UI Differences: Safari’s toolbar popover is more limited than Chrome’s—you can’t have a multi-column popup, and the size is fixed.
  • Performance: Safari extensions run in a separate process and have stricter memory limits, so heavy extensions may need optimization.

Despite these differences, the core JavaScript and HTML logic is portable, making it easy to maintain a cross-browser extension.

Frequently Asked Questions

Do I need a Mac to create a Safari extension?

Yes, you need a Mac because Xcode is only available on macOS. You can write the code on any OS, but building and testing requires a Mac.

Can I make money from a Safari extension?

Yes, you can sell your extension on the Mac App Store. However, Apple takes a 30% commission on paid apps (15% for small businesses earning under $1 million per year). You can also offer it free and use donations or a subscription model via in-app purchase.

How long does it take to create a simple Safari extension?

If you’re familiar with web development, a basic extension (like a URL shortener or a page highlighter) can take a few hours. Porting an existing Chrome extension can take under an hour if you don’t hit API compatibility issues.

Can I update my extension after it’s on the App Store?

Yes, you can submit new versions. Each update goes through review, but minor changes are usually approved quickly. Users will receive the update automatically if they have automatic updates enabled.

Why is my extension not working on some websites?

This is often due to Content Security Policy (CSP) restrictions on the website, which can block injected scripts. You can work around this by using chrome.scripting.executeScript with world: 'MAIN' (in v3) or by requesting the all_urls permission, but be aware of privacy implications.

Is it possible to create an extension for Safari on iPhone or iPad?

Yes, but it’s a different process. You need to create an App Extension that includes a Safari extension, and it must be distributed through the App Store. The Web Extension API is not supported on iOS; you’ll use native code and JavaScript with the Safari App Extension framework.