Files
short-video-factory/electron/lib/cookieAllowCrossSite.ts
2025-07-10 17:43:46 +08:00

19 lines
654 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { app, session } from 'electron'
/**
* 解决 electron15 后跨域cookie无法携带问题
*/
export default function useCookieAllowCrossSite() {
app.whenReady().then(() => {
const filter = { urls: ['https://*/*'] }
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 })
})
})
}