Skip to content

Wisej.Web.WebBrowser.eavl(JS) do not works #4817

Closed

Description

@itg-assistant

mgmst asked 2025-07-27 08:55:58 UTC

Wisej.Web.WebBrowser.eavl(JS) do not works

In this code, please advise:

Public Class CTreeView_basic_01_ForBooks
Inherits TreeView

Dim OWebBrowser As Wisej.Web.WebBrowser

Public Sub New(INOGuid As Guid, ByRef INoWebBrowser As Wisej.Web.WebBrowser)
OWebBrowser = INoWebBrowser

With Me
.Dock = DockStyle.Fill
.ShowPlusMinus = True
.ShowRootLines = True
.ShowNodeToolTips = True
End With

End Sub

Private Sub CTreeView_basic_01_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles Me.NodeMouseClick
Dim OTreeNode As TreeNode = e.Node

Dim searchText As String = OTreeNode.Text

Dim js As String =
"var found = false;
var el = document.body;
if (el.innerText.includes('" & searchText.Replace("""", """") & "')) {
el.style.backgroundColor = 'yellow';
found = true;
}
if (!found) alert('Nothing Found');"

OWebBrowser.Eval(js)

End Sub

End Class

Activity

  1. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2025-07-27 10:12:52 UTC

    Hi,

    "does not work" means what? Do you get an error in the console?
    We need a test case with a clear indication of expected result to check this.

    Best regards
    Frank

  2. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-27 11:11:01 UTC

    Nothing at all, complete silence and darkness.

  3. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    JD answered 2025-07-27 12:21:23 UTC

    Turn the light on?

  4. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    JD answered 2025-07-27 12:25:00 UTC

    Javascript is executed by the browser. So I used google and found why your “code” doesn’t work.

    https://stackoverflow.com/ questions/3999101 /get-iframes-document-from-javascript-in- main- document

  5. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-27 14:38:47 UTC

    When it is in the test application (please find attached), I at least receive "Nothing found" message, which points that JS works.

    When it is in a my control for books' content loading- JS not works at all! Why so? Please advice.

    Public Class C_Books_Container
    Inherits Panel
    Private ОWebBrowser As New CUtils.CInterfaceIni.CInterface.C_Wisej_Web_WebBrowser
    Public WithEvents OTV As New CUtils.CInterfaceIni.CInterface.CTreeViewS.CTreeView.CTreeView_basic_01(Guid.NewGuid)
    Private OSplitContainer As New SplitContainer

    Public Sub New(INOStrURLText As String, INOSTRDelimiter As String, INOSTRDelimiter_Internal As String)
    ОWebBrowser.Dock = DockStyle.Fill
    OTV.Dock = DockStyle.Fill

    With OSplitContainer
    .Dock = DockStyle.Fill
    .Panel1.Controls.Add(OTV)
    .Panel2.Controls.Add(ОWebBrowser)
    End With
    ОWebBrowser.Url = New Uri(INOStrURLText)
    Dim OStringPageContent As String = GetTextFromUrl(INOStrURLText)
    F_TableОfContents_Get(OTV, OStringPageContent, INOSTRDelimiter, INOSTRDelimiter_Internal)

    Me.Dock = DockStyle.Fill
    Me.Controls.Add(OSplitContainer)

    End Sub

    Private Sub OTV_NodeMouseClick(sender As Object, e As TreeNodeMouseClickEventArgs) Handles OTV.NodeMouseClick

    Dim searchText = "5"

    Dim js As String =
    "
    var found = false;
    var elements = document.getElementsByTagName('*');
    for (var i = 0; i < elements.length; i++) {
    if (elements[i].innerText && elements[i].innerText.includes('" & searchText.Replace("""", """") & "')) {
    elements[i].scrollIntoView({behavior: 'smooth', block: 'center'});
    elements[i].style.backgroundColor = 'yellow';
    found = true;
    break;
    }
    }
    if (!found) {
    alert('Nothing found.');
    }
    "

    ОWebBrowser.Eval(js)

    End Sub

    End Class

  6. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-28 05:19:17 UTC

    Thank you for your efforts. I can easily fix that. In my case, the problem is that in my BOOKS loading control, the JavaScript doesn’t work at all, whereas in my demo project, it works just fine.

  7. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Frank (ITG) answered 2025-07-28 14:19:49 UTC

    Hi mgmst,

    we need a compilable test case that shows the issue including the URL that you have been testing.
    Otherwise we cannot help any further.

    Best regards
    Frank

  8. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-29 23:09:04 UTC

    Hi,

    I'm coming back with a solution to the problem, whose cause and fix turned out to be utterly absurd.

    If a SplitContainer contains a TreeView and a Wisej.Web.WebBrowser, and the TreeView has more than 4 nodes, then

    Wisej.Web.WebBrowser.Eval(js)
    

    does not execute. But if the number of nodes is 4 or fewer, the JS does execute.

    This bizarre bug makes it impossible to implement an e-book scenario with a browser and a tree view containing more than 4 topics — which is, to put it mildly, EXTREMELY ANNOYING.

    Please find images attached.

  9. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Julie (ITG) answered 2025-07-30 13:31:51 UTC

    Hello, if you can provide a compliable test case we can look into fixing this bug. We would need a compliable test case, not just screenshots or code snippets.

  10. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Alaa (ITG) answered 2025-07-30 14:03:12 UTC

    Hi there,

    I tried to reproduce the issue exactly like you stated, and I couldn't reproduce.

    Furthermore, having a TreeView with more than 4 nodes works, there's no relation as to why having a TreeView with more than 4 nodes would fail evaluating javascript in the WebBrowser component.

    At this point, we're trying to guess what you're trying to accomplish and it's beyond the scope of free Wisej.NET support, please verify the javascript you're trying to execute and make sure everything is escaped correctly.

    The only way for us to verify this is to have a compilable, ready-to-run sample that demonstrates the issue reported.

    Best Regards,
    Alaa

  11. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-30 15:06:39 UTC

    It’s taking me a lot of time, but I’ll get it done. The case is interesting :) I lost two days, 15 hours each, to get to this point.

  12. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-30 15:15:26 UTC

    The problem isn’t with the JavaScript itself, but whether it executes or not. When there are more than 4 nodes, the JavaScript doesn’t run at all. When there are 4 or fewer, it executes and even shows a message. I’m trying to build something like an e-book, with a Table of Contents (TreeView) and positioning to the corresponding chapter when a node is clicked. Nothing complicated. I will prepare a compilable, ready-to-run sample. It will take me a lot of time, but I need a final solution for my e-book.

  13. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-07-30 17:06:16 UTC

    Hi,

    I’m back with a compilable test case that shows the issue, including the URL I’ve been testing. The behavior is exactly as I previously described:

    1. If you load the tree view with all elements, the JavaScript does not execute at all.

    2. If you load it with only 4 elements, the JavaScript executes and displays a message that nothing was found (which is not the issue we’re discussing).

    Execute the two buttons in different sessions, not one after another in one session.

    Please find source code attached. It is based on NET 4.8

    Kind regards!

  14. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Julie (ITG) answered 2025-08-01 14:07:59 UTC

    I tested with your sample, but for me it’s not hitting the js with either button. I put a breakpoint on the eval call (line 262) and it’s not running. Additionally, in the future please include the entire project and not just the Page1.vb file,

  15. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Julie (ITG) answered 2025-08-01 14:26:59 UTC

    The sample works, there is no bug in Wisej. Here are the issues with the sample:

    1. Uses static (Shared in VB.NET means static) buttons. Causing the single instance to be shared (as the name Shared implies) therefore the app is unusable in the browser after the first use closes the page.
      2.There is nothing wrong in Wisej.NET. The Javascript code runs correctly and it does what it has been programmed for. That is, finds the first element that contains the text “5” and sets the background color to yellow. See what getElementsByTagName(“*”) does and what innerText returns. You can try the js using jsfiddle. Check also mozilla for javascript help.
      3.The second sample also works, there is no error at all. The alert is coded in the javascript. And it simply says what it says, that there is no “5” in the second sample.
  16. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    Julie (ITG) answered 2025-08-01 14:40:50 UTC

    Additionally- you can’t check the document of an iFrame if the domains don’t match. You would need to host your own version under the same domain.

  17. itg-assistant commented on Jun 16, 2026

    @itg-assistant
    Author

    mgmst answered 2025-08-04 14:50:07 UTC

    Thank you Julie. It works with 4 tree nodes but do not work with more than 4 tree nodes. JS do not executes. You do not comment about that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    GeneralQuestions, how-tos and everything else.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions