aboutsummaryrefslogblamecommitdiffstats
path: root/app/scripts/contentscript.js
blob: 53ec9eef56d68e5ea495ac76d62a853ff4a2210a (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
                                     
 

                        
                                                

                                                                   



                                                         













                                                               
const messageType = 'metamaskMessage'


// inject in-page script
var scriptTag = document.createElement('script')
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 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)
}