SOLVED CUSTOMGUI_HTMLVIEWER didn't work when mouse out the dialog

Hello !

Qustion :

My little dialog with CUSTOMGUI_HTMLVIEWER will black down and didn,t work anymore when mouse click anywhere out of the dialog, did I do something wrong?

Details:

Here is the worked onr and black one . The black one even cann;t close with the dialog button . only can close in windows toolbar. And I don't know how to solve
c01a5e3c-f3cf-43e4-a852-7df87f6fa368-image.png
8d492c56-a95b-4894-9582-3820c34b7f61-image.png

Here is a little code

import c4d

defpage = "https://www.baidu.com"

class Dialog(c4d.gui.GeDialog):
    
    def __init__(self):        
        self.AddGadget(c4d.DIALOG_NOMENUBAR, 0)
    
    def CreateLayout(self):
        self.SetTitle("Web Browser")
        self.GroupBegin(0, c4d.BFH_SCALEFIT, 0, 1)
        self.GroupBorderSpace(2, 2, 2, 0)
        self.AddEditText(1001, c4d.BFH_SCALEFIT)
        self.GroupEnd()
        self.b = self.AddCustomGui(1000, c4d.CUSTOMGUI_HTMLVIEWER, "",
            c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 200, 200)
        return True

    def InitValues(self):
        self.SetString(1001, defpage)
        self.Command(1, None)
        return True

    def Command(self, wid, bc):
        if wid == c4d.DLG_OK:  # Enter pressed
            url = self.GetString(1001)
            self.b.SetUrl(url, c4d.URL_ENCODING_UTF16)
        return True

dlg = Dialog()
dlg.Open(c4d.DLG_TYPE_ASYNC)

Thanks

Hello @dunhou,

Thank you for reaching out to us and giving a clear description of your problem. I understand perfectly what your problem is but cannot reproduce it on my machine. I have tried R25.113, S26.107, as well as the upcoming RC and all of them do not exhibit the behavior of turning black and effectively freezing the dialog when clicking outside of the bounds of the dialog.

However, I noticed that when the HTML is loading/parsing a page, it renders itself as black. Which for example happens when you open the dialog, and a page is being loaded for the first time.

html_gadget_black.gif

So, to solve your problem, we need a bit more context information, because the HTML gadget relies on your system browser and its caches/settings.

  • Which version of Windows are using? Press the ⊞ Win key and type 'System Information' and hit Enter, you can find the version number of your Windows as the second entry there.
  • Are you logged into Baidu? I do not have a Baidu account, but it is much more popular outside of Europe/the US, and there could be something going wrong with how our gadget handles cookies/a login session.

I have also reached out to the developer of the browser integration to see if he has an idea what could be going wrong there.

Cheers,
Ferdinand

@ferdinand

Thanks , here is my destop windows version , I have lastest win 11 in my home . Maybe I could test afterwork.
And I test this on S26.107
772ddca2-4e4a-4a7e-8363-7cc22058b98a-image.png

About logged in Baidu , I think I did not . It's just a test url wo start with , I want to build a C4D info search tool, like search a Subdivision Surface in sdk or just Wiki it within c4d and I can dock the tab .

So when I start the code , it runs , and I click out the dialog or input another url , It would black down and did not work anymore .
And I cann't edit it anymore , even the url link box .(Like C4D Help do:Ctrl+F1 )

Internet connection seems all right , I test Baidu translator API , It works well and return the translation in C4D . But I don't know how browser caches works, I use Edge , and test url in Chorme as well . they all works.
a0739457-304d-4e59-ba88-b32293f410c8-image.png

When loading , it renders itself as black. I didn't notice this happened , maybe my internet near to Baidu , that I cann't notice that🤣 (as I said I have no knowledge about Internet).

If any context information I have miss , plz let me know .

Hello @dunhou,

Thank you for the updated information. So, I spoke with the developer and did some digging.

Technical Overview

First of all, I provided some slightly outdated information. Since the reimplementation of the HTML browser, it does not share the cache with the system default browser anymore, and there are now also two Browser types which can kick in, depending on your environment:

  • The new Chromium HTML Rendering Engine of Windows 10+ as the new default (the Cinema 4D installer will install the required WebView2 dependencies even on older versions of Win10 which used EdgeHtml)
  • The old Trident, i.e. Internet Explorer, HTML Rendering engine of older Windows engines as a fallback.

The cache of our HTML gadget is stored under \{user}\AppData\Roaming\MAXON\{c4d version}\EBWebView. You can also force Cinema 4D to use the old engine by passing the startup augment -g_forceedge=false, e.g., C:\Program Files\Maxon\S26_107>"Cinema 4D.exe" -g_forceedge=false. When running Cinema 4D you can distinguish the internally used HTML engine easily by their context menu.

The context menu of the HTML gadget in the Quickstart dialog of S26.107 running in legacy browser mode with "Cinema 4D.exe" -g_forceedge=false
9e729ede-e7c7-4f43-8a7f-3a3da9934488-image.png

The context menu of the HTML gadget in the Quickstart dialog of S26.107 running in default browser mode with "Cinema 4D.exe", i.e., "Cinema 4D.exe" -g_forceedge=true
f66bd3c5-c932-4d21-90a2-bb66730c10e3-image.png

