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 2

Share this post


Link to post
Share on other sites

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() :)

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

That's what i concluded too, still thank you :)

And yeah,  i'm using your function, more powerful than my old one 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.