ソースを参照

禁用安全限制

PUGE 6 ヶ月 前
コミット
c0705e202a
3 ファイル変更52 行追加18 行削除
  1. 4 5
      config.json
  2. 17 1
      config3.json
  3. 31 12
      main.js

+ 4 - 5
config.json

@@ -1,12 +1,11 @@
 {
-    "enterURL": "https://demos.run/soundSynthesis/index1.html",
-    "width": 960,
-    "height": 580,
+    "enterURL": "https://www.tiktok.com/@yes_crystalwholesale/live?enter_from_merge=general_search&enter_method=others_photo&search_id=2025090223262442774B7E8537813E76BF&search_keyword=yes%20crystal%20wholesale&search_result_id=6830419904492258306&search_type=general",
+    "width": 1920,
+    "height": 1080,
     "webPreferences": {
         "webSecurity": false,
         "nodeIntegration": false,
-        "nativeWindowOpen": false,
-        "preload": "<dir>/preload.js"
+        "nativeWindowOpen": false
     },
     "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
     "autoHideMenuBar": true,

+ 17 - 1
config3.json

@@ -1 +1,17 @@
-{"enterURL":"https://demos.run/debuger/index.html","width":1200,"height":800,"webPreferences":{"webSecurity":false,"nodeIntegration":true,"nativeWindowOpen":false},"autoHideMenuBar":true,"redirect":[],"redirectURL":"","proxy":"","noCache":false,"data":[],"activeIndex":1,"username":"","fullscreen":false}
+{
+    "enterURL": "https://www.tiktok.com/@yes_crystalwholesale/live?enter_from_merge=general_search&enter_method=others_photo&search_id=2025090223262442774B7E8537813E76BF&search_keyword=yes%20crystal%20wholesale&search_result_id=6830419904492258306&search_type=general",
+    "width": 960,
+    "height": 580,
+    "webPreferences": {
+        "webSecurity": false,
+        "nodeIntegration": false,
+        "nativeWindowOpen": false,
+        "preload": "<dir>/preload.js"
+    },
+    "userAgent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/138.0.0.0 Safari/537.36",
+    "autoHideMenuBar": true,
+    "redirect":[],
+    "redirectURL":"",
+    "proxy":"",
+    "noCache": false
+}

+ 31 - 12
main.js

@@ -13,6 +13,7 @@ let webConfig = {
     webSecurity: false,
     contextIsolation: true,
     nodeIntegration: false,
+    allowRunningInsecureContent: true, // 允许不安全内容
     preload: path.join(__dirname, "preload.js")
   },
   autoHideMenuBar: true
@@ -21,6 +22,9 @@ let webConfig = {
   // 全屏
   // fullscreen: true
 }
+
+
+
 // 判断是否有特殊配置文件
 console.log(__dirname + "\\config.json")
 if (fs.existsSync("./config.json")) {
@@ -139,29 +143,44 @@ function createWindow () {
   
 }
 
-// This method will be called when Electron has finished
-// initialization and is ready to create browser windows.
-// Some APIs can only be used after this event occurs.
-app.whenReady().then(() => {
-  session.defaultSession.webRequest.onBeforeRequest(xxx_filter, (details, callback) => {
-    callback({ redirectURL: webConfig.redirectURL});
-  })
-  session.defaultSession.webRequest.onHeadersReceived((details, callback) => {
-    const responseHeaders = details.responseHeaders;
+function setupCSPRemoval(ses) {
+  ses.webRequest.onHeadersReceived((details, callback) => {
+    const responseHeaders = details.responseHeaders || {};
+    
+    const cspHeaders = [
+      'content-security-policy',
+      'Content-Security-Policy',
+      'content-security-policy-report-only',
+      'x-content-security-policy',
+      'x-webkit-csp'
+    ];
     
-    // 删除 CSP
-    delete responseHeaders['content-security-policy'];
-    delete responseHeaders['Content-Security-Policy'];
+    cspHeaders.forEach(header => {
+      if (responseHeaders[header]) {
+        console.log('Removing', header, 'from', details.url);
+        delete responseHeaders[header];
+      }
+    });
     
     callback({ cancel: false, responseHeaders });
   });
+}
+
+// This method will be called when Electron has finished
+// initialization and is ready to create browser windows.
+// Some APIs can only be used after this event occurs.
+app.whenReady().then(() => {
   // 判断是否无缓存
   if (webConfig.noCache) {
     console.log('无缓存模式!')
     webConfig.webPreferences.partition = 'persist:Session' + Math.round(Math.random()*100000)
+    
   } else {
     webConfig.webPreferences.partition = 'persist:owoApp'
   }
+  // 去掉安全措施
+  const partitionSession = session.fromPartition(webConfig.webPreferences.partition);
+  setupCSPRemoval(partitionSession);
   createWindow()
   
   app.on('activate', function () {