mirror of
https://github.com/th-ch/youtube-music.git
synced 2026-01-10 18:21:47 +00:00
use session.webRequest.onBeforeSendHeaders for useragent
This commit is contained in:
15
index.js
15
index.js
@ -166,19 +166,28 @@ function createMainWindow() {
|
|||||||
|
|
||||||
app.once("browser-window-created", (event, win) => {
|
app.once("browser-window-created", (event, win) => {
|
||||||
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
|
// User agents are from https://developers.whatismybrowser.com/useragents/explore/
|
||||||
|
const originalUserAgent = win.webContents.userAgent;
|
||||||
const userAgents = {
|
const userAgents = {
|
||||||
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; rv:95.0) Gecko/20100101 Firefox/95.0",
|
mac: "Mozilla/5.0 (Macintosh; Intel Mac OS X 12.1; rv:95.0) Gecko/20100101 Firefox/95.0",
|
||||||
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
windows: "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
||||||
linux: "Mozilla/5.0 (Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
linux: "Mozilla/5.0 (Linux x86_64; rv:95.0) Gecko/20100101 Firefox/95.0",
|
||||||
}
|
}
|
||||||
|
|
||||||
const userAgent =
|
const updatedUserAgent =
|
||||||
is.macOS() ? userAgents.mac :
|
is.macOS() ? userAgents.mac :
|
||||||
is.windows() ? userAgents.windows :
|
is.windows() ? userAgents.windows :
|
||||||
userAgents.linux;
|
userAgents.linux;
|
||||||
|
|
||||||
app.userAgentFallback = userAgent;
|
win.webContents.userAgent = updatedUserAgent;
|
||||||
|
app.userAgentFallback = updatedUserAgent;
|
||||||
|
|
||||||
|
win.webContents.session.webRequest.onBeforeSendHeaders((details, cb) => {
|
||||||
|
if (win.webContents.getURL().startsWith("https://accounts.google.com") && details.url.startsWith("https://accounts.google.com")){
|
||||||
|
details.requestHeaders["User-Agent"] = originalUserAgent;
|
||||||
|
}
|
||||||
|
cb({ requestHeaders: details.requestHeaders });
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
setupSongInfo(win);
|
setupSongInfo(win);
|
||||||
loadPlugins(win);
|
loadPlugins(win);
|
||||||
|
|||||||
@ -98,7 +98,7 @@ function moveVolumeHud(showVideo) {
|
|||||||
|
|
||||||
function observeThumbnail() {
|
function observeThumbnail() {
|
||||||
const playbackModeObserver = new MutationObserver(mutations => {
|
const playbackModeObserver = new MutationObserver(mutations => {
|
||||||
if (!$('#player').videoMode_) return;
|
if (!player.videoMode_) return;
|
||||||
|
|
||||||
mutations.forEach(mutation => {
|
mutations.forEach(mutation => {
|
||||||
if (!mutation.target.src.startsWith('data:')) return;
|
if (!mutation.target.src.startsWith('data:')) return;
|
||||||
|
|||||||
Reference in New Issue
Block a user