Browse Source

复现cookie获取不到的问题

test
yonghang 2 years ago
parent
commit
602acf3e2d
  1. 4
      app/main/constant.js
  2. 10
      app/main/index.js
  3. 9
      app/main/ipc.js
  4. 5
      app/main/windows/lib/common.js
  5. 1
      app/main/windows/lib/preload.js

4
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:

10
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') {

9
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);
});
})
}

5
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,

1
app/main/windows/lib/preload.js

@ -19,6 +19,7 @@ window.api = [
'PrtSc',
'downloadImg',
'removeCanvas',
'getCookies'
].reduce(
(acc, apiName) => {
acc[apiName] = (...params) => {

Loading…
Cancel
Save