Jump to content

Recommended Posts

Posted (edited)

Hi, as the title says, i'm trying to pass an array into a cef.execute function as here is:

browser.inject(`popup("${type}","${title}",${args})`);
function inject(execute) {
	browser.execute(execute);
}

The array is Args, where it is by default:

args = [
["Faction", "Test"]
]
 
I'm trying to solve this problem, but i'm stuck.
If anybody could help it would be great
 
 
 
Problem solved, see below!
Edited by Protocole
Posted (edited)
browser.emit = (eventName, ...args) => {

    let argumentsString = '';

    for (let arg of args) {
        switch (typeof arg) {
            case 'string': {
                argumentsString += `'${arg}', `;
                break;
            }
            case 'number':
            case 'boolean': {
                argumentsString += `${arg}, `;
                break;
            }
            case 'object': {
                argumentsString += `${JSON.stringify(arg)}, `;
                break;
            }
        }
    }

    browser.execute(`typeof window['${eventName}'] !== 'undefined' && window['${eventName}'](${argumentsString})`);
}

browser.emit('popup', 'kek', 'lol', ['test', 'cheburek']);

 

Edited by kemperrr
  • Like 2
Posted

Thank you, very useful.

 

And if anybody seeing this in future, JSON.stringify() transform object into string, and to get it back to obj do JSON.parse() :)

Posted
1 час назад, Protocole сказал:

Thank you, very useful.

 

And if anybody seeing this in future, JSON.stringify() transform object into string, and to get it back to obj do JSON.parse() :)

from clientside to CEF, if you use the function above, you do not need to use JSON.stringify

and if from CEF in clientside, then you need to use JSON.stringify / parse

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...