Skip to content

Commit

Permalink
Fixes the Kagi Summarize context menu action for Firefox users: - (#86)
Browse files Browse the repository at this point in the history
- Update background.js to attach request for activeTab permission to a user input handler, if the browser is not Chrome.
- Increment minor version numbering in manifest.json (Chrome and Firefox)

Co-authored-by: Bob <[email protected]>
  • Loading branch information
super0nashwan and Bob authored Sep 25, 2024
1 parent 4b7e88d commit 41b15a6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Kagi Search for Chrome",
"version": "0.7.1",
"version": "0.7.2",
"description": "A simple extension for setting Kagi as a default search engine, and automatically logging in to Kagi in incognito browsing windows",
"background": {
"service_worker": "src/background.js",
Expand Down
2 changes: 1 addition & 1 deletion firefox/manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 3,
"name": "Kagi Search for Firefox",
"version": "0.7.1",
"version": "0.7.2",
"description": "A simple helper extension for setting Kagi as a default search engine, and automatically logging in to Kagi in incognito browsing windows.",
"background": {
"page": "src/background_page.html"
Expand Down
8 changes: 6 additions & 2 deletions shared/src/background.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { summarizeContent, fetchSettings } from './lib/utils.js';
import { summarizeContent, fetchSettings, requestActiveTabPermission } from './lib/utils.js';

if (!globalThis.browser) {
globalThis.browser = chrome;
Expand Down Expand Up @@ -278,10 +278,14 @@ browser.contextMenus.create({
});

// Add a listener for the context menu item.
browser.contextMenus.onClicked.addListener((info, tab) => {
browser.contextMenus.onClicked.addListener(async (info, tab) => {
if (info.menuItemId === 'kagi-summarize') {
if (!IS_CHROME) { // Attach permission request to user input handler for Firefox
await requestActiveTabPermission();
}
kagiSummarize(info, tab);
} else if (info.menuItemId === 'kagi-image-search') {
kagiImageSearch(info, tab);
}
});

16 changes: 16 additions & 0 deletions shared/src/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,3 +161,19 @@ export async function getActiveTab(fetchingFromShortcut = false) {

return tab;
}

export async function requestActiveTabPermission() {
try {
const granted = await browser.permissions.request({
permissions: ['activeTab'],
});
if (!granted) {
console.error('Permission not granted for activeTab.');
return false;
}
return true;
} catch (error) {
console.error('Error requesting activeTab permission:', error);
return false;
}
}
6 changes: 2 additions & 4 deletions shared/src/popup.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fetchSettings, getActiveTab } from './lib/utils.js';
import { fetchSettings, getActiveTab, requestActiveTabPermission } from './lib/utils.js';

if (!globalThis.browser) {
globalThis.browser = chrome;
Expand Down Expand Up @@ -376,9 +376,7 @@ async function setup() {
event.preventDefault();
event.stopPropagation();

const permissionGranted = await browser.permissions.request({
permissions: ['activeTab'],
});
const permissionGranted = await requestActiveTabPermission();

if (!permissionGranted) {
alert(
Expand Down

0 comments on commit 41b15a6

Please sign in to comment.