Protocole Posted June 14, 2018 Posted June 14, 2018 (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 June 14, 2018 by Protocole
kemperrr Posted June 14, 2018 Posted June 14, 2018 (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 June 16, 2018 by kemperrr 2
Protocole Posted June 14, 2018 Author Posted June 14, 2018 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()
kemperrr Posted June 14, 2018 Posted June 14, 2018 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
Protocole Posted June 14, 2018 Author Posted June 14, 2018 That's what i concluded too, still thank you And yeah, i'm using your function, more powerful than my old one
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now