Skip to content

Commit

Permalink
Fixing chrome issue and dark mode
Browse files Browse the repository at this point in the history
  • Loading branch information
pasu authored and pasu committed Mar 3, 2020
1 parent 8892297 commit 11e541f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 24 deletions.
36 changes: 14 additions & 22 deletions devtools/devtools.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,58 +32,50 @@ function checkURLTagged(url, replaceData) {
}

function submitResponse(filteredData, continueParams) {
let responseLines = [];
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);
continueParams.responseCode = 200;
continueParams.binaryResponseHeaders = btoa(`Content-Type: ${filteredData.contentType}`);
continueParams.body = btoa(unescape(encodeURIComponent(filteredData.replace)));
chrome.debugger.sendCommand(debugee, 'Fetch.fulfillRequest', continueParams);
}

let debugee = null;
function setupDebugger(target) {
debugee = { tabId: target.id };

chrome.debugger.attach(debugee, "1.0", () => {
chrome.debugger.sendCommand(debugee, "Network.setRequestInterception", { patterns: [{ urlPattern: '*' }] });
chrome.debugger.sendCommand(debugee, "Fetch.enable", { patterns: [{ urlPattern: '*' }] });
});

chrome.debugger.onEvent.addListener((source, method, params) => {
var request = params.request;
var continueParams = {
interceptionId: params.interceptionId,
requestId: params.requestId,
};
if (source.tabId === target.id) {
if (method === "Network.requestIntercepted") {
if (method === "Fetch.requestPaused") {
chrome.storage.local.get("replaceData", (storageData) => {
let filteredData = checkURLTagged(params.request.url, storageData.replaceData);
if (filteredData.length > 0) {
var responseLines = [];
responseLines.push('HTTP/1.1 200 OK');
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);
continueParams.responseCode = 200;
continueParams.binaryResponseHeaders = btoa(unescape(encodeURIComponent(data.getAllResponseHeaders())));
continueParams.body = btoa(unescape(encodeURIComponent(replacedData)));
chrome.debugger.sendCommand(debugee, 'Fetch.fulfillRequest', continueParams);
});
}, (status) => {
responseLInes[0] = `HTTP/1.1 ${status}`;
continecontinueParams.rawResponse = btoa(responseLines.join('\r\n'));
chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams);
chrome.debugger.sendCommand(debugee, 'Fetch.continueRequest', continueParams);
});
}
} else {
chrome.debugger.sendCommand(debugee, 'Network.continueInterceptedRequest', continueParams);
chrome.debugger.sendCommand(debugee, 'Fetch.continueRequest', continueParams);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Chrome Response Override",
"short_name": "Chrome Response Override",
"version": "1.3",
"version": "1.4",
"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",
Expand Down
2 changes: 1 addition & 1 deletion panel/panel.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
tr:nth-child(even) {background-color:#dee4dc;}
</style>
</head>
<body>
<body style="background: #f0ffff">
<div>
<span style="display:table-cell;padding:10px;">
<image style="height:32px" src="../images/icon.png">
Expand Down

0 comments on commit 11e541f

Please sign in to comment.