Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firefox MV3 Migration #462

Merged
merged 17 commits into from
May 22, 2024
Prev Previous commit
Next Next commit
Host permission handler
  • Loading branch information
Mattm27 committed Mar 24, 2024
commit 2626a56a37208f861cbf2850ba8945c9e2e7368c
26 changes: 26 additions & 0 deletions src/background/control.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,32 @@ function disable() {
}
]);
}
// Check if the browser is Firefox
if (typeof browser !== 'undefined') {
async function requestPermissions() {
try {
// Request permissions
const response = await browser.permissions.request({
origins: ["<all_urls>"] // Allows host permissions
});

// Check if permissions were granted or refused
if (response) {
console.log("Permissions were granted");
} else {
console.log("Permissions were refused");
}

// Retrieve current permissions after the request
const currentPermissions = await browser.permissions.getAll();
console.log(`Current permissions:`, currentPermissions);
} catch (error) {
console.error('Error requesting permissions:', error);
}
}
// Call the function to open the onboarding tab and request permissions
requestPermissions();
}
// Initializes the default settings
let settingsDB = await storage.getStore(stores.settings);
for (let setting in defaultSettings) {
Expand Down
4 changes: 3 additions & 1 deletion src/popup/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@
</div>

<hr id="divider-10" class="divide" style="margin: 0px" />

<body>
<button id="requestPermissionsButton">Request Permissions</button>
</body>
<!-- Dark Mode -->
<div uk-grid class="uk-margin-top" style="margin-bottom: 4%">
<div
Expand Down
27 changes: 27 additions & 0 deletions src/popup/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -767,3 +767,30 @@ document.getElementById("domain-list").addEventListener("click", async () => {
await storage.set(stores.settings, true, "DOMAINLIST_PRESSED");
chrome.runtime.openOptionsPage();
});

document.addEventListener('DOMContentLoaded', function () {
const requestPermissionsButton = document.getElementById('requestPermissionsButton');
requestPermissionsButton.addEventListener('click', requestPermissions);
});

async function requestPermissions() {
try {
// Request permissions
const response = await browser.permissions.request({
origins: ["<all_urls>"] // Allows host permissions
});

// Check if permissions were granted or refused
if (response) {
console.log("Permissions were granted");
} else {
console.log("Permissions were refused");
}

// Retrieve current permissions after the request
const currentPermissions = await browser.permissions.getAll();
console.log(`Current permissions:`, currentPermissions);
} catch (error) {
console.error('Error requesting permissions:', error);
}
}