Tracktion / choc

A collection of header only classes, permissively licensed, to provide basic useful tasks with the bare-minimum of dependencies.
Other
529 stars 47 forks source link

Webview error reporting #25

Closed otristan closed 9 months ago

otristan commented 1 year ago

Hi,

Would be great if there was a way to know if navigating to an URL has worked. Unless I am missing something, I don't see any error reporting.

Thanks !

julianstorer commented 1 year ago

AFAIK none of the native APIs give any kind of return code for their navigate functions. It's all async, so I guess there's no way to know what's happened until later. I guess what's needed is a way of asking what the status of the loaded page is?

Too busy to dig into that right now, but will leave it here as a FR..

otristan commented 1 year ago

Yep that would do the trick. Juce webview own version has some callback to do that pageLoadHadNetworkError, pageFinishedLoading so being able to set custom std::function for those would be great.

Thanks !

otristan commented 10 months ago

I'm trying to add this myself but I'm having a hard time figuring how you bind stuff with class_addMethod

I do see in the debugger WebPageProxy::didFailProvisionalLoadForFrame: frameID=4, isMainFrame=1, domain=NSURLErrorDomain, code=-1009, isMainFrame=1

I suppose I should bind like that

 class_addMethod (delegateClass, sel_registerName ("webView:didFailProvisionalLoadWithError:forFrame:"),
                                                              (IMP) (+[](id self, SEL, id, id, id)
                                                              {

but no success. Any hint is welcomed :)

Thanks !

julianstorer commented 10 months ago

That code looks correct to me. When you say "no success", what's actually going wrong?

otristan commented 10 months ago

I think I miss some inner knowledge of how it should work as it looks like I need to call setFrameLoadDelegate to the same delegate you are using in Pimpl ctor but call<void> (webview, "setFrameLoadDelegate:", delegate); fail

My objC knowledge and webkit framework seems too limited

julianstorer commented 10 months ago

Yeah, finding out how any of this stuff works is a nightmare, there's almost no documentation. I've mainly just found random code examples and used trial-and-error for a lot of it. But yes, it does sound like to need to find whatever the method is that attaches this delegate in the right way. I also pushed another change yesterday which does something similar for yet another type of delegate - maybe that could be a clue..

julianstorer commented 10 months ago

BTW, it looks like that method is from the WebFrameLoadDelegate class, which is deprecated. Might be worth finding out what its replacement is before putting too much effort into getting that working?

otristan commented 10 months ago

you pointed in the right direction I need to call call<void> (webview, "setNavigationDelegate:", delegate); in the ctor and then add a callback on webView:didFailProvisionalNavigation:withError:

Will investigate further

otristan commented 10 months ago

Here is a quick diff which at least show the error message like it happens on Windows diff.txt Can give you some start to implement something like Juce own version does.

The drawsBackground to false allows to have a custom paint showed while the page is loading

julianstorer commented 10 months ago

OK, ta, I'll see if I can add something along those lines

otristan commented 10 months ago

I've moved to something like that in my latest test. diff2.txt I've checked how to do something similar on Windows but this is not 2 line of code

julianstorer commented 10 months ago

OK, well I've added the message display to get things started. Can add the callback function at some point when we can do it on more than one platform

otristan commented 10 months ago

yep on Windows at least you have a default error message so this is more annoying on OSX indeed

otristan commented 10 months ago

If you want something more fancy, my web guy did this for me start.txt

julianstorer commented 10 months ago

I think with library code like this it's always a good policy to avoid anything fancy! When there's a callback, people can customise it however they like

otristan commented 9 months ago

Just wanted to mention that OSX WebKit reports some error which are not really error like NSURLErrorCancelled so I did something like that in my fork https://github.com/otristan/choc/commit/a69edcaa7fc66a1f812f37ae943ff15e2c299d28

julianstorer commented 9 months ago

Oh, good catch, thanks, I'll add something for that.