This repository has been archived by the owner on Jun 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 53
/
injection.js
45 lines (37 loc) · 2.22 KB
/
injection.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
require('./main_process_shit');
const electron = require('electron');
const path = require('path');
electron.app.commandLine.appendSwitch("no-force-async-hooks-checks");
electron.session.defaultSession.webRequest.onHeadersReceived(function(details, callback) {
if (!details.responseHeaders['content-security-policy-report-only'] && !details.responseHeaders['content-security-policy']) return callback({cancel: false});
delete details.responseHeaders['content-security-policy-report-only'];
delete details.responseHeaders['content-security-policy'];
callback({cancel: false, responseHeaders: details.responseHeaders});
});
class BrowserWindow extends electron.BrowserWindow {
constructor(originalOptions) {
let win = new electron.BrowserWindow(originalOptions);
if (!originalOptions || !originalOptions.webPreferences || !originalOptions.title) return win; // eslint-disable-line constructor-super
const originalPreloadScript = originalOptions.webPreferences.preload;
originalOptions.webPreferences.preload = path.join(process.env.injDir, 'dom_shit.js');
originalOptions.webPreferences.transparency = true;
win = new electron.BrowserWindow(originalOptions);
win.webContents.__preload = originalPreloadScript;
return win;
}
}
BrowserWindow.webContents;
const electron_path = require.resolve('electron');
Object.assign(BrowserWindow, electron.BrowserWindow); // Assigns the new chrome-specific ones
if (electron.deprecate && electron.deprecate.promisify) {
const originalDeprecate = electron.deprecate.promisify; // Grab original deprecate promisify
electron.deprecate.promisify = (originalFunction) => originalFunction ? originalDeprecate(originalFunction) : () => void 0; // Override with falsey check
}
const newElectron = Object.assign({}, electron, {BrowserWindow});
// Tempfix for Injection breakage due to new version of Electron on Canary (Electron 7.x)
// Found by Zerebos (Zack Rauen)
delete require.cache[electron_path].exports;
// /TempFix
require.cache[electron_path].exports = newElectron;
//const browser_window_path = require.resolve(path.resolve(electron_path, '..', '..', 'browser-window.js'));
//require.cache[browser_window_path].exports = BrowserWindow;