-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
94 lines (79 loc) · 2.72 KB
/
main.js
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
const { app, BrowserWindow, session } = require('electron')
const path = require('path')
require('dotenv').config()
// Suppress security warnings
process.env.ELECTRON_DISABLE_SECURITY_WARNINGS = 'true';
let mainWindow = null
function createWindow () {
mainWindow = new BrowserWindow({
width: 1200,
height: 800,
title: 'Perplexity Finance',
webPreferences: {
nodeIntegration: false,
contextIsolation: true,
webviewTag: true,
webSecurity: true,
preload: path.join(__dirname, 'preload.js')
}
})
// Configure session
const webviewSession = session.fromPartition('persist:perplexity')
// Set persistent permissions
webviewSession.setPermissionRequestHandler((webContents, permission, callback) => {
callback(true)
})
// Configure headers and cookies
webviewSession.webRequest.onBeforeSendHeaders((details, callback) => {
callback({
requestHeaders: {
...details.requestHeaders,
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Upgrade-Insecure-Requests': '1'
}
})
})
// Configure CSP and other response headers
webviewSession.webRequest.onHeadersReceived((details, callback) => {
callback({
responseHeaders: {
...details.responseHeaders,
'Content-Security-Policy': ["default-src * 'unsafe-inline' 'unsafe-eval' data: blob:; connect-src *; worker-src blob: 'self'; img-src * data: blob:"]
}
})
})
// Enable cookies
webviewSession.cookies.set({
url: 'https://www.perplexity.ai',
name: 'session_persist',
value: 'true',
domain: '.perplexity.ai',
path: '/'
}).catch(console.error)
mainWindow.loadFile('index.html')
mainWindow.on('closed', () => {
mainWindow = null
})
}
// Enable required switches
app.commandLine.appendSwitch('ignore-certificate-errors')
app.commandLine.appendSwitch('disable-site-isolation-trials')
app.whenReady().then(() => {
createWindow()
app.on('activate', () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow()
}
})
})
app.on('window-all-closed', () => {
if (process.platform !== 'darwin') {
app.quit()
}
})
// Handle any uncaught exceptions
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error)
})