Protocole

cef.execute with an array?

Recommended Posts

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

Share this post


Link to post
Share on other sites
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 1

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

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.