Skip to content

Commit 1d487d0

Browse files
authored
Merge pull request #293 from ouuan/firefox-api-permissions
Request host permissions for custom API servers on Firefox
2 parents cd51f43 + 6d11ab6 commit 1d487d0

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/manifests/firefox.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"chrome_style": false,
3939
"page": "options.html"
4040
},
41-
"permissions": ["alarms", "tabs", "storage", "activeTab"],
41+
"permissions": ["alarms", "tabs", "storage", "activeTab", "https://api.wakatime.com/*", "https://wakatime.com/*"],
42+
"optional_permissions": ["<all_urls>"],
4243
"version": "4.0.12"
4344
}

src/utils/settings.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,12 @@ export const getSettings = async (): Promise<Settings> => {
8181
};
8282

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

8792
export const getApiUrl = async () => {

0 commit comments

Comments
 (0)