Skip to content

Commit

Permalink
Only show warning when POST error occurs
Browse files Browse the repository at this point in the history
Refs #213
  • Loading branch information
MisterPhilip committed Aug 10, 2024
1 parent 1b3647d commit 165d1d4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/devtools/panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ window.Omnibug = (() => {
let redirectHelpLink = createElement("a", {
"attributes": {
"target": "_blank",
"href": "https://omnibug.io/help/redirected-requests"
"href": "https://omnibug.io/help/redirected-requests?utm_source=omnibug&utm_medium=##BROWSER##&utm_campaign=redirect-help-warning"
},
"text": "Learn more."
}),
Expand All @@ -768,21 +768,21 @@ window.Omnibug = (() => {
});
body.appendChild(redirectWarning);

if(request.request.type === "ping" && request.request.method === "POST" && !request.request.postData) {
if(request.request.postError) {
const warningIcon = createElement("i", {
"classes": ["fas", "fa-exclamation-triangle", "request-error-icon"],
"title": "This request was not successful",
}),
pingHelpLink = createElement("a", {
"attributes": {
"target": "_blank",
"href": "https://github.com/MisterPhilip/omnibug/issues/213"
"href": "https://omnibug.io/help/post-data-error?utm_source=omnibug&utm_medium=##BROWSER##&utm_campaign=post-data-warning"
},
"text": "Learn more."
}),
pingWarning = createElement("div", {
"classes": ["toast", "toast-error"],
"text": "Due to a Chrome bug, this type of request (ping) may not display all data points sent with the request. ",
"text": "There was an error capturing the POST data. Some data points sent with the request may be missing in Omnibug. ",
"children": [pingHelpLink]
});
body.appendChild(pingWarning);
Expand Down
16 changes: 10 additions & 6 deletions src/serviceWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,21 @@ chrome.webRequest.onBeforeRequest.addListener(
"timestamp": details.timeStamp,
"type": details.type,
"url": details.url,
"postData": ""
"postData": "",
"postError": false
},
"event": "webRequest"
};

// Grab any POST data that is included
if (details.method === "POST" && details.requestBody) {
if (details.requestBody.raw && details.requestBody.raw[0]) {
data.request.postData = String.fromCharCode.apply(null, new Uint8Array(details.requestBody.raw[0].bytes));
} else if (typeof details.requestBody.formData === "object") {
data.request.postData = details.requestBody.formData;
if (details.method === "POST" && typeof details.requestBody !== "undefined") {
const body = details.requestBody;
if(typeof body.error !== "undefined" && body.error) {
data.request.postError = true;
} else if (typeof body.raw !== "undefined" && body.raw[0]) {
data.request.postData = String.fromCharCode.apply(null, new Uint8Array(body.raw[0].bytes));
} else if (typeof body.formData === "object") {
data.request.postData = body.formData;
}
}

Expand Down

0 comments on commit 165d1d4

Please sign in to comment.