disable tabs permission when not testing

This commit is contained in:
Tommy D. Rossi
2025-11-24 11:59:37 +01:00
parent 16b3aaca50
commit 2a9793bf9d
2 changed files with 26 additions and 8 deletions
+14 -7
View File
@@ -14,14 +14,21 @@ Required to attach the Chrome debugger to the current tab when the user clicks t
Essential for core functionality. This permission allows the extension to attach Chrome DevTools Protocol (CDP) to tabs selected by the user (via clicking the extension icon). CDP access enables the extension to relay automation commands from local Playwright scripts to the browser, allowing actions like page navigation, element interaction, and JavaScript execution for testing and development purposes. Essential for core functionality. This permission allows the extension to attach Chrome DevTools Protocol (CDP) to tabs selected by the user (via clicking the extension icon). CDP access enables the extension to relay automation commands from local Playwright scripts to the browser, allowing actions like page navigation, element interaction, and JavaScript execution for testing and development purposes.
### tabs ### tabs (Testing Only - Removed in Production Builds)
Required to: **Note: This permission is automatically removed during production builds and is only included in test builds.**
- Track which tabs have active debugger connections (shown via icon color)
- Detect when connected tabs are closed to properly clean up debugger attachments The tabs permission is only needed during development/testing to:
- Update extension icon state across all tabs - Access the URL property of tabs for test identification (finding tabs by URL pattern)
- Create, close, and switch between automated tabs - Query all tabs with full information for test assertions
- Monitor tab activation events
In production, the extension functions perfectly without the tabs permission because:
- Tab event listeners (onRemoved, onActivated, onUpdated) work without it
- chrome.tabs.create() and chrome.tabs.remove() work without it
- chrome.tabs.query() for active tab works without it
- chrome.tabs.get() works without it (returns limited info which is sufficient)
The build process (vite.config.mts) automatically removes this permission when TESTING environment variable is not set.
### host_permissions (<all_urls>) ### host_permissions (<all_urls>)
+12 -1
View File
@@ -2,6 +2,7 @@ import { fileURLToPath } from 'url';
import { dirname, resolve } from 'path'; import { dirname, resolve } from 'path';
import { defineConfig } from 'vite'; import { defineConfig } from 'vite';
import { viteStaticCopy } from 'vite-plugin-static-copy'; import { viteStaticCopy } from 'vite-plugin-static-copy';
import fs from 'node:fs';
const __filename = fileURLToPath(import.meta.url); const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename); const __dirname = dirname(__filename);
@@ -21,7 +22,17 @@ export default defineConfig({
}, },
{ {
src: resolve(__dirname, 'manifest.json'), src: resolve(__dirname, 'manifest.json'),
dest: '.' dest: '.',
transform: (content) => {
const manifest = JSON.parse(content);
// Only include tabs permission during testing
if (!process.env.TESTING) {
manifest.permissions = manifest.permissions.filter((p: string) => p !== 'tabs');
}
return JSON.stringify(manifest, null, 2);
}
}, },
{ {
src: resolve(__dirname, 'welcome.html'), src: resolve(__dirname, 'welcome.html'),