feat(buffer): buffer messages before devTools open

Before the devTools are opened, messages should be buffered. This way they can
be delivered when the devTools are opened.
This commit is contained in:
Erin Altenhof-Long 2014-08-08 11:39:18 -07:00
parent e1cd70d98e
commit d0da55123f

View File

@ -1,6 +1,13 @@
var buffer = [];
function addToBuffer(message) {
buffer.push(message);
}
chrome.runtime.onMessage.addListener(addToBuffer);
chrome.runtime.onConnect.addListener(function(port) { chrome.runtime.onConnect.addListener(function(port) {
chrome.runtime.onMessage.removeListener(addToBuffer);
buffer.forEach(function(msg) {
port.postMessage(msg);
});
// context script > background // context script > background
chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) { chrome.runtime.onMessage.addListener(function(msg, sender, sendResponse) {
port.postMessage(msg); port.postMessage(msg);