Skip to content

SOLVED: How do I access functions on the "Window" object from JavaScript running in ClearScript? #611

Answered by DavidBal
PoseidonEnergy asked this question in Q&A
Discussion options

You must be logged in to vote

Hi @PoseidonEnergy,

yes there is a way to do this, you need to provide the function your self.

Here are a example how i am doing it for atob, btoa and isNaN:

private void Patch(V8ScriptEngine scriptEngine)
{
    string jsPatch = """
        if(typeof(btoa) !== "function")
        {
            globalThis.btoa = (stringToEncode) => {
                const b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
                stringToEncode = String(stringToEncode);
                const rest = stringToEncode.length % 3;
                let result = "";
                for (let i = 0; i < stringToEncode.length;) {
                    const a = stringToEncode.charCodeAt(i…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@PoseidonEnergy
Comment options

Answer selected by PoseidonEnergy
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants