How can I pass some data from the game to the UMG browser widget and the opposite?
Say I have an authenticated user in game and want him to fill in form from a webpage. I want to pass his User ID in the form automatically.
How do I proceed?
I’ve seen this in 4.9:
New: UObject instances can now be passed to SWebBrowser and accessed from browser javascript.
Is this related to my question or is it related to HTML5?
Additionally I’ve seen in 4.9:
New: Users can now provide functionality to web browser widgets to handle creation of popup windows.
New: Users can now provide functionality to web browser widgets to handle the closing of popup windows created by the browser.
Use APPEND to put together some HTML and your form values from in game. Then use Load String , you can then even interact with a PHP server. Would love to know a way how to get the data back from PHP to the game. Any help appreciated.
get data back from the webbrowser widget in the sense, to get information about the redirected url like in the case of social media login? or the webpage content?
I struggled a little with this but eventually found a solution, but no one is talking about this anywhere online so I thought I’d leave this here for posterity:
Basically you can use the “execute Javascript” node to run some logic in the currently open webpage inside the web browser widget. Here’s how for example I was able to parse some text from inside the webpage and get it to display in another widget text:
trigger the “execute Javascript” node with whatever event/button click you want
feed it a string variable holding your JS code
in that code, parse data, store it inside a JS variable
at the end of your JS code use console.log(variable) to post your data
back in UE in the details panel of your browser widget at the bottom use “on console message”, the “message” string output holds your data, feed it to a UE variable or directly to a widget
First line finds all HTML elements with the class “.class_name” and puts them in a nodelist (an array basically)
second line finds the last index of the array, but you could simply write [0] at the end of the first line if you want the first result in your case
third line reads the actual text content inside the HTML element
last line posts your result to the console
You might notice I’m not using var or const to declare my variables, this is because if you run that script several times you will get an error that says something like “can’t declare a variable that is already declared”, so doing it this way works fine as long as you make sure to use a variable name that isn’t an existing JS function name.
Note that I didn’t know any JS before doing this, my only “programming” experience being blueprints, but it’s super easy to learn by searching stackoverflow or MDN, took me only a couple hours to write this snippet by looking up syntax and a lot of trial and error lol.