Results 1 to 40 of 555

Thread: VB6 WebView2-Binding (Edge-Chromium)

Hybrid View

  1. #1

    Thread Starter
    PowerPoster
    Join Date
    Jun 2013
    Posts
    7,454

    Re: VB6 WebView2-Binding (Edge-Chromium)

    Quote Originally Posted by tmighty2 View Post
    Sorry to ask again, but can you please show me an example?

    My problem is that I don't know how to access the hotspots that the function returns.
    I have tried this:

    Dim hotspots
    hotspots = WV.jsRun("window._grid_ensureHotSpotIds")

    Debug.Print UBound(hotspots) 'here it errors out saying "Type mismatch" (obviously it's not an array. It's empty)
    You will have to check in your js-source, whether the window._grid_ensureHotSpotIds function,
    returns something at all...

    And if it does, then gather these results in your own array -
    and then return this array as a serialized JSON-string via:
    return JSON.stringify(myHotspotArray)

    At the vb6-side you can then easily convert that returned JSON-string into a cCollection:
    Dim oHotSpots As cCollection
    Set oHotSpots = New_c.JSONDecodeToCollection(WV.jsRun("window._grid_ensureHotSpotIds"))

    HTH

    Olaf

  2. #2
    Fanatic Member
    Join Date
    Jul 2017
    Posts
    761

    Question Re: VB6 WebView2-Binding (Edge-Chromium)

    My problem is that stringify does not work. hotspots.count is 196, but the line "alert('after stringify');" is not fired in the code below:

    Code:
    HTMLElement.prototype._grid_ensureHotSpotIds = function(selector)
    {
      let hotSpots = [];
      if (selector != null)
      {
        var splitSelector = selector.split(',');
        //Some websites need a selector that's too complex to make just in one step. So we need to split the selector on commas and do querySelectors that will chain the results.
        splitSelector.forEach(singleSelector =>
        {
          if (hotSpots != null)
          {
            let hotSpotsFound = this.querySelectorAll(singleSelector);
            if (hotSpotsFound != null)
            {
              hotSpots = hotSpots.concat(Array.from(hotSpotsFound));
            }
            else
            {
              //alert('hotspots is null in splitselector');
            }
          }
        });
      }
      else
      {
        hotSpots = this.querySelectorAll(hotSpotSelector);
      }
      //alert("Found " + hotSpots.length + " hotspots."); // Alert showing the number of hotspots found
      
      for (var hotSpot of hotSpots)
      {
        hotSpot._grid_ensureId();
      }
      alert('before stringify');
      let hotSpotsString = JSON.stringify(hotSpots); // Convert the hotspots array to a JSON string
      alert('after stringify');
      alert("Hotspots: " + hotSpotsString); // Alert showing the hotspots as a string
      
      return hotSpotsString; // Return the hotspots array as a JSON string
    };
    I guess it could be due to members of such a hotspot.
    I have uploaded the prototype of "element" which I try to stringify:

    https://drive.google.com/file/d/1XPd...usp=share_link

    Edit: I know now that in C# the hotspots are handled like this:

    C# code:

    Code:
    protected virtual Task<HtmlElementReference> GetStartElementAsync(HtmlElementReference startElement, CursorDirection direction)
    		{
    			return Task.FromResult<HtmlElementReference>(startElement);
    		}
    
    		protected async Task<HtmlElementReference> HandleFindElementResultAsync(ElementCursorBase.FindElementResult result, IWebBrowserFrame currentFrame, string getNodesFunc, int? nodeType, CursorDirection direction)
    		{
    			HtmlElementReference htmlElementReference;
    			HtmlElementReference elementReferenceAsync;
    			CursorDirection cursorDirection;
    			string str;
    			if (result != null)
    			{
    				switch (result.ResultType)
    				{
    					case ElementCursorBase.FindElementResultType.Element:
    					{
    						htmlElementReference = new HtmlElementReference(currentFrame.Identifier, result.Element);
    						return htmlElementReference;
    					}
    					case ElementCursorBase.FindElementResultType.IterateUpIntoParent:
    					{
    						HtmlElementReference elementReferenceAsync1 = await WebBrowserExtensionMethods.GetElementReferenceAsync(currentFrame.Parent, String.Format("document.querySelector('[data-grid-frame-identifier=\"{0}\"]')._grid_ensureId()", currentFrame.Identifier));
    						cursorDirection = direction;
    						if (cursorDirection == CursorDirection.Backward || cursorDirection == CursorDirection.BackwardToHeading)
    						{
    							getNodesFunc = "_grid_getPreviousNodes";
    						}
    						htmlElementReference = await this.FindElementAsync(elementReferenceAsync1, getNodesFunc, nodeType, false, direction);
    						return htmlElementReference;
    					}
    					case ElementCursorBase.FindElementResultType.IterateDownIntoFrame:
    					{
    						using (IWebBrowserFrame frame = this._webBrowser.GetFrame(Convert.ToUInt64(result.Element)))
    						{
    							if (frame != null)
    							{
    								cursorDirection = direction;
    								switch (cursorDirection)
    								{
    									case CursorDirection.Forwards:
    									case CursorDirection.ForwardsToHeading:
    									{
    										str = "document.body._grid_ensureId()";
    										break;
    									}
    									case CursorDirection.Backward:
    									case CursorDirection.BackwardToHeading:
    									{
    										str = "document.body._grid_getLastElement()._grid_ensureId()";
    										getNodesFunc = "_grid_getSelfAndPreviousNodes";
    										break;
    									}
    									default:
    									{
    										throw new InvalidOperationException();
    									}
    								}
    								elementReferenceAsync = await WebBrowserExtensionMethods.GetElementReferenceAsync(frame, str);
    							}
    							else
    							{
    								htmlElementReference = null;
    								return htmlElementReference;
    							}
    						}
    						frame = null;
    						htmlElementReference = await this.FindElementAsync(elementReferenceAsync, getNodesFunc, nodeType, true, direction);
    						return htmlElementReference;
    					}
    				}
    				throw new InvalidOperationException();
    			}
    			else
    			{
    				htmlElementReference = null;
    			}
    			return htmlElementReference;
    			throw new InvalidOperationException();
    		}
    Would there be any way to do the same with your browser?
    Last edited by tmighty2; Mar 25th, 2023 at 04:05 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width