-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsw-patch.js
More file actions
94 lines (86 loc) · 3 KB
/
sw-patch.js
File metadata and controls
94 lines (86 loc) · 3 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Service Worker Patch for Arc Browser
// Intercepts sidePanel API calls and redirects to floating panel
// Detect if sidePanel API is unavailable (Arc browser)
const _isSidePanelSupported =
typeof chrome !== "undefined" &&
typeof chrome.sidePanel !== "undefined" &&
typeof chrome.sidePanel.open === "function";
if (!_isSidePanelSupported) {
console.log("[Claude Arc Patch] sidePanel API not available, using floating panel");
// Monkey-patch chrome.sidePanel if it doesn't exist
if (!chrome.sidePanel) {
chrome.sidePanel = {};
}
// Override sidePanel.open to send message to content script
chrome.sidePanel.open = async function (options) {
const tabId = options?.tabId;
if (tabId) {
try {
await chrome.tabs.sendMessage(tabId, { type: "TOGGLE_FLOATING_PANEL" });
} catch (e) {
console.warn("[Claude Arc Patch] Could not send to tab:", e.message);
}
} else {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab?.id) {
try {
await chrome.tabs.sendMessage(tab.id, { type: "TOGGLE_FLOATING_PANEL" });
} catch (e) {
console.warn("[Claude Arc Patch] Could not send to tab:", e.message);
}
}
}
};
// Override sidePanel.setOptions (no-op for Arc)
chrome.sidePanel.setOptions = async function () {};
chrome.sidePanel.setPanelBehavior = async function () {};
chrome.sidePanel.getOptions = async function () {
return { enabled: true };
};
chrome.sidePanel.getPanelBehavior = async function () {
return { openPanelOnActionClick: true };
};
}
// Handle extension icon click
// Handle tab ID requests from content script
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.type === "GET_TAB_ID") {
sendResponse({ tabId: sender.tab?.id || 0 });
return true;
}
});
// Toggle floating panel via icon click
chrome.action.onClicked.addListener(async (tab) => {
if (!tab?.id) return;
try {
await chrome.tabs.sendMessage(tab.id, { type: "TOGGLE_FLOATING_PANEL" });
} catch (e) {
try {
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["floating-panel.js"]
});
await new Promise(r => setTimeout(r, 100));
await chrome.tabs.sendMessage(tab.id, { type: "TOGGLE_FLOATING_PANEL" });
} catch (e2) {}
}
});
// Handle keyboard shortcut
chrome.commands.onCommand.addListener(async (command) => {
if (command === "toggle-side-panel") {
const [tab] = await chrome.tabs.query({ active: true, lastFocusedWindow: true });
if (!tab?.id) return;
try {
await chrome.tabs.sendMessage(tab.id, { type: "TOGGLE_FLOATING_PANEL" });
} catch (e) {
try {
await chrome.scripting.executeScript({
target: { tabId: tab.id },
files: ["floating-panel.js"]
});
await new Promise(r => setTimeout(r, 100));
await chrome.tabs.sendMessage(tab.id, { type: "TOGGLE_FLOATING_PANEL" });
} catch (e2) {}
}
}
});