fix: 🐛 fix the utf8ToBase64_ implementation to mitigate maximum s… (#32817)

* fix: 🐛 fix the utf8ToBase64_ implementation to mitigate maximum stack error for big scriptlets, resolves issue 51448

* docs: 📝 update comment
This commit is contained in:
Gordan Nekić
2025-12-22 11:50:36 -07:00
committed by GitHub
parent 9e89a1b51e
commit 47ce8a9688
@@ -146,7 +146,15 @@ export class BraveAdblockBrowserProxyImpl implements BraveAdblockBrowserProxy {
private utf8ToBase64_ (str: string) {
const uint8Array = new TextEncoder().encode(str)
const base64String = btoa(String.fromCharCode(...uint8Array))
let binaryString = ''
const chunkSize = 1024
for (let i = 0; i < uint8Array.length; i += chunkSize) {
const chunk = uint8Array.slice(i, i + chunkSize)
binaryString += String.fromCharCode(...chunk)
}
const base64String = btoa(binaryString)
// Replace with uint8Array.toBase64() when TypeScript adds support for
// toBase64 method.
return base64String
}