From 1fefc792fc330874d6d2eb54e1ea1ef1efb95934 Mon Sep 17 00:00:00 2001
From: buvta <12312540+buvta@users.noreply.github.com>
Date: Tue, 29 Dec 2020 16:00:45 +0800
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E8=AF=B7=E6=B1=82referer?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.eslintrc.js | 3 ++-
public/index.html | 1 +
src/background.js | 18 ++++++++++++++++++
3 files changed, 21 insertions(+), 1 deletion(-)
diff --git a/.eslintrc.js b/.eslintrc.js
index 2c6a7fa..32e1edd 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -12,6 +12,7 @@ module.exports = {
},
rules: {
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
- 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
+ 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
+ 'standard/no-callback-literal': 0
}
}
diff --git a/public/index.html b/public/index.html
index a57d6e5..ca2a143 100644
--- a/public/index.html
+++ b/public/index.html
@@ -4,6 +4,7 @@
+
<%= htmlWebpackPlugin.options.title %>
diff --git a/src/background.js b/src/background.js
index e59233b..3d6fa84 100644
--- a/src/background.js
+++ b/src/background.js
@@ -5,6 +5,7 @@ import { createProtocol } from 'vue-cli-plugin-electron-builder/lib'
import installExtension, { VUEJS_DEVTOOLS } from 'electron-devtools-installer'
import { initUpdater } from './lib/update/update'
const isDevelopment = process.env.NODE_ENV !== 'production'
+// const log = require('electron-log') // 用于调试主程序
app.commandLine.appendSwitch('disable-features', 'OutOfBlinkCors') // 允许跨域
app.commandLine.appendSwitch('--ignore-certificate-errors', 'true') // 忽略证书相关错误
@@ -35,6 +36,23 @@ function createWindow () {
win.loadURL('app://./index.html')
}
+ // 修改request headers
+ // Sec-Fetch下禁止修改,浏览器自动加上请求头 https://www.cnblogs.com/fulu/p/13879080.html 暂时先用index.html的meta referer policy替代
+ const filter = {
+ urls: ['http://*/*', 'http://*/*']
+ }
+ win.webContents.session.webRequest.onBeforeSendHeaders(filter, (details, callback) => {
+ const url = new URL(details.url)
+ details.requestHeaders.Origin = url.origin
+ if (!details.url.includes('//localhost') && details.requestHeaders.Referer && details.requestHeaders.Referer.includes('//localhost')) {
+ details.requestHeaders.Referer = url.origin
+ }
+ callback({
+ cancel: false,
+ requestHeaders: details.requestHeaders
+ })
+ })
+
initUpdater(win)
win.on('closed', () => {