Skip to content

Commit

Permalink
Handle Chrome extension Port object
Browse files Browse the repository at this point in the history
As described here the api is of ports within an extension is onMessage.addListener and while it does respond to addEventListener, 
mixed usage is problematic since the listener set by addEventListener is overwritten.
http://developer.chrome.com/extensions/runtime.html#type-Port
  • Loading branch information
francoisfrisch committed Feb 8, 2014
1 parent eea8121 commit 6df27ea
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions adapt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ function adapt(port, origin) {
port.on("message", function (data) {
queue.put(data);
}, false);
// Chrome extension message ports
} else if (port.onMessage) {
port.onMessage.addListener(function (message) {
queue.put(message);
});
} else if (port.addEventListener) {
port.addEventListener("message", function (event) {
queue.put(event.data);
Expand Down

0 comments on commit 6df27ea

Please sign in to comment.