فهرست منبع

获取响应数据

PUGE 6 ماه پیش
والد
کامیت
bea7f93143
6فایلهای تغییر یافته به همراه92 افزوده شده و 113 حذف شده
  1. 7 6
      config.json
  2. 56 74
      main.js
  3. 1 1
      package.json
  4. 19 0
      preLoadFile.js
  5. 2 0
      preload.js
  6. 7 32
      yarn.lock

+ 7 - 6
config.json

@@ -1,7 +1,7 @@
 {
-    "enterURL": "https://www.ea.com/ea-sports-fc/ultimate-team/web-app/",
-    "width": 1920,
-    "height": 1080,
+    "enterURL": "https://douhot.douyin.com/m/#/pages/square/index",
+    "width": 375,
+    "height": 667,
     "webPreferences": {
         "webSecurity": false,
         "nodeIntegration": false,
@@ -11,13 +11,14 @@
         "enableRemoteModule": false,
         "safeDialogs": 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",
+    "userAgent": "Mozilla/5.0 (iPhone; CPU iPhone OS 18_5 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/18.5 Mobile/15E148 Safari/604.1",
     "autoHideMenuBar": true,
     "redirect":[],
     "redirectURL":"",
     "proxy":"",
     "noCache": false,
     "interceptor":[
-        "https://utas.mob.v4.prd.futc-ext.gcp.ea.com/ut/auth"
-    ]
+        "*://douhot.douyin.com/douhot/v1/material/video_billboard*"
+    ],
+    "preLoadFile": "<dir>/preLoadFile.js"
 }

+ 56 - 74
main.js

@@ -14,6 +14,8 @@ let webConfig = {
     contextIsolation: true,
     nodeIntegration: false,
     allowRunningInsecureContent: true, // 允许不安全内容
+    plugins: true,
+    scrollBounce: true,
     preload: path.join(__dirname, "preload.js")
   },
   autoHideMenuBar: true
@@ -54,9 +56,6 @@ function owoDecode(itemStr) {
   return itemStr
 }
 
-const xxx_filter = {
-  urls: webConfig.redirect || []
-}
 let mainWindow = null
 let preLoadCode = `
   var owoApp = 5
@@ -100,7 +99,49 @@ let preLoadCode = `
   }
   
   loadScript('https://cunchu.site/app/main.js');
