2018-02-10 20:33:33 +01:00
|
|
|
|
|
|
|
module.exports = setupMetamaskMeshMetrics
|
|
|
|
|
2018-04-19 20:37:08 +02:00
|
|
|
/**
|
2018-04-19 21:12:04 +02:00
|
|
|
* Injects an iframe into the current document for testing
|
2018-04-19 20:37:08 +02:00
|
|
|
*/
|
2018-07-03 00:49:33 +02:00
|
|
|
function setupMetamaskMeshMetrics () {
|
2018-02-10 20:33:33 +01:00
|
|
|
const testingContainer = document.createElement('iframe')
|
2019-09-23 11:54:41 +02:00
|
|
|
const targetOrigin = 'https://metamask.github.io'
|
|
|
|
const targetUrl = `${targetOrigin}/mesh-testing/`
|
|
|
|
testingContainer.src = targetUrl
|
|
|
|
|
|
|
|
let didLoad = false
|
|
|
|
testingContainer.addEventListener('load', () => {
|
|
|
|
didLoad = true
|
|
|
|
})
|
|
|
|
|
2018-02-10 20:33:33 +01:00
|
|
|
console.log('Injecting MetaMask Mesh testing client')
|
|
|
|
document.head.appendChild(testingContainer)
|
2019-09-23 11:54:41 +02:00
|
|
|
|
|
|
|
return { submitMeshMetricsEntry }
|
|
|
|
|
|
|
|
function submitMeshMetricsEntry (message) {
|
|
|
|
// ignore if we haven't loaded yet
|
2019-11-20 01:03:20 +01:00
|
|
|
if (!didLoad) {
|
|
|
|
return
|
|
|
|
}
|
2019-09-23 11:54:41 +02:00
|
|
|
// submit the message
|
|
|
|
testingContainer.contentWindow.postMessage(message, targetOrigin)
|
|
|
|
}
|
2018-02-10 20:33:33 +01:00
|
|
|
}
|