Is there a simple conversion method for converting chrome message passing to the safari message passing syntax?

Viewed 1329

My Chrome extension uses message passing to retrieve various values from the extension's built in localstorage area on the background page.

The thing I love about chrome message passing, is it lets you include a callback function inside the sendMessage call, like so:

chrome.runtime.sendMessage({greeting: "hello"}, function(response) {
    console.log(response.farewell);   
});

and the corresponding message receiving code would look like the following (example code from the Chrome extensions documentation):

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    console.log(sender.tab ?
                "from a content script:" + sender.tab.url :
                "from the extension");
    if (request.greeting == "hello")
      sendResponse({farewell: "goodbye"});
  });

I'm trying to convert my extension to the Safari extension format, but I can't figure out how to map the Chrome sendMessage / onMessage functions to Safari's safari.self.tab.dispatchMessage(name, data) message handling functions

Is it even possible to include callback functions in Safari's dispatchMessage function call? If not, how should I work around this limitation?

1 Answers
Related