Index: ext/content.js |
=================================================================== |
--- a/ext/content.js |
+++ b/ext/content.js |
@@ -44,40 +44,40 @@ |
for (let message of queue) |
backgroundFrame.contentWindow.postMessage(message, "*"); |
} |
window.removeEventListener("message", loadHandler); |
} |
}; |
window.addEventListener("message", loadHandler); |
- ext.backgroundPage = { |
- _sendRawMessage(message) |
- { |
- if (messageQueue) |
- messageQueue.push(message); |
- else |
- backgroundFrame.contentWindow.postMessage(message, "*"); |
- } |
- }; |
- |
/* Polyfills */ |
if (!("runtime" in chrome)) |
chrome.runtime = {}; |
+ function sendRawMessage(message) |
+ { |
+ if (messageQueue) |
+ messageQueue.push(message); |
+ else |
+ backgroundFrame.contentWindow.postMessage(message, "*"); |
+ } |
+ |
+ chrome.runtime.connect = () => |
+ { |
+ sendRawMessage({type: "connect"}); |
+ return {onMessage: ext.onMessage}; |
+ }; |
+ |
chrome.runtime.sendMessage = (message, responseCallback) => |
{ |
let messageId = ++maxMessageId; |
- ext.backgroundPage._sendRawMessage({ |
- type: "message", |
- messageId, |
- payload: message |
- }); |
+ sendRawMessage({type: "message", messageId, payload: message}); |
if (responseCallback) |
{ |
let callbackWrapper = event => |
{ |
if (event.data.type == "response" && event.data.messageId == messageId) |
{ |
window.removeEventListener("message", callbackWrapper); |