diff --git a/packages/react-native-compat/index.js b/packages/react-native-compat/index.js index 9ae7d203b..89e7f457e 100644 --- a/packages/react-native-compat/index.js +++ b/packages/react-native-compat/index.js @@ -14,6 +14,24 @@ if (typeof Buffer === "undefined") { global.Buffer = require("buffer").Buffer; } +// Polyfill btoa +if (typeof btoa === "undefined") { + global.btoa = function (str) { + return Buffer.alloc(str.length, str, "binary").toString("base64"); + }; +} + +// Polyfill atob +if (typeof atob === "undefined") { + global.atob = function (b64Encoded) { + return Buffer.alloc( + Buffer.from(b64Encoded, "base64").length, + Buffer.from(b64Encoded, "base64"), + "binary", + ).toString("binary"); + }; +} + if (typeof global?.Linking === "undefined") { try { global.Linking = require("react-native").Linking;