Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create youtube-theater-fix.js, fixes brave/brave-browser#29591 adds a scriptlet to mirror the session cookie value in localstorage * Update youtube-theater-fix.js * Fix youtube scriptlet, add build output * Store cookie as a JSON string * Only set localstorage if cookie exists, else delete localstorage entry To make sure that they are in sync --------- Co-authored-by: Shivan Kaul Sahib <shivankaulsahib@gmail.com>
- Loading branch information
1 parent
5a949d7
commit 6075775
Showing
3 changed files
with
39 additions
and
1 deletion.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
(async _ => { | ||
if (self.cookieStore === undefined) { | ||
// Do nothing on iOS. The problem doesn't exist there, and the | ||
// solution wouldn't work anyway | ||
return | ||
} | ||
const storeKey = 'brave::wide' | ||
const cookieKey = 'wide' | ||
// If we have a localStorage value, set it as a cookie. | ||
if (localStorage.getItem(storeKey) !== null) { | ||
// The cookie object is stored as a string. Parse it. | ||
const cookieObj = JSON.parse(localStorage.getItem(storeKey)) | ||
await cookieStore.set(cookieObj) | ||
} | ||
|
||
// Persist the cookie value to localStorage every second. | ||
setInterval(async _ => { | ||
try { | ||
const wideCookie = await cookieStore.get(cookieKey) | ||
// We have to stringify the cookie object to store it in localStorage. | ||
if (wideCookie) { | ||
localStorage.setItem(storeKey, JSON.stringify(wideCookie)) | ||
} else { | ||
localStorage.removeItem(storeKey) | ||
} | ||
} catch (e) { | ||
// swallow error from no cookie existing | ||
} | ||
}, 1000) | ||
})() |