Skip to content

Commit

Permalink
fix: should set User-Agent in axios for Firefox
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtemSBulgakov committed Jun 21, 2024
1 parent 4b4efa7 commit 6699bd8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/entrypoints/background/net-rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import Rule = chrome.declarativeNetRequest.Rule
import RuleActionType = chrome.declarativeNetRequest.RuleActionType

export async function applyUserAgentRule() {
// Set "MoodleMobile" User-Agent for requests to get_autologin_key
// Set "MoodleMobile" User-Agent for requests to get_autologin_key.
// This doesn't work in Firefox, so we need to set User-Agent in Axios.
const ua_rule: Rule = {
id: 1,
action: {
Expand Down
6 changes: 3 additions & 3 deletions src/shared/moodle-ws-api/axios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ export const AxiosWS = axios.create({
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
// Browser doesn't allow to set User-Agent here.
// Extension should use declarativeNetRequest rules.
// "User-Agent": "MoodleMobile",
// Chrome prohibits to set User-Agent here. We should use declarativeNetRequest rules.
// But Firefox allows to set User-Agent here.
'User-Agent': 'MoodleMobile',
},
})

Expand Down

0 comments on commit 6699bd8

Please # to comment.