-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharc-tabs-patch.js
More file actions
35 lines (31 loc) · 1.21 KB
/
arc-tabs-patch.js
File metadata and controls
35 lines (31 loc) · 1.21 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
// Patch chrome.tabs.query for iframe context (Arc browser)
// When sidepanel runs in an iframe, it can't find the "active tab"
// This patch intercepts the query and returns the correct tab
(function() {
const params = new URLSearchParams(window.location.search);
const tabId = parseInt(params.get("tabId"), 10);
if (!tabId || !chrome?.tabs?.query) return;
const originalQuery = chrome.tabs.query.bind(chrome.tabs);
chrome.tabs.query = function(queryInfo, callback) {
// If asking for active tab in current window, return the tab we know about
if (queryInfo && queryInfo.active && (queryInfo.currentWindow || queryInfo.lastFocusedWindow)) {
const promise = chrome.tabs.get(tabId).then(tab => {
const result = [tab];
if (callback) callback(result);
return result;
}).catch(() => {
// Fallback to original query
return originalQuery(queryInfo).then(result => {
if (callback) callback(result);
return result;
});
});
if (!callback) return promise;
return;
}
// For all other queries, use original
const result = originalQuery(queryInfo);
if (callback) result.then(callback);
return result;
};
})();