Pleroma: username detection by request body

This commit is contained in:
Austin Huang 2023-02-26 22:25:38 -05:00
parent a92434d3da
commit 94f0903614
No known key found for this signature in database
GPG key ID: 84C23AA04587A91F
2 changed files with 8 additions and 2 deletions

View file

@ -170,7 +170,7 @@ async function onTabUpdate(tabId, changeInfo) {
function init() {
NetworkTools.webRequestListen(["http://*/*", "https://*/*"], "onBeforeRequest", (requestDetails) => {
return handleWebRequest(requestDetails).catch(handleError).catch(console.error);
});
}, ["requestBody"]);
browser.tabs.onUpdated.addListener(onTabUpdate, {
properties: ["url"]

View file

@ -110,6 +110,12 @@ export function getTootUrl(url) {
export function getUsername(url, requestDetails) {
redirectSiteFinishedLoading = false;
try {
return requestDetails.requestBody.formData.nickname[0];
} catch (e) {
console.error("Could not get username from request body. Error: ", e);
}
try {
const originUrl = new URL(requestDetails.originUrl);
const match = USER_PAGE_URL_REGEX.exec(originUrl.pathname);
@ -122,7 +128,7 @@ export function getUsername(url, requestDetails) {
console.error("Could not get valid username from request details. Got", originUrl, "from", requestDetails);
}
} catch (e) {
console.error("Could not get username from request details. Error: ", e);
console.error("Could not get username from request origin. Error: ", e);
}
// fallback to HTML scraping