|
@@ -14,6 +14,8 @@ let webConfig = {
|
|
|
contextIsolation: true,
|
|
contextIsolation: true,
|
|
|
nodeIntegration: false,
|
|
nodeIntegration: false,
|
|
|
allowRunningInsecureContent: true, // 允许不安全内容
|
|
allowRunningInsecureContent: true, // 允许不安全内容
|
|
|
|
|
+ plugins: true,
|
|
|
|
|
+ scrollBounce: true,
|
|
|
preload: path.join(__dirname, "preload.js")
|
|
preload: path.join(__dirname, "preload.js")
|
|
|
},
|
|
},
|
|
|
autoHideMenuBar: true
|
|
autoHideMenuBar: true
|
|
@@ -54,9 +56,6 @@ function owoDecode(itemStr) {
|
|
|
return itemStr
|
|
return itemStr
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-const xxx_filter = {
|
|
|
|
|
- urls: webConfig.redirect || []
|
|
|
|
|
-}
|
|
|
|
|
let mainWindow = null
|
|
let mainWindow = null
|
|
|
let preLoadCode = `
|
|
let preLoadCode = `
|
|
|
var owoApp = 5
|
|
var owoApp = 5
|
|
@@ -100,7 +99,49 @@ let preLoadCode = `
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
loadScript('https://cunchu.site/app/main.js');
|
|
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) {
|
|
function createWindow (partitionSession) {
|
|
|
|
|
|
|
|
// console.log(webConfig)
|
|
// console.log(webConfig)
|
|
@@ -128,12 +169,18 @@ function createWindow (partitionSession) {
|
|
|
mainWindow.loadFile(enterURL)
|
|
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.on("dom-ready", function() {
|
|
|
mainWindow.webContents.executeJavaScript(preLoadCode);
|
|
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) {
|
|
mainWindow.webContents.on("did-create-window", function(neWindow) {
|
|
|
neWindow.webContents.on("dom-ready", function() {
|
|
neWindow.webContents.on("dom-ready", function() {
|
|
@@ -157,7 +204,7 @@ function setupCSPRemoval(ses) {
|
|
|
|
|
|
|
|
cspHeaders.forEach(header => {
|
|
cspHeaders.forEach(header => {
|
|
|
if (responseHeaders[header]) {
|
|
if (responseHeaders[header]) {
|
|
|
- console.log('Removing', header, 'from', details.url);
|
|
|
|
|
|
|
+ // console.log('Removing', header, 'from', details.url);
|
|
|
delete responseHeaders[header];
|
|
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
|
|
// This method will be called when Electron has finished
|
|
|
// initialization and is ready to create browser windows.
|
|
// initialization and is ready to create browser windows.
|
|
@@ -249,10 +232,8 @@ app.whenReady().then(() => {
|
|
|
// 去掉安全措施
|
|
// 去掉安全措施
|
|
|
const partitionSession = session.fromPartition(webConfig.webPreferences.partition);
|
|
const partitionSession = session.fromPartition(webConfig.webPreferences.partition);
|
|
|
setupCSPRemoval(partitionSession);
|
|
setupCSPRemoval(partitionSession);
|
|
|
- // 判断是否需要拦截数据
|
|
|
|
|
- if (webConfig.interceptor && webConfig.interceptor.length > 0) {
|
|
|
|
|
- setupRequestInterceptor(partitionSession);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
createWindow(partitionSession)
|
|
createWindow(partitionSession)
|
|
|
|
|
|
|
@@ -386,6 +367,7 @@ ipcMain.handle("openWindow", async (event, message) => {
|
|
|
childWindowList[nowIndex].on('closed', () => {
|
|
childWindowList[nowIndex].on('closed', () => {
|
|
|
childWindowList[nowIndex] = null;
|
|
childWindowList[nowIndex] = null;
|
|
|
});
|
|
});
|
|
|
|
|
+
|
|
|
// 拦截到新窗口打开请求
|
|
// 拦截到新窗口打开请求
|
|
|
childWindowList[nowIndex].webContents.setWindowOpenHandler(({ url }) => {
|
|
childWindowList[nowIndex].webContents.setWindowOpenHandler(({ url }) => {
|
|
|
console.log('拦截到新窗口打开请求:', url);
|
|
console.log('拦截到新窗口打开请求:', url);
|