blob: 0493921f06d21517451235bfd7e721b3a10a94d7 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
const allowedMessageTarget = 'metamask'
const allowedMessageType = 'addUnconfirmedTx'
// 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)
// setup connection with background
var metamaskPlugin = chrome.runtime.connect({name: 'metamask'})
// forward messages from inpage to background
window.addEventListener('message', receiveMessage, false);
function receiveMessage(event){
var msg = event.data
// validate message type
if (typeof msg !== 'object') return
if (msg.to !== allowedMessageTarget) return
if (msg.type !== allowedMessageType) return
// forward message
metamaskPlugin.postMessage(msg)
}
|