Repository navigation
Expand file tree
/
Copy pathbackground.js
More file actions
54 lines (47 loc) · 1.56 KB
/
Copy pathbackground.js
File metadata and controls
54 lines (47 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Log extension initialization for debugging
console.log('Tailgunner extension initialized');
/**
* Toggles the Tailgunner panel in the active tab
* @param {chrome.tabs.Tab} tab - The active browser tab
*/
function toggleTailgunnerPanel(tab) {
// Validate tab object and ID
if (!tab) {
console.error('Tailgunner: No active tab found');
return;
}
if (!tab.id) {
console.error('Tailgunner: Invalid tab ID');
return;
}
// Check for restricted URLs where content scripts can't run
if (tab.url && (tab.url.startsWith('chrome://') || tab.url.startsWith('edge://') || tab.url.startsWith('about:'))) {
console.warn(`Tailgunner: Cannot access restricted page: ${tab.url.substring(0, 30)}...`);
return;
}
// Send message to content script with proper error handling
try {
chrome.tabs.sendMessage(
tab.id,
{ action: 'toggle-panel' },
(response) => {
// Handle response from content script
if (chrome.runtime.lastError) {
console.warn('Tailgunner: Error sending message:', chrome.runtime.lastError.message);
return;
}
if (response) {
if (response.success) {
console.log('Tailgunner: Panel toggled successfully');
} else if (response.error) {
console.warn('Tailgunner: Content script reported an error:', response.error);
}
}
}
);
} catch (error) {
console.error('Tailgunner: Fatal error:', error.message);
}
}
// Register the click handler
chrome.action.onClicked.addListener(toggleTailgunnerPanel);