Ole Albers
Ole Albers

Reputation: 9305

Porting a chrome extension to firefox

First of all: This is no duplicate of "how to automaticly convert a chrome extension"...

I wrote a complex chrome extension which is quite popular. So a lot of people asked me to publish a firefox - version.

I am currently in a quite early state of analyzing the difficulties I might run into. I am able to map most chrome-specific commands to others in firefox.

Just one topic is unsolved until now: Chrome uses content-scripts and background-scripts.

the communication works that way: Content-Script:

chrome.runtime.sendMessage(
{
   Action: "LoadAll"
}, function(response)
{
   mySetting= response.Setting;
}
);

background-script:

chrome.runtime.onMessage.addListener(
   function(request, sender, sendResponse)
   {
      if (request.Action === "LoadAll")
            {
               sendResponse({Setting: "hello out there!"});
               return true;
            }
      )
    });

(please ignore if I might have missed a bracket)

How is this communication been done on firefox extensions? Or does FF recommend a complete different approach?

If there is no "Take this command" - answer, a link to a more in-depth-explanation would be nice.

Upvotes: 2

Views: 1302

Answers (1)

Dmitrii Sorin
Dmitrii Sorin

Reputation: 4026

The thing you are looking for is Message Manager. We are developing a big and complicated extension for about 2 years for Fx and recently made a good Chrome port of it. Messaging process differs strongly in Fx and Chrome. Think of it like you inject a content script in window/browser/tab, which has few things in common with content scripts in Chrome, and then talk to your extension code from injected script via sendSyncMessage/sendAsyncMessage. I hope this helps.

Upvotes: 2

Related Questions