This project is a complete, working example of a real-time chat application that communicates between a native macOS application (built with Swift and SwiftUI) and a Google Chrome extension (built with JavaScript, HTML, and CSS).
It serves as a clear, modern template for developers looking to implement Chrome's Native Messaging API on macOS. The user interfaces for both the app and the extension popup.
- Real-time Bidirectional Communication: Send messages from the Chrome extension to the macOS app, and vice-versa.
- macOS App:
- Swift
- SwiftUI
- Combine Framework for state management
- Chrome Extension:
- JavaScript (ES6)
- HTML5
- CSS3
- Communication Protocol:
- Native Messaging API (using Standard I/O)
- JSON for message formatting
This project includes an automated setup script to simplify the configuration process.
- Open your Terminal.
- Make the script executable by running the following command:
chmod +x setup.sh
- Execute the script:
./setup.sh
The script will handle the following automatically:
- Building the native macOS application in Xcode.
- Finding the correct path to the app executable.
- Configuring the native messaging manifest with this path.
- Installing the manifest into the required Chrome directory.
After the script finishes, it will print the final manual steps required. You just need to tell Chrome which extension is allowed to connect to the native app.
- Load the Extension: Open Chrome and go to
chrome://extensions. Enable "Developer mode" and click "Load unpacked." Select thechrome-extensiondirectory. - Copy the ID: The "Native App Communicator" will appear. Copy its Extension ID.
- Update the Manifest: Open the installed manifest file by running the
open ...command provided by the script. - Paste the ID: In the file that opens, replace
YOUR_CHROME_EXTENSION_IDwith the ID you copied. - Save the file.
- Run the macOS app from Xcode by selecting Product > Run (
Cmd+R). - In Chrome, click the extension's icon in the toolbar to open the chat popup.
- You can now send messages back and forth!