diff --git a/devtools/devtools.js b/devtools/devtools.js index f217d36..7617872 100644 --- a/devtools/devtools.js +++ b/devtools/devtools.js @@ -31,6 +31,18 @@ function checkURLTagged(url, replaceData) { return replaceData.filter(replaceDatum => url.includes(replaceDatum.url)); } +function submitResponse(filteredData, continueParams) { + let responseLines = []; + if (filteredData.contentType) { + responseLines.push(`Content-Type: ${filteredData.contentType}`); + } + responseLines.push(''); + responseLines.push(''); + responseLines.push(filteredData.replace); + continueParams.rawResponse = btoa(unescape(encodeURIComponent(responseLines.join('\r\n')))); + chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); +} + let debugee = null; function setupDebugger(target) { debugee = { tabId: target.id }; @@ -51,21 +63,25 @@ function setupDebugger(target) { if (filteredData.length > 0) { var responseLines = []; responseLines.push('HTTP/1.1 200 OK'); - ajaxMe(request.url, (data) => { - replaceResponse(data.response, filteredData, (replacedData) => { - let headers = data.getAllResponseHeaders(); - responseLines.push(headers); - responseLines.push(''); - responseLines.push(''); - responseLines.push(replacedData); - continueParams.rawResponse = btoa(unescape(encodeURIComponent(responseLines.join('\r\n')))); + if (filteredData[0].find === '~NO_API~') { + submitResponse(filteredData[0], continueParams) + } else { + ajaxMe(request.url, (data) => { + replaceResponse(data.response, filteredData, (replacedData) => { + let headers = data.getAllResponseHeaders(); + responseLines.push(headers); + responseLines.push(''); + responseLines.push(''); + responseLines.push(replacedData); + continueParams.rawResponse = btoa(unescape(encodeURIComponent(responseLines.join('\r\n')))); + chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); + }); + }, (status) => { + responseLInes[0] = `HTTP/1.1 ${status}`; + continecontinueParams.rawResponse = btoa(responseLines.join('\r\n')); chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); }); - }, (status) => { - responseLInes[0] = `HTTP/1.1 ${status}`; - continecontinueParams.rawResponse = btoa(responseLines.join('\r\n')); - chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); - }); + } } else { chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams); } diff --git a/manifest.json b/manifest.json index f0aa2ce..c5a6496 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "Chrome Response Override", "short_name": "Chrome Response Override", - "version": "1.2", + "version": "1.3", "description": "Provides support to override API/HTML/* response using simple Find & Replace steps. No external app installation required", "author": "Pasupathi Rajamanickam", "devtools_page": "devtools/devtools.html", diff --git a/panel/panel.html b/panel/panel.html index 6e0bbc8..2b57292 100644 --- a/panel/panel.html +++ b/panel/panel.html @@ -31,7 +31,9 @@ - + +Wiki + @@ -40,6 +42,8 @@