You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I test few JavaScript functions (running on Awesonium) with AngleSharp Scripting
This test demonstrates that it is not possible to retrieve current coordinates of DOM element
ScriptingServicejavascriptService=newScriptingService();IConfigurationconfig=Configuration.Default.WithDefaultLoader().With(javascriptService).WithCss();IDocumentashDocument=awaitBrowsingContext.New(config).OpenAsync("http://crawlbin.com/");awaitTask.WhenAll(ashDocument.Requests);stringjsScript=@"var JSAngleSharpExtension = { getPathTo: function(element) { if (element.id !== '' && element.id !== null) return '//*[@id=\'' + element.id + '\']'; if (element === document.body) return element.tagName.toLowerCase(); var ix = 0; var siblings = element.parentNode.childNodes; for (var i = 0; i < siblings.length; i++) { var sibling = siblings[i]; if (sibling === element) return JSAngleSharpExtension.getPathTo(element.parentNode) + '/' + element.tagName.toLowerCase() + '[' + (ix + 1) + ']'; if (sibling.nodeType === 1 && sibling.tagName === element.tagName) { ix++; } } }, getPageXY: function(element) { var x = 0, y = 0; while (element) { x += element.offsetLeft; y += element.offsetTop; element = element.offsetParent; } return [x, y]; }, getLinks: function() { var nodeArray = []; var nodeList = document.links; for (var i = 0; i < nodeList.length; ++i) { var xpathElement = JSAngleSharpExtension.getPathTo(nodeList[i]); nodeArray.push({ href: nodeList[i].href, anchor: nodeList[i].textContent.replace(/[\n\r\t]+/g, ' ').trim(), xPath: xpathElement, position: JSAngleSharpExtension.getPageXY(nodeList[i]) }); } return JSON.stringify(nodeArray); }};JSAngleSharpExtension.getLinks();";stringjsonLinksdata=javascriptService.Engine.Execute(jsScript,newScriptOptions(){Context=ashDocument.DefaultView,Document=ashDocument}).AsString();
The text was updated successfully, but these errors were encountered:
How should that be possible? There is no rendering engine thus the DOM does not know anything about a potential layout.
Yes, this will be possible some time in the future, but never with AngleSharp + AngleSharp.Scripting alone. You will need at least one more library, which gives you a RenderingContext implementation with a whole render tree and CSS evaluation (not only parsing, but real evaluation in the context of a rendering device).
I mark it as enhancement without any milestone set. The test could then be used for some integration tests.
I test few JavaScript functions (running on Awesonium) with AngleSharp Scripting
This test demonstrates that it is not possible to retrieve current coordinates of DOM element
The text was updated successfully, but these errors were encountered: