added permissions for website

This commit is contained in:
2024-11-04 11:55:14 -05:00
parent 5c845ffe61
commit 014e4c8b7b
19 changed files with 507 additions and 71 deletions
+32
View File
@@ -5,6 +5,8 @@ import { addEl, isValidURL } from "./misc.js";
import { startinject } from "./ipc.js";
import intercept, { noworker } from "../serverJS/intercept.js";
import loggermod from '../utils/logger.cjs';
import { askUserQuestion, getSitePerms, promptForPerms, setSitePerms } from "./dialogue.js";
import { getCurrentWindow } from "../serverJS/tabs_server.js";
const { logger } = loggermod;
@@ -66,6 +68,36 @@ export async function createWebview(tabId, currentWindow, customSession, preload
startinject(view, uid);
});
let perms;
const refreshperms = async (_, u) => {
perms = await getSitePerms(null, isValidURL(u)?.hostname);
}
view.webContents.on('did-navigate', refreshperms);
view.webContents.setWindowOpenHandler((details) => {
// let run out for an automatic "deny"
const hostname = isValidURL(view.webContents.getURL())?.hostname;
if (!perms) promptForPerms(getCurrentWindow(), hostname).then(() => refreshperms(null, hostname));
// else if (perms['popups'] === 'ask') askUserQuestion(view, 'allow popups', `allow popups from ${hostname}`)
else {
const permsJSON = JSON.parse(perms);
if (permsJSON['popups'] === 'ask') {
askUserQuestion(getCurrentWindow(), 'safety prompt', `allow ${hostname} to open popups?`)
.then(allowed => setSitePerms(null, hostname, 'popups', allowed ? 'allow' : 'deny'))
.catch(console.error)
.finally(() => refreshperms(null, hostname));
}
if (permsJSON['popups'] === 'allow') return { action: 'allow' };
}
// fall through
return { action: 'deny' };
});
view.webContents.setBackgroundThrottling(true);
resizeWebView();
return view;