-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
91 lines (76 loc) · 2.43 KB
/
background.js
File metadata and controls
91 lines (76 loc) · 2.43 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
console.log("Background script initialized");
let currentTabUrl = "";
const logToken = (data) => {
try {
for (let header of data.requestHeaders) {
if (header.name.toLowerCase() === "authorization") {
chrome.storage.sync.set({
token: header,
currentTabUrl: currentTabUrl,
}).catch(err => console.error("Storage error:", err));
return;
}
}
} catch (error) {
console.error("Error in logToken:", error);
}
};
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
try {
if (changeInfo.status === "complete" && tab.url) {
currentTabUrl = tab.url;
}
} catch (error) {
console.error("Error in tab update listener:", error);
}
});
chrome.webRequest.onSendHeaders.addListener(
(data) => {
logToken(data);
},
{
urls: [
"https://signal-api.kalvium.community/*",
"https://assessment-api.kalvium.community/api/assessments/*",
],
},
["requestHeaders"]
);
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === "bypassFullscreen") {
(async () => {
try {
console.log("Bypass fullscreen request received");
const currentTab = sender.tab;
if (!currentTab || !currentTab.id) {
console.error("No tab found in sender");
sendResponse({ success: false, error: "No tab found" });
return;
}
console.log("Current tab:", currentTab.id);
const allTabs = await chrome.tabs.query({ currentWindow: true });
let targetTab = allTabs.find((tab) => tab.id !== currentTab.id);
if (!targetTab) {
console.log("Creating new tab");
targetTab = await chrome.tabs.create({
url: "about:blank",
active: true,
});
} else {
console.log("Switching to existing tab:", targetTab.id);
await chrome.tabs.update(targetTab.id, { active: true });
}
await new Promise((resolve) => setTimeout(resolve, 1500));
console.log("Switching back to quiz tab");
await chrome.tabs.update(currentTab.id, { active: true });
sendResponse({ success: true });
} catch (error) {
console.error("Bypass fullscreen error:", error);
sendResponse({ success: false, error: error.message });
}
})();
return true;
}
console.log("Unknown action received:", request.action);
return false;
});