Safari Extension Sending a Message To an App
-
01-07-2021 - |
Question
I'm new in making browser extensions. I need to make an extension for Safari capable of launching or sending a message to an existing app on user machine. I want to do this in Mac platform. I want to know is it possible? and if it is possible can anyone provide a sample code or a way of how can it be done?
Regards
Solution
There are at least a couple ways a Safari extension can communicate with the outside world. Probably the cleanest is for your extension to open a connection to a WebSocket server running on the local machine.
// Inside your extension's master or local .js
WebSocket ws = new WebSocket("ws://localhost/mywebserver");
ws.onopen = function () {
ws.send("Message to outside world");
};
This server could be integrated into your application using a library like libwebsockets, jWebSocket, or Socket.IO.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow