Extension types
Safari Extension
Full web extensions with content scripts and background pages
Content Blocker
Declarative content blocking rules
Safari Extension
Modern Safari extensions use the WebExtensions API compatible with Chrome and Firefox extensions.Extension point
| Property | Value |
|---|---|
| Type | safari |
| Extension Point | com.apple.Safari.web-extension |
| Frameworks | None |
Creating a Safari extension
manifest.json- Extension manifestbackground.js- Background scriptcontent.js- Content scriptassets/- Extension resources
manifest.json
Background script
Content script
Native messaging
Communicate between the web extension and native iOS app:File structure
Theassets/ directory is automatically linked as resources:
Files in the top-level
assets/ directory are linked as resources. This is specific to Safari extensions.Content Blocker
Declarative content blocking without JavaScript execution.Extension point
| Property | Value |
|---|---|
| Type | content-blocker |
| Extension Point | com.apple.Safari.content-blocker |
| Frameworks | None |
Creating a content blocker
Blocking rules
Define blocking rules inblockerList.json:
Action types
| Action | Description |
|---|---|
block | Block the request |
block-cookies | Block cookies |
css-display-none | Hide elements with CSS |
ignore-previous-rules | Override previous rules |
make-https | Upgrade to HTTPS |
Trigger options
| Property | Description |
|---|---|
url-filter | Regular expression for URLs |
url-filter-is-case-sensitive | Case sensitivity |
resource-type | Types: document, image, script, stylesheet, etc. |
if-domain | Apply only on these domains |
unless-domain | Apply except on these domains |
load-type | first-party or third-party |
Loading rules
Content blocker rules are loaded automatically from the extension bundle. EnsureblockerList.json is included in the target.
Rule limits
Safari supports up to 50,000 content blocking rules per extension. Rules are compiled for performance.Permissions
Common Safari extension permissions:Testing Safari extensions
Enable Safari Developer settings
In Safari, go to Safari > Settings > Advanced and enable “Show Develop menu in menu bar”.
Best practices
Minimize permissions
Minimize permissions
- Only request permissions you actually need
- Use
activeTabinstead of<all_urls>when possible - Explain permission usage to users
Optimize performance
Optimize performance
- Keep content scripts lightweight
- Use event pages instead of persistent background pages
- Lazy load resources when needed
- Minimize DOM manipulations
Handle errors gracefully
Handle errors gracefully
- Validate all external data
- Provide fallbacks for failed operations
- Log errors for debugging
- Test on multiple websites
Troubleshooting
Extension not appearing in Safari
Extension not appearing in Safari
- Verify the extension is built and installed
- Enable “Allow Unsigned Extensions” in Safari Developer menu
- Check Safari Settings > Extensions
- Rebuild the extension target
Content script not running
Content script not running
- Check
matchespattern in manifest.json - Verify website matches the pattern
- Look for JavaScript errors in Safari Web Inspector
- Ensure manifest_version is correct
Resources not loading
Resources not loading
- Verify files are in the
assets/directory - Check file paths in manifest.json
- Rebuild after adding new files
- Check Xcode build phase includes resources
Learn more
Safari extensions guide
Detailed Safari extension guide
Target config
Configure Safari extensions
Complete target list
All extension types
Apple documentation
Official Safari Web Extensions documentation