Skip to content

Commit

Permalink
Request host permissions for custom API servers on Firefox
Browse files Browse the repository at this point in the history
`content_scripts.matches` implies permissions to send cross-origin
requests on Chrome, but not on Firefox with Manifest V2. We need to
request permissions for custom API servers.
  • Loading branch information
ouuan committed Nov 11, 2024
1 parent 2aa0780 commit a934f2c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/manifests/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
"chrome_style": false,
"page": "options.html"
},
"permissions": ["alarms", "tabs", "storage", "activeTab"],
"permissions": ["alarms", "tabs", "storage", "activeTab", "https://api.wakatime.com/*", "https://wakatime.com/*"],
"optional_permissions": ["<all_urls>"],
"version": "4.0.9"
}
7 changes: 6 additions & 1 deletion src/utils/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,5 +81,10 @@ export const getSettings = async (): Promise<Settings> => {
};

export const saveSettings = async (settings: Settings): Promise<void> => {
return browser.storage.sync.set(settings);
// permissions.request must be the first await, not after the browser.storage.sync.set
// See https://stackoverflow.com/a/47729896/12601364
await browser.permissions.request({
origins: [`${settings.apiUrl}/*`],
});
await browser.storage.sync.set(settings);
};

0 comments on commit a934f2c

Please sign in to comment.