mirror of
https://github.com/kremalicious/metamask-extension.git
synced 2024-12-23 09:52:26 +01:00
disable localhost interception
This commit is contained in:
parent
519d4b1192
commit
dbd3b8f76f
@ -1,6 +1,6 @@
|
|||||||
const XHR = window.XMLHttpRequest
|
const XHR = window.XMLHttpRequest
|
||||||
const fauxJax = require('faux-jax')
|
// const fauxJax = require('faux-jax')
|
||||||
fauxJax.install()
|
// fauxJax.install()
|
||||||
const Web3 = require('web3')
|
const Web3 = require('web3')
|
||||||
const createPayload = require('web3-provider-engine/util/create-payload')
|
const createPayload = require('web3-provider-engine/util/create-payload')
|
||||||
const StreamProvider = require('./lib/stream-provider.js')
|
const StreamProvider = require('./lib/stream-provider.js')
|
||||||
@ -96,64 +96,64 @@ console.log('MetaMask - injected web3')
|
|||||||
//
|
//
|
||||||
|
|
||||||
|
|
||||||
console.log('MetaMask - intercepting localhost:8545 requests')
|
// console.log('MetaMask - intercepting localhost:8545 requests')
|
||||||
|
|
||||||
fauxJax.on('request', function(req){
|
// fauxJax.on('request', function(req){
|
||||||
// check if local node request
|
// // check if local node request
|
||||||
if (req.requestURL.indexOf('localhost:8545') !== -1) {
|
// if (req.requestURL.indexOf('localhost:8545') !== -1) {
|
||||||
var rpcReq = JSON.parse(req.requestBody)
|
// var rpcReq = JSON.parse(req.requestBody)
|
||||||
if (req.async) {
|
// if (req.async) {
|
||||||
remoteProvider.sendAsync(rpcReq, function(err, result){
|
// remoteProvider.sendAsync(rpcReq, function(err, result){
|
||||||
// console.log('intercepted request (async):', rpcReq, result)
|
// // console.log('intercepted request (async):', rpcReq, result)
|
||||||
handleResult(result)
|
// handleResult(result)
|
||||||
})
|
// })
|
||||||
} else {
|
// } else {
|
||||||
var result = remoteProvider.send(rpcReq)
|
// var result = remoteProvider.send(rpcReq)
|
||||||
// console.log('intercepted request (sync):', rpcReq, result)
|
// // console.log('intercepted request (sync):', rpcReq, result)
|
||||||
handleResult(result)
|
// handleResult(result)
|
||||||
}
|
// }
|
||||||
} else {
|
// } else {
|
||||||
// console.log('request continuing normally:', req.requestURL)
|
// // console.log('request continuing normally:', req.requestURL)
|
||||||
continueRequestNormally(req)
|
// continueRequestNormally(req)
|
||||||
}
|
// }
|
||||||
|
|
||||||
function handleResult(result){
|
// function handleResult(result){
|
||||||
var serializedResult = JSON.stringify(result)
|
// var serializedResult = JSON.stringify(result)
|
||||||
req.respond(200, {
|
// req.respond(200, {
|
||||||
'content-type': 'application/json',
|
// 'content-type': 'application/json',
|
||||||
}, serializedResult)
|
// }, serializedResult)
|
||||||
}
|
// }
|
||||||
})
|
// })
|
||||||
|
|
||||||
function continueRequestNormally(req){
|
// function continueRequestNormally(req){
|
||||||
var xhr = new XHR()
|
// var xhr = new XHR()
|
||||||
// set target url and method
|
// // set target url and method
|
||||||
xhr.open(req.requestMethod, req.requestURL, req.async)
|
// xhr.open(req.requestMethod, req.requestURL, req.async)
|
||||||
// set headers
|
// // set headers
|
||||||
Object.keys(req.requestHeaders || {}).forEach(function(headerKey){
|
// Object.keys(req.requestHeaders || {}).forEach(function(headerKey){
|
||||||
xhr.setRequestHeader(headerKey, req.requestHeaders[headerKey])
|
// xhr.setRequestHeader(headerKey, req.requestHeaders[headerKey])
|
||||||
})
|
// })
|
||||||
// send and call completion handler
|
// // send and call completion handler
|
||||||
if (req.async) {
|
// if (req.async) {
|
||||||
xhr.onload = copyResult
|
// xhr.onload = copyResult
|
||||||
xhr.send(req.requestBody)
|
// xhr.send(req.requestBody)
|
||||||
} else {
|
// } else {
|
||||||
xhr.send(req.requestBody)
|
// xhr.send(req.requestBody)
|
||||||
copyResult()
|
// copyResult()
|
||||||
}
|
// }
|
||||||
|
|
||||||
function copyResult() {
|
// function copyResult() {
|
||||||
var headers = extractResponseHeaders(xhr.getAllResponseHeaders())
|
// var headers = extractResponseHeaders(xhr.getAllResponseHeaders())
|
||||||
req.respond(xhr.status, headers, xhr.response)
|
// req.respond(xhr.status, headers, xhr.response)
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
function extractResponseHeaders(rawHeaders){
|
// function extractResponseHeaders(rawHeaders){
|
||||||
var headers = {}
|
// var headers = {}
|
||||||
var headerKeyValues = rawHeaders.split('\r\n').filter(Boolean)
|
// var headerKeyValues = rawHeaders.split('\r\n').filter(Boolean)
|
||||||
headerKeyValues.forEach(function(keyValue){
|
// headerKeyValues.forEach(function(keyValue){
|
||||||
var data = keyValue.split(': ')
|
// var data = keyValue.split(': ')
|
||||||
headers[data[0]] = data[1]
|
// headers[data[0]] = data[1]
|
||||||
})
|
// })
|
||||||
return headers
|
// return headers
|
||||||
}
|
// }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user