And here is what I shared with @gm1 about my WebBrowserComponent code; we didn’t see anything obviously wrong with it.
Depending on platform, I use a Component like this:
#if defined(IM_TARGET_TVOS)
class MyWebBrowserComponent : public juce::Component {
#elif defined(IM_TARGET_WINDOWS)
class MyWebBrowserComponent : public juce::WindowsWebView2WebBrowserComponent {
#else // defined(IM_TARGET_WINDOWS)
class MyWebBrowserComponent : public juce::WebBrowserComponent {
#endif // defined(IM_TARGET_WINDOWS)
…
public:
#if defined(IM_TARGET_TVOS)
MyWebBrowserComponent(WJX_OnboardScreenVC* parent)
: juce::Component(),
#elif defined(IM_TARGET_WINDOWS)
MyWebBrowserComponent(WJX_OnboardScreenVC* parent)
: juce::WindowsWebView2WebBrowserComponent(
false, [] {
juce::File appOrDLLPath = juce::File::getSpecialLocation(juce::File::currentApplicationFile);
juce::File parentFolderToAppOrDLL = appOrDLLPath.getParentDirectory();
juce::File webView2LoaderFile = parentFolderToAppOrDLL.getChildFile("WebView2Loader.dll");
auto userDataFolder = ImFile::sGetTmpFolder(ImContext::sGetImContextSingleInstanceApp());
userDataFolder.appendPath("userDataFolder");
userDataFolder.Mkdirp();
juce::File jUserDataFolder(juce::String::fromUTF8(userDataFolder.getFilePath().c_str()));
return juce::WebView2Preferences()
.withDLLLocation(webView2LoaderFile)
.withUserDataFolder(jUserDataFolder);
}()),
#else // defined(IM_TARGET_WINDOWS)
MyWebBrowserComponent(WJX_OnboardScreenVC* parent) : juce::WebBrowserComponent(false),
#endif // defined(IM_TARGET_WINDOWS)
mParent(parent)
{
#if defined(IM_TARGET_TVOS)
#else // defined(IM_TARGET_TVOS)
refresh();
clearCookies();
#endif // defined(IM_TARGET_TVOS)
}
So, nothing very special there; on Windows I use a special version of the browser that renders better on modern Windows platforms (e.g. allows it to embed svg images, and uses a nicer font etc.). NB: WJX_OnboardScreenVC is simply a variant of juce::Component, that owns the instance of MyWebBrowserComponent.
When I create the instance, I do this:
webBrowser = std::make_shared<MyWebBrowserComponent>(this);
webBrowser->setBounds(0, 0, 200, 200); // Required for page load to work...
Note the comment in the second line of code; just FWIW.
Other than that, the way I handle the virtual methods is as follows:
#if defined(IM_TARGET_TVOS)
#else // defined(IM_TARGET_TVOS)
bool MyWebBrowserComponent::pageAboutToLoad (const juce::String& newURL) {
if (newURL.startsWith("http")) {
// https reference - use external browser
im_web_LaunchURLViaExternalBrowser(newURL.toUTF8().getAddress());
// Return false, to stop the navigation happening internally!
return false;
}
if (newURL == "about:blank") {
// Required for Android!
return false;
}
return true;
}
// You can override this method to show some other error page by calling
// goToURL. Return true to allow the browser to carry on to the internal
// browser error page.
bool MyWebBrowserComponent::pageLoadHadNetworkError (const juce::String& errorInfo) {
#ifdef IM_DEBUG
im_trace("IM_DEBUG: MyWebBrowserComponent::pageLoadHadNetworkError (%s)\n", errorInfo.toUTF8().getAddress());
#endif // IM_DEBUG
ImThread::sDelayToMainThread(std::chrono::milliseconds(200), [this]() {
// Required on Android, otherwise ERROR is displayed
mParent->pageIndexUpdated();
});
return false; // Required on Android!
}
// This callback occurs when the browser attempts to load a URL in a new window.
// This won't actually load the window but gives you a chance to either launch a
// window yourself or just load the URL into the current window with goToURL().
void MyWebBrowserComponent::newWindowAttemptingToLoad (const juce::String& newURL) {
goToURL(newURL);
}
// This callback happens when the browser has finished loading a page.
void MyWebBrowserComponent::pageFinishedLoading (const juce::String& url) {
// Re-establish z-order of overlaid components.
// Seems to be necessary for Android!
mParent->fixZOrdering();
}
...
void WJX_OnboardScreenVC::fixZOrdering() {
// Make sure the components that we use to overlay the WebView, remaining on top; especially for Android...
closeButton->toFront(false);
backButton->toFront(false);
}
#endif // defined(IM_TARGET_TVOS)
I hope there is some clue in there...
Hoping that all helps somebody else,
Pete