Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set new consent cookie and supress tracking cookies on the watch page #4013

Merged
merged 2 commits into from
Oct 8, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Set new consent cookie and supress tracking cookies on the watch page
  • Loading branch information
absidue committed Oct 6, 2023
commit 84038f965ac0d3c35c900b296b8b5f6a8d0bcf6a
18 changes: 18 additions & 0 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,13 @@ function runApp() {
})
})

session.defaultSession.cookies.set({
url: 'https://www.youtube.com',
name: 'SOCS',
value: 'CAI',
sameSite: 'no_restriction',
})

// make InnerTube requests work with the fetch function
// InnerTube rejects requests if the referer isn't YouTube or empty
const innertubeAndMediaRequestFilter = { urls: ['https://www.youtube.com/youtubei/*', 'https://*.googlevideo.com/videoplayback?*'] }
Expand Down Expand Up @@ -336,6 +343,17 @@ function runApp() {
callback({ requestHeaders })
})

// when we create a real session on the watch page, youtube returns tracking cookies, which we definitely don't want
const trackingCookieRequestFilter = { urls: ['https://www.youtube.com/sw.js_data', 'https://www.youtube.com/iframe_api'] }

session.defaultSession.webRequest.onHeadersReceived(trackingCookieRequestFilter, ({ responseHeaders }, callback) => {
if (responseHeaders) {
delete responseHeaders['set-cookie']
}
// eslint-disable-next-line n/no-callback-literal
callback({ responseHeaders })
})

if (replaceHttpCache) {
// in-memory image cache

Expand Down