-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
30 lines (27 loc) · 907 Bytes
/
Copy pathbackground.js
File metadata and controls
30 lines (27 loc) · 907 Bytes
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
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.local.set({ password: null }, () => {
console.log("Password not set yet.");
});
});
chrome.action.onClicked.addListener(() => {
chrome.tabs.create({ url: chrome.runtime.getURL("index.html") });
});
chrome.runtime.onStartup.addListener(() => {
chrome.storage.local.get("password", (result) => {
if (result.password) {
const userPassword = prompt("Enter your password to access the browser:");
if (userPassword !== result.password) {
alert("Incorrect password! The browser will now close.");
closeBrowser();
}
}
});
});
function closeBrowser() {
// Note: Directly closing the browser is not supported for security reasons. Here, we can close all tabs as a workaround.
chrome.tabs.query({}, function (tabs) {
for (let tab of tabs) {
chrome.tabs.remove(tab.id);
}
});
}