Your Problem
  1. I still cannot reproduce your problem. Your Windows 10 version seems recent enough. I am on Windows 11 though (latest build at the pointing of writing this).
  2. Our developer pointed out that your screenshot, especially its scrolls bars, look a bit like you are running in legacy mode, i.e., on Trident.
  3. The form how you provided the example, as a Script Manager script, is inherently not supported by the HTML gadget, because the browser instance attaches itself internally to a window handle (HWND). It is therefore important to pass in a plugin id on GeDaialog.Open.
Solutions

I have provided below a conformant CommandData bound solution, could you please check if the issue is reproducible with this variant? When this does not fix your problem, could please also check the following:

  1. Via the trick of the context menu 'look', could you please figure out if your Cinema 4D HTML gadget runs on Trident or Chormium?
  2. Try to start Cinema 4D with -g_forceedge=false and -g_forceedge=true and check if:
    a. -g_forceedge=true indeed will use Edge(Chromium),
    b. if either of these flags will resolve the problem.
  3. I still would not rule out that you somehow screwed up your browser cache. When the problem persists, please delete \{user}\AppData\Roaming\MAXON\{c4d version}\EBWebView.

I will at least update the Python docs to indicate more clearly in c4d.gui.HtmlViewerCustomGui that this gadget is not supported in asynchronous dangling dialogs opened in the Script Manager.

Cheers,
Ferdinand

The code:

"""Provides a simple example for a browser control in a dialog hosted by a CommandData plugin.

The important caveats are here:

    1. CUSTOMGUI_HTMLVIEWER only supports asynchronous dialogs.
    2. Which by extension means that CUSTOMGUI_HTMLVIEWER is not supported in Script Manager scripts.

You must save this file as a pyp plugin file in your plugin folder of choice.
"""

import c4d

class HtmlDialog(c4d.gui.GeDialog):
    """A dialog with the HTML gadget in it.
    """

    URL_DEFAULT: str = r"https://www.baidu.com"

    ID_GDT_URLBAR: int = 1000
    ID_GDT_BROWSER: int = 1001

    def CreateLayout(self):
        """Called by Cinema 4D to populate the dialog with gadgets.
        """
        self.SetTitle("Web Browser")
        self.GroupBegin(0, c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 1)
        self.GroupSpace(5, 5)
        self.GroupBorderSpace(5, 5, 5, 5)
        self.AddEditText(HtmlDialog.ID_GDT_URLBAR, c4d.BFH_SCALEFIT)
        self.htmlView = self.AddCustomGui(HtmlDialog.ID_GDT_BROWSER, c4d.CUSTOMGUI_HTMLVIEWER, "",
            c4d.BFH_SCALEFIT | c4d.BFV_SCALEFIT, 200, 200, c4d.BaseContainer())
        if not isinstance(self.htmlView, c4d.gui.BaseCustomGui):
            return False
        self.GroupEnd()
        return True

    def InitValues(self):
        """Init the dialog values after CreateLayout().
        """
        self.SetString(HtmlDialog.ID_GDT_URLBAR, HtmlDialog.URL_DEFAULT)
        self.htmlView.SetUrl(HtmlDialog.URL_DEFAULT, c4d.URL_ENCODING_UTF16)
        return True

    def Command(self, wid, bc):
        """React to input events in the dialog.
        """
        if wid == c4d.DLG_OK:  # Enter pressed
            url: str = self.GetString(HtmlDialog.ID_GDT_URLBAR)
            if url is not None:
                self.htmlView.SetUrl(url, c4d.URL_ENCODING_UTF16)
        return True

class HtmlDialogCommand(c4d.plugins.CommandData):
    """Opens the HTML gadget dialog.
    """
    ID_PLUGIN: int = 1060020

    def __init__(self) -> None:
        """Initialize the dialog property of the command.
        """
        self._dialog = None

    @property
    def Dialog (self) -> HtmlDialog:
        """Returns the dialog of the command instance.
        """
        if self._dialog is None:
            self._dialog = HtmlDialog()
        
        return self._dialog

    def Execute(self, doc: c4d.documents.BaseDocument) -> bool:
        """Opens the HTML dialog of the command.
        """
        self.Dialog.Open(c4d.DLG_TYPE_ASYNC, HtmlDialogCommand.ID_PLUGIN, defaultw=500, defaulth=500)
        return True

    def RestoreLayout(self, secret: object) -> bool:
        """Restores the HTML dialog on layout changes.
        """
        return self.Dialog.Restore(HtmlDialogCommand.ID_PLUGIN, secret)


if __name__ == '__main__':
    c4d.plugins.RegisterCommandPlugin(
        id=HtmlDialogCommand.ID_PLUGIN,
        str="PC14180 (GeDialog HTML gadget)",
        info=c4d.PLUGINFLAG_SMALLNODE,
        icon=None,
        help="PC14180",
        dat=HtmlDialogCommand())

@ferdinand

Thanks for your explain .

The code you procvde work fine and the black not show again .

.pyp provided code

70681df3-c320-4e74-96f8-9da76e511164-image.png

The old one is also use EdgeHtml viewer . Maybe render black in scripts manager is as a not support way as you mentioned?

.py run in script manager

eb6e2741-393f-4b26-b1f8-54d62c054be5-image.png

Finnally, here is the contrast result .
c0f18ff0-e61e-463d-85d9-b9aae6e2ab8e-image.png

Hey @dunhou,

thanks for your reply and the overview.

I am not quite sure that you consider this solved. Is the problem solved for you now or do you need further assistance?

Cheers,
Ferdinand

@ferdinand
Thnaks for your help, I think it is enough for this specific toppic . It work as espected 😬