Back

Nov 15, 2024

Nov 15, 2024

Converting a Dart Google Chrome Extension to a Safari Extension

Convert your Flutter/Dart Chrome extension to Safari with this step-by-step guide using Xcode for broader reach.

Hello! I'm Mason Williams, a software engineer specializing in developing both internal and external tools and extensions. If you've developed a Google Chrome extension using Flutter and Dart, you might be considering bringing it over to Safari to cater to a broader audience. This guide will walk you through the step-by-step process of converting your existing Chrome extension into a Safari extension using Xcode.


Prerequisites

Before you begin, ensure you have the following:

  • Xcode Installed: You need Xcode to build and manage the Safari extension project.

  • Flutter/Dart Chrome Extension: Your existing extension, ready to be converted.

  • Basic Knowledge of Terminal Commands: You'll be using the command line for some steps.


1. Compile Your Chrome Extension

First, you need to compile your existing Chrome extension to generate the build/web folder, which contains the compiled version of your extension.

flutter build web

This command will compile your Flutter web app and place the output in the build/web directory.


2. Ensure Manifest Compatibility

Safari extensions use a manifest.json file similar to Chrome, but there are some differences. You'll need to adjust your manifest file to be compatible with Safari.

Create a Safari-Specific Manifest

If you ship your extension to multiple browsers, you might already have separate manifest files. Create a manifest_safari.json for Safari:

cp manifest_regular.json manifest_safari.json

Update Permissions and Features

  • Permissions: Safari may not support all the permissions that Chrome does. Review the permissions in your manifest_safari.json and remove any that are not supported.

  • Remove Unsupported Features: Safari doesn't support side panels like Chrome. Remove any "side_panel" entries from your manifest and permissions array.

Note: When you run the converter command later, it will log any potential issues with your manifest.


3. Run the Safari Web Extension Converter

Apple provides a command-line tool to help convert your web extension to a Safari extension.

Command to Generate the Xcode Project

Run the following command in your terminal:

xcrun safari-web-extension-converter /path/to/build/web \

--project-location .. \

--bundle-identifier com.yourcompany.YourExtension \

--swift \

--macos-only \

--copy-resources \

--force

Flags explained:

  • /path/to/build/web: Replace with the actual path to your build/web folder.

  • --project-location ..: Places the Xcode project one directory up from the current location.

  • --bundle-identifier: A unique identifier for your extension (e.g., com.pieces.PiecesForSafari.Extension).

  • --swift: Generates the extension using Swift.

  • --macos-only: Targets macOS only.

  • --copy-resources: Copies the resources into the Xcode project.

  • --force: Overwrites existing files if necessary.


4. Build the Xcode Project

After running the converter, Xcode should automatically open with your new project.

Building the Project

  • Using Keyboard Shortcut: Press Command + B to build the project.

  • Using Menu Bar: Navigate to Product > Build in the top menu bar.

Wait for the build to complete. Fix any build errors that may occur.


5. Enable the Extension in Safari

Now that your extension is built, you need to enable it in Safari for testing.

Steps to Enable Unsigned Extensions

  1. Open Safari.

  2. Access Safari Settings:

    1. Click on Safari > Settings in the menu bar.

    2. Or press Command + ,.

  3. Enable Developer Features:

    1. Go to the Advanced tab.

    2. Check "Show Develop menu in menu bar".

  4. Allow Unsigned Extensions:

    1. Close the settings window.

    2. Click on the new Develop menu in the menu bar.

    3. Ensure "Allow Unsigned Extensions" is checked.

Enable Your Extension

  1. Open Safari Settings Again: Click on Safari > Settings. Navigate to the Extensions tab.

  2. Activate Your Extension: Find your extension in the list. Check the box next to it to enable it.

  3. Confirm Activation: A prompt may appear asking for confirmation. Accept it.

Your extension should now be active and visible in Safari!


6. Test Your Extension

It's crucial to thoroughly test your extension to ensure all features work as expected in Safari.

  • Functionality: Check all the features and interactions.

  • Permissions: Ensure the extension has the necessary permissions.

  • UI/UX: Verify that the user interface elements display correctly.


7. Publishing Your Extension

Once you're satisfied with your extension's performance, you can proceed to publish it.

Apple Developer Program

You need to be enrolled in the Apple Developer Program to distribute your extension.

Distribute Your App

Safari extensions are distributed as part of a macOS app. Follow these steps:

  1. Select a Distribution Method: Refer to Apple's documentation on Distributing Your App for Beta Testing and Releases.

  2. Prepare for Submission: Ensure your app meets all the App Store Review Guidelines.

  3. Archive Your App: In Xcode, select Product > Archive.

  4. Upload to App Store Connect: Use the Organizer window to upload your app.

  5. Submit for Review: In App Store Connect, create a new app listing and submit your extension for review.


Additional Resources

Converting your Flutter/Dart Chrome extension to a Safari extension may seem daunting at first, but by following these steps, you can seamlessly bring your extension to a new audience. Remember to test thoroughly and adhere to Apple's guidelines to ensure a smooth review process.

Have questions or need further assistance? Feel free to join our Discord Server!

Happy Coding!

Written by

Written by

Mason Williams

Mason Williams

SHARE

SHARE

Title

Title

our newsletter

Sign up for The Pieces Post

Check out our monthly newsletter for curated tips & tricks, product updates, industry insights and more.

our newsletter

Sign up for The Pieces Post

Check out our monthly newsletter for curated tips & tricks, product updates, industry insights and more.

our newsletter

Sign up for The Pieces Post

Check out our monthly newsletter for curated tips & tricks, product updates, industry insights and more.