Page not loading content from external sources.
Lenny32 opened this issue · comments
I cannot figure out if the problem comes from my code or it is a bug.
I have this simple page that is loading jQuery but it seem that it is not working.
My C#:
var config = Configuration.Default
.WithCookies()
.WithJavaScript()
.WithCss()
.WithConsoleLogger(context => new ConsoleLogger())
.WithDefaultLoader(setup =>
{
setup.IsResourceLoadingEnabled = true;
setup.IsNavigationEnabled = true;
});
var address = "http://localhost:5000";
var browsingContext = BrowsingContext.New(config);
var document = await browsingContext.OpenAsync(address);
var title = document.Title;
var downloadButton = document.QuerySelector("#downloadButton") as IHtmlButtonElement;
Console.WriteLine("Click");
downloadButton.DoClick();
Console.WriteLine("Clicked");
Console.WriteLine("Title: " + title);
Console.WriteLine("Title: " + document.Title);
My js:
<script src="~/lib/jquery/dist/jquery.js"></script>
<script type="text/javascript">
$(function(){
document.title = 'Hello!';
$('#downloadButton').click(function()
{
document.title = 'I have been clicked! This means jQuery is loaded.';
});
});
</script>
The web page works perfectly in the browser but not in the "code".
Can someone point out what I am doing wrong?
Code looks alright on a first glance.
Two things:
- Is jQuery really loaded? Not sure if the tilde is handled correctly. Please verify that the transfer completes.
- The inner part (callback to the jQuery ready) is executed after everything finished. This includes the C# code (as it has higher priority being dispatched immediately after the document has been loaded, while the JS code is dispatched whenever the TPL can run it). Can you verify that the inner part is never completed? (otherwise it would be invoked with a slight delay, say O(10) ms)
Hope this helps to determine if its a bug or not.
I haven't heard back in a while, so I assume that it could be resolved.