Creating a Web Browser in a Custom Slate Tab

Hey,

I’ve been trying extend the Editor to allow me to create a Tab which holds a Web Browser, like this example from the SlateViewer.exe TestSuite1 :



I have no problem creating the tab. However, when I try to use any of the include files that I’ve found relevant seem to be incomplete types, and SWebBrowserWidget doesn’t seem to work for me?
(I tried: SWebBrowser.h, SWebBrowserView.h, WebBrowser.h, WebBrowserViewport.h)

TSharedRef<SDockTab> FCustomClass::SpawnTab(const FSpawnTabArgs& TabSpawnerArgs)
{
	return SNew(SDockTab)
		.TabRole(ETabRole::NomadTab)
		[	
			// This works without problems
			SNew(SBox).VAlign(VAlign_Center).HAlign(HAlign_Center)
			[
               SNew(STextBlock).Text(FText::FromString(TEXT("Placeholder")))
			]

			// None of these work, tells me they are incomplete types
			SNew(SWebBrowser / SWebBrowserView)
			[
			]

			// This is recognized but causes crashes
			// And only has default Slate Named Arguments 
            // (ie. SNew(...)./AccessibleParams())
			SNew(SWebBrowserWidget)
			[
				// I dont know what to do here either
			]
		];
}



I would really appreciate it if anyone can help me make sense of how to create a Web Browser in my Custom Created Tab :slightly_smiling_face:

I feel like I should also further elaborate on an issue that is caused with trying to use

  • #include "WebBrowser/Public/SWebBrowser.h" , it crashes at compile time, telling me either that there was an error generating some PCH file, or "FBrowsingContextSettings uses undefined struct ‘WEBBROWSER_API’ "
  • #include "WebBrowser/Public/SWebBrowserView.h" and include "WebBrowser/Public/WebBrowserViewport.h", it crashes at compile time, telling me “incomplete type not allowed

So unless I’m missing something I don’t see how its exactly possible to create a Web Browser within the UE Tabs like its shown in the SlateViewer?


From what I gathered with some help,

The issue was that adding the SWebBrowser.h file like I did doesnt work, I needed to add it to the public dependencies in the .build file of my module.

Even after that it still has issues with Intellisense not recognizing it so: SNew(SWebBrowser) will still show an error, but will compile and work as it does in the SlateViewer example.

Although I noticed that it will crash at compile time when instead of SNew I do:

In .h file:

#include "SWebBrowser.h"

...

SWebBrowser MyWebBrowser;

In .cpp file:

#include "MyHeader.h"

...

SAssignNew(MyWebBrowser, SWebBrowser)

For some reason it will not be able to compile this telling me these errors (also when forward declared) :

  • “SWebBrowser” is undefined

Edit* I forgot and simply declared it wrong, it should be:
TSharedPtr<SWebBrowser> MyBrowser;

So to summarize for anyone looking back at this in the future:

  • Include “WebBrowser” in you .build file’s dependencies
  • Add the include “SWebBrowser.h” to your file in which your creating the browser
  • Use SNew(SWebBrowser) / SAssignNew(/*YourBrowser*/, SWebBrowser)

And you should be set. Hope this was helpful, and saved someone out there some time figuring this out.
Especially if your a beginner like me :slightly_smiling_face: