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?