Creating a Web Browser Extension

Overview
In this tutorial, we will use the GameOn WebBrowserObject to create a GameOn Extension that once activated will open a window that will take the user to a specified url. In this case, we’re going to send them to the Minecraft Wiki.

What you’ll need:
GameOn Developer Toolkit (v200501) or later.
or any Coding IDE (we recommend Visual Studio Code)
A fully filled and properly formatted Extension Manifest (see tutorial 1)


Step One: Our Window

In part-one of the tutorial, we created a button event that opened a window to print the text “Hello World”. We changed this to add a GUI in part-two. In this part, we will make adjustments to the code in part one, as the only user interface object we need is the WebBrowserObject.

//create an activity on button press
            button.activity(new activity)
            {
                new GameOnOverlay.Window(MyWindow)
                {
                    
                }
            }

We must now add the code for a WebBrowserObject to the solution. If you’re wondering how to create a WebBrowserObject, we currently have an insert feature in GameOn Developer Toolkit that will automatically add a code block with some standard tools. For a full list of properties, you’ll want to see WebBrowserObject Class (GameOn.LXCore)

//create an activity on button press
            button.activity(new activity)
            {
                new GameOnOverlay.Window(MyWindow)
                {
                    new WebBrowserObject = WebBrowser1();
                            WebBrowser1.src.ToString = "https://www.minecraftwiki.net"
                            WebBrowser1.AllowInsecureBrowsing = true;
                            WebBrowser1.Dock = fill;
                }
            }

This code is simple and human readable thanks to the Code LX programming language and our wonderful GameOn and GameOnExt libraries. Now if you run the extension and click on the extension icon, you will see that this is the window we receive:

The reason the window appears small is because we haven’t given the window a dedicated size (the default width and height of an extension window is very small). To change the Width and Height of the window, we must append the code:

//create an activity on button press
            button.activity(new activity)
            {
                new GameOnOverlay.Window(MyWindow)
                {
                    MyWindow.State = windowed;
				MyWindow.Height = 800px
				MyWindow.Width = 800px
                    new WebBrowserObject = WebBrowser1();
                            WebBrowser1.src.ToString = "https://www.minecraftwiki.net"
                            WebBrowser1.AllowInsecureBrowsing = true;
                            WebBrowser1.Dock = fill;
                }
            }

You might also notice that our output doesn’t have scrollbars on the window. We need to make sure that the window supports scrolling. We can do this using the WebBrowserObject.Scrollbar property. We should set this to support horizontal and vertical scrolling.

new WebBrowserObject = WebBrowser1();
                            WebBrowser1.src.ToString = "https://www.minecraftwiki.net"
                            WebBrowser1.AllowInsecureBrowsing = true;
                            WebBrowser1.Dock = fill;
                            WebBrowser1.Scrollbar = vertical, horizontal;

Now if we run the extension, we can see that it functions more like how we would expect:

And there you have it. That’s how you can easily and simply integrate a web browser into your GameOn Extension using the WebBrowserObject class. This makes it easy to provide your web applications to GameOn users.

Menu