Skip to content

Commit

Permalink
fix: prevent mobile to desktop version redirect (#64)
Browse files Browse the repository at this point in the history
Co-authored-by: Arnaud Ligny <arnaud@ligny.org>
  • Loading branch information
logeen and ArnaudLigny authored Nov 9, 2023
1 parent 5ee3395 commit dbc3198
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "f-notifier",
"version": "2.8.2",
"version": "2.8.3",
"description": "Displays your Facebook notifications unread count.",
"homepage": "https://dev.ligny.org/F-Notifier",
"author": "Arnaud Ligny",
Expand Down
18 changes: 18 additions & 0 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,28 @@ function openFacebookHomeInTab(tab) {
});
}

function rewriteUserAgentHeader(event) {
for (const header of event.requestHeaders) {
if (header.name.toLowerCase() === 'user-agent') {
// Prevent mobile to desktop version redirect
header.value = header.value.replace(/\schrome\/[\d.]+/i, '$& Mobile').replace(/;\s*rv:[\d.]+/i, '; Mobile$&');
}
}

return {requestHeaders: event.requestHeaders};
}

/**
* Events
*/

// Chrome request
chrome.webRequest.onBeforeSendHeaders.addListener(
rewriteUserAgentHeader,
{urls: [FETCH_URL]},
['blocking', 'requestHeaders'],
);

// Chrome alarm
chrome.alarms.create({delayInMinutes: 1, periodInMinutes: 1});
chrome.alarms.onAlarm.addListener(updateBadge);
Expand Down
4 changes: 3 additions & 1 deletion src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "__MSG_extName__",
"version": "2.8.2",
"version": "2.8.3",
"description": "__MSG_extDescription__",
"homepage_url": "https://dev.ligny.org/F-Notifier",
"author": "Arnaud Ligny",
Expand All @@ -13,6 +13,8 @@
"permissions": [
"alarms",
"tabs",
"webRequest",
"webRequestBlocking",
"https://m.facebook.com/"
],
"background": {
Expand Down

0 comments on commit dbc3198

Please sign in to comment.