diff options
builds smoothly + forwards txs to extension
Diffstat (limited to 'app/scripts/contentscript.js')
-rw-r--r-- | app/scripts/contentscript.js | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/app/scripts/contentscript.js b/app/scripts/contentscript.js index 2e50ae3a5..53ec9eef5 100644 --- a/app/scripts/contentscript.js +++ b/app/scripts/contentscript.js @@ -1,16 +1,25 @@ -const web3 = require('web3') +const messageType = 'metamaskMessage' -// inject script tag + +// inject in-page script var scriptTag = document.createElement('script') -scriptTag.src = chrome.extension.getURL('scripts/web3.js') -scriptTag.onload = function() { debugger; this.parentNode.removeChild(this) } +scriptTag.src = chrome.extension.getURL('scripts/inpage.js') +scriptTag.onload = function() { this.parentNode.removeChild(this) } var container = document.head || document.documentElement container.appendChild(scriptTag) // listen for messages -var port = chrome.runtime.connect({name: 'metamask'}) -port.postMessage({joke: 'Knock knock'}) -port.onMessage.addListener(function(msg) { - console.log(msg) - // port.postMessage({answer: 'Madame'}) -})
\ No newline at end of file +var metamaskPlugin = chrome.runtime.connect({name: 'metamask'}) +// metamaskPlugin.onMessage.addListener(function(msg) { +// console.log(msg) +// }) + +window.addEventListener('message', receiveMessage, false); +function receiveMessage(event){ + var msg = event.data + // validate message type + if (typeof msg !== 'object') return + if (msg.type !== messageType) return + // forward message + metamaskPlugin.postMessage(msg) +}
\ No newline at end of file |