From 602acf3e2d63b4f9c0a173d2844ced99c9a00198 Mon Sep 17 00:00:00 2001 From: yonghang <1251679661@qq.com> Date: Wed, 10 May 2023 07:51:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=8D=E7=8E=B0cookie=E8=8E=B7=E5=8F=96?= =?UTF-8?q?=E4=B8=8D=E5=88=B0=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/main/constant.js | 4 ++-- app/main/index.js | 10 +++++++++- app/main/ipc.js | 9 ++++++++- app/main/windows/lib/common.js | 5 ----- app/main/windows/lib/preload.js | 1 + 5 files changed, 20 insertions(+), 9 deletions(-) diff --git a/app/main/constant.js b/app/main/constant.js index 5c8fa98..6760b26 100644 --- a/app/main/constant.js +++ b/app/main/constant.js @@ -23,8 +23,8 @@ switch (schema) { url = 'http://localhost:3806/'; break; case 'QB': - url = 'http://localhost:3806/TIS_PLATFORM/'; - // url = 'http://localhost:8080/TIS_PLATFORM/'; + // url = 'http://localhost:3806/TIS_PLATFORM/'; + url = 'http://localhost:8080/TIS_PLATFORM/'; // url = 'http://tis.inscloudtech.com:9009/TIS_PLATFORM/#/pc'; break; default: diff --git a/app/main/index.js b/app/main/index.js index b2a0075..4cb2c68 100644 --- a/app/main/index.js +++ b/app/main/index.js @@ -1,4 +1,4 @@ -const {app, BrowserWindow, dialog, protocol, ipcMain} = require('electron') +const {app, BrowserWindow, dialog, protocol, session} = require('electron') const {create: createMainWindow} = require('./windows/main') const {MANUAL_CREATED_FLAG,} = require('./constant') const handleIPC = require('./ipc') @@ -16,6 +16,14 @@ if (isFirstInstall) { // app.disableHardwareAcceleration() // app.allowRendererProcessReuse = true app.whenReady().then(() => { + const filter = {urls: ['http://127.0.0.1:5500/*']}; + session.defaultSession.webRequest.onHeadersReceived(filter, (details,callback) => { + if(details.responseHeaders && details.responseHeaders['Set-Cookie']){ + for(let i = 0;i < details.responseHeaders['Set-Cookie'].length;i++) details.responseHeaders['Set-Cookie'][i] += ";SameSite=None;Secure"; + } + callback({ responseHeaders: details.responseHeaders}); + }) + app.commandLine.appendSwitch('disable-features','BlockInsecurePrivateNetworkRequests') // 启动应用时自动启动监控平台接口服务 // const child_process = require('child_process') // if (global.worker !== 'start') { diff --git a/app/main/ipc.js b/app/main/ipc.js index f7fb7ad..c110dac 100644 --- a/app/main/ipc.js +++ b/app/main/ipc.js @@ -1,4 +1,4 @@ -const {BrowserWindow, desktopCapturer} = require('electron'); +const {BrowserWindow, desktopCapturer, session} = require('electron'); // const {net} = require('electron'); const electron = require('electron'); const ipc = require('electron').ipcMain; @@ -411,4 +411,11 @@ module.exports = () => { found.webContents.send('removeCanvas'); } }) + // 获取cookie + ipc.on('getCookies', function (event, arg){ + console.log('getCookies--',session.defaultSession.cookies.get) + session.defaultSession.cookies.get({}, function(error, cookies) { + console.log('cookies--', cookies); + }); + }) } diff --git a/app/main/windows/lib/common.js b/app/main/windows/lib/common.js index 823c816..adfefe5 100644 --- a/app/main/windows/lib/common.js +++ b/app/main/windows/lib/common.js @@ -13,12 +13,7 @@ function createWindow(url,options,node=false) { // height: 530, webPreferences: { // webSecurity: false, - // contextIsolation: false, - // enableRemoteModule:true, nodeIntegration: node, - // webviewTag: true, - // devTools: true, - // preload: path.join(__dirname, 'preload.js') webSecurity: false, contextIsolation: false, enableRemoteModule:true, diff --git a/app/main/windows/lib/preload.js b/app/main/windows/lib/preload.js index 7a31a3b..44d5c58 100644 --- a/app/main/windows/lib/preload.js +++ b/app/main/windows/lib/preload.js @@ -19,6 +19,7 @@ window.api = [ 'PrtSc', 'downloadImg', 'removeCanvas', + 'getCookies' ].reduce( (acc, apiName) => { acc[apiName] = (...params) => {