trigger-corp / browser-extensions

Build and run cross-platform browser extensions from one codebase.
Other
312 stars 52 forks source link

forge.message.listen's reply message is picked up by wrong activation #35

Closed jaredsohn closed 10 years ago

jaredsohn commented 10 years ago

Here is a simplified version of my extension that exhibits the problem:

  1. Background page has:

forge.message.listen( function(scriptname, reply) { reply(true); }, function(err) { console.log(err); } );

  1. I have at least two activations that consist of the following code:

var activation_id = "$SCRIPT_NAME"; // set via tokenizing code forge.message.broadcastBackground(activation_id, activation_id, function(content) { console.log(__activation_id + " response: " + content) }, function(content) { console.log(activation_id + " response: " + content) });

Basically when I run this, my activations all talk to the background page and I would expect each to write to the console the reply they received. Unfortunately, I often experience one activation getting multiple responses and the others not getting any responses. There isn't a parameter to restrict the reply to certain listeners, but I would think that could and would be determined automatically.

jaredsohn commented 10 years ago

While troubleshooting this, I discovered the basic problem was I was misunderstanding how scope works in contentscripts (the reality is that even if contentscripts run under a different set of match criteria, they share the same scope.) Here, both contentscripts share the same __activation_id field.

Thus, I am closing this issue.