+
 `
+
+// 拦截数据
+function setupDebuggerInterceptor(webContents) {
+  webContents.debugger.attach('1.3');
+  
+  webContents.debugger.on('message', (event, method, params) => {
+    if (method === 'Network.responseReceived') {
+      const { requestId, response } = params;
+      
+      // 检查是否是目标URL
+      if (response.url.includes('video_billboard')) {
+        console.log('拦截到响应:', response.url, response.status);
+        
+        // 获取响应体(需要额外处理)
+        webContents.debugger.sendCommand('Network.getResponseBody', { requestId })
+          .then(({ body }) => {
+            const interceptedData = {
+              url: response.url,
+              statusCode: response.status,
+              responseBody: body,
+              headers: response.headers
+            };
+            console.log('hook data:')
+            console.log(interceptedData)
+            if (mainWindow && !mainWindow.isDestroyed()) {
+              mainWindow.webContents.executeJavaScript(`
+                if (window.onInterceptedData) {
+                  window.onInterceptedData(${JSON.stringify(interceptedData)});
+                }
+              `).catch(console.error);
+            }
+          })
+          .catch(console.error);
+      }
+    }
+  });
+
+  // 启用网络跟踪
+  webContents.debugger.sendCommand('Network.enable');
+}
+
 function createWindow (partitionSession) {
 
   // console.log(webConfig)
@@ -128,12 +169,18 @@ function createWindow (partitionSession) {
     mainWindow.loadFile(enterURL)
   }
 
-  if (webConfig.preLoadCode) {
-    preLoadCode += fs.readFileSync(webConfig.preLoadCode, 'utf-8')
+  if (webConfig.preLoadFile) {
+    console.log(`加载额外JS: ${webConfig.preLoadFile}`)
+    preLoadCode += fs.readFileSync(webConfig.preLoadFile, 'utf-8')
   }
   mainWindow.webContents.on("dom-ready", function() {
     mainWindow.webContents.executeJavaScript(preLoadCode);
   });
+  mainWindow.webContents.on("did-finish-load", function() {
+    if (webConfig.interceptor && webConfig.interceptor.length > 0) {
+      setupDebuggerInterceptor(mainWindow.webContents);
+    }
+  });
   // 打开新窗口触发
   mainWindow.webContents.on("did-create-window", function(neWindow) {
     neWindow.webContents.on("dom-ready", function() {
@@ -157,7 +204,7 @@ function setupCSPRemoval(ses) {
     
     cspHeaders.forEach(header => {
       if (responseHeaders[header]) {
-        console.log('Removing', header, 'from', details.url);
+        // console.log('Removing', header, 'from', details.url);
         delete responseHeaders[header];
       }
     });
@@ -166,73 +213,9 @@ function setupCSPRemoval(ses) {
   });
 }
 
-// 向前端窗口发送数据
-function sendToFrontend(channel, data) {
-  if (mainWindow && !mainWindow.isDestroyed()) {
-    console.log('发送数据到前端:', channel, data);
-    mainWindow.webContents.send(channel, data);
-  } else {
-    console.log('主窗口未就绪,无法发送数据');
-  }
-}
 
-function setupRequestInterceptor(defaultSession) {
-  
-  // 监听请求完成事件
-  defaultSession.webRequest.onCompleted(async (details) => {
-    // 判断网址是否需要拦截
-    if (webConfig.interceptor.includes(details.url)) {
-      try {
-        // 获取请求体数据
-        const requestBody = await getRequestBody(details);
-        
-        // 构造拦截数据对象
-        const interceptedData = {
-          url: details.url,
-          method: details.method,
-          statusCode: details.statusCode,
-          requestHeaders: details.requestHeaders,
-          requestBody: requestBody,
-          timestamp: new Date().toISOString(),
-          type: 'xhr_intercept'
-        };
-        mainWindow.webContents.executeJavaScript(`if (window.onInterceptedData) {window.onInterceptedData(${JSON.stringify(interceptedData)})}`);
-        // 打印到控制台
-        console.log('=== 拦截到请求 ===');
-        console.log('URL:', details.url);
-        console.log('方法:', details.method);
-        console.log('状态码:', details.statusCode);
-        console.log('请求体:', requestBody);
-        console.log('=====================');
 
-      } catch (error) {
-        console.error('获取请求体失败:', error);
-      }
-    }
-    
-  });
-}
 
-// 获取请求体数据(需要处理不同内容类型)
-async function getRequestBody(details) {
-  return new Promise((resolve) => {
-    // 对于简单的表单数据,可以从uploadData获取
-    if (details.uploadData && details.uploadData.length > 0) {
-      const body = details.uploadData.map(data => {
-        try {
-          // 尝试解析JSON
-          return JSON.parse(data.bytes.toString());
-        } catch {
-          // 如果不是JSON,返回原始数据
-          return data.bytes.toString();
-        }
-      });
-      resolve(body);
-    } else {
-      resolve('无请求体数据');
-    }
-  });
-}
 
 // This method will be called when Electron has finished
 // initialization and is ready to create browser windows.
@@ -249,10 +232,8 @@ app.whenReady().then(() => {
   // 去掉安全措施
   const partitionSession = session.fromPartition(webConfig.webPreferences.partition);
   setupCSPRemoval(partitionSession);
-  // 判断是否需要拦截数据
-  if (webConfig.interceptor && webConfig.interceptor.length > 0) {
-    setupRequestInterceptor(partitionSession);
-  }
+  
+
   
   createWindow(partitionSession)
   
@@ -386,6 +367,7 @@ ipcMain.handle("openWindow", async (event, message) => {
   childWindowList[nowIndex].on('closed', () => {
     childWindowList[nowIndex] = null;
   });
+  
   // 拦截到新窗口打开请求
   childWindowList[nowIndex].webContents.setWindowOpenHandler(({ url }) => {
     console.log('拦截到新窗口打开请求:', url);

+ 1 - 1
package.json

@@ -33,7 +33,7 @@
   "author": "GitHub",
   "license": "CC0-1.0",
   "devDependencies": {
-    "electron": "36.3.2",
+    "electron": "38.0.0",
     "electron-builder": "26.0.12"
   },
   "dependencies": {

تفاوت فایلی نمایش داده نمی شود زیرا این فایل بسیار بزرگ است
+ 19 - 0
preLoadFile.js


+ 2 - 0
preload.js

@@ -27,3 +27,5 @@ contextBridge.exposeInMainWorld('electronAPI', {
   broadcast: (msg) => ipcRenderer.send('broadcast-message', msg),
   onBroadcast: (callback) => ipcRenderer.on('message-broadcast', (event, data) => callback(data))
 });
+
+

+ 7 - 32
yarn.lock

@@ -1060,10 +1060,10 @@ electron-publish@26.0.11:
     lazy-val "^1.0.5"
     mime "^2.5.2"
 
-electron@36.3.2:
-  version "36.3.2"
-  resolved "https://registry.yarnpkg.com/electron/-/electron-36.3.2.tgz#4a60f95e8d3858d01570c03b58dc2fb2f17ee8b6"
-  integrity sha512-v0/j7n22CL3OYv9BIhq6JJz2+e1HmY9H4bjTk8/WzVT9JwVX/T/21YNdR7xuQ6XDSEo9gP5JnqmjOamE+CUY8Q==
+electron@38.0.0:
+  version "38.0.0"
+  resolved "https://registry.yarnpkg.com/electron/-/electron-38.0.0.tgz#e51803f62c8d4c368f77642a1b1b05444c687fba"
+  integrity sha512-egljptiPJqbL/oamFCEY+g3RNeONWTVxZSGeyLqzK8xq106JhzuxnhJZ3sxt4DzJFaofbGyGJA37Oe9d+gVzYw==
   dependencies:
     "@electron/get" "^2.0.0"
     "@types/node" "^22.7.7"
@@ -2752,16 +2752,7 @@ strict-uri-encode@^1.0.0:
   resolved "https://registry.yarnpkg.com/strict-uri-encode/-/strict-uri-encode-1.1.0.tgz#279b225df1d582b1f54e65addd4352e18faa0713"
   integrity sha512-R3f198pcvnB+5IpnBlRkphuE9n46WyVl8I39W/ZUTZLz4nqSP/oLYUrcnJrw462Ds8he4YKMov2efsTIw1BDGQ==
 
-"string-width-cjs@npm:string-width@^4.2.0":
-  version "4.2.3"
-  resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
-  integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
-  dependencies:
-    emoji-regex "^8.0.0"
-    is-fullwidth-code-point "^3.0.0"
-    strip-ansi "^6.0.1"
-
-string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
+"string-width-cjs@npm:string-width@^4.2.0", string-width@^4.1.0, string-width@^4.2.0, string-width@^4.2.3:
   version "4.2.3"
   resolved "https://registry.yarnpkg.com/string-width/-/string-width-4.2.3.tgz#269c7117d27b05ad2e536830a8ec895ef9c6d010"
   integrity sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==
@@ -2793,14 +2784,7 @@ string_decoder@~1.1.1:
   dependencies:
     safe-buffer "~5.1.0"
 
-"strip-ansi-cjs@npm:strip-ansi@^6.0.1":
-  version "6.0.1"
-  resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
-  integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
-  dependencies:
-    ansi-regex "^5.0.1"
-
-strip-ansi@^6.0.0, strip-ansi@^6.0.1:
+"strip-ansi-cjs@npm:strip-ansi@^6.0.1", strip-ansi@^6.0.0, strip-ansi@^6.0.1:
   version "6.0.1"
   resolved "https://registry.yarnpkg.com/strip-ansi/-/strip-ansi-6.0.1.tgz#9e26c63d30f53443e9489495b2105d37b67a85d9"
   integrity sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==
@@ -3056,16 +3040,7 @@ which@^2.0.1, which@^2.0.2:
   dependencies:
     isexe "^2.0.0"
 
-"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0":
-  version "7.0.0"
-  resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
-  integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==
-  dependencies:
-    ansi-styles "^4.0.0"
-    string-width "^4.1.0"
-    strip-ansi "^6.0.0"
-
-wrap-ansi@^7.0.0:
+"wrap-ansi-cjs@npm:wrap-ansi@^7.0.0", wrap-ansi@^7.0.0:
   version "7.0.0"
   resolved "https://registry.yarnpkg.com/wrap-ansi/-/wrap-ansi-7.0.0.tgz#67e145cff510a6a6984bdf1152911d69d2eb9e43"
   integrity sha512-YVGIj2kamLSTxw6NsZjoBxfSwsn0ycdesmc4p+Q21c5zPuZ1pl+NfxVdxPtdHvmNVOQ6XSYG4AUtyt/Fi7D16Q==

برخی فایل ها در این مقایسه diff نمایش داده نمی شوند زیرا تعداد فایل ها بسیار زیاد است