NJKWebViewProgress icon indicating copy to clipboard operation
NJKWebViewProgress copied to clipboard

Progress issue with single page web app

Open SPopenko opened this issue 11 years ago • 14 comments

On such web sites like: http://www.toysrus.com/ the component has issue with detecting load completion. It means that it never get 100% load indicator. Please take a look on the screenshot.

toysrus

SPopenko avatar Apr 10 '14 07:04 SPopenko

@SPopenko Thanks reporting. I'll check that website.

ninjinkun avatar Apr 14 '14 22:04 ninjinkun

@SPopenko I've tried several times to access Toysrus site, and problem happened only one time. I'm looking for condition what caused this problem. Do you know how to represent it?

ninjinkun avatar Apr 30 '14 02:04 ninjinkun

@ninjinkun I think that it happens when page has error in load and system trigger didFailLoadWithError

Most probably it could be when block executed twice for the same page. On error and on start load triggers.

    if (interactive) {
        _interactive = YES;
        NSString *waitForCompleteJS = [NSString stringWithFormat:@"window.addEventListener('load',function() { var iframe = document.createElement('iframe'); iframe.style.display = 'none'; iframe.src = '%@'; document.body.appendChild(iframe);  }, false);", completeRPCURL];
        [webView stringByEvaluatingJavaScriptFromString:waitForCompleteJS];
    }

SPopenko avatar Apr 30 '14 05:04 SPopenko

@SPopenko Thanks to your suggestion. It represented under bad network with Network Link Conditioner. I'll try to solve it.

ninjinkun avatar Apr 30 '14 11:04 ninjinkun

I'm noticing an issue like this as well where sometimes a page doesn't reach 100%. Some will get about half way, some will only reach 10%.

If you attempt to view a github.com page, this can happen. Could this be related to history API?

stevemckenzie avatar Jun 26 '14 19:06 stevemckenzie

I can confirm the problem for me is related to your JS on load event listener. The iframe never loads so the completeRPCURL is never requested.

A small change I made that is looking reliable, instead of using an iframe, just using a window.location:

[NSString stringWithFormat:@"window.addEventListener('load',function() { window.location = '%@'; }, false);", completeRPCURL];

stevemckenzie avatar Jun 26 '14 19:06 stevemckenzie

Hey @ninjinkun, do you think solution suggested by @stevemckenzie good enough to integrate it in the new release? :)

SPopenko avatar Jun 27 '14 06:06 SPopenko

@stevemckenzie window.location = causes to override UIWebView referred URL. But your suggestion was big hint. I found incomplete problem is caused by Content Security Policy. They refused iframe from other domain. I'm planning that fall back to window.location when iframe is refused, or change PRC URL scheme and domain to content URL.

ninjinkun avatar Jun 27 '14 09:06 ninjinkun

@ninjinkun this sounds like a good plan. Could you let us know please when you make new release?

SPopenko avatar Jun 27 '14 11:06 SPopenko

@ninjinkun but because you return NO in the shouldStartLoadWithRequest delegate method, isn't it fine? I've used this method to relay info back to the delegate before.

stevemckenzie avatar Jun 27 '14 14:06 stevemckenzie

@stevemckenzie You are right. I even thought window.location affects current URL. But I can't find any problem with shouldStartLoadWithRequest returns NO as your suggestion.

I research two methods again.

  • window.location or location.href
    • can handle single request
  • IFrame

NJKWebViewProgress can use both two methods for single complete request. However, I don't want to change method for conservative reason. Currently IFrame works fine without the site using Content Security Policy. And this CSP problem can avoid with #27. I want to go using proven IFrame method. Do you have any reason to use window.location?

@SPopenko I made pull request with new RPC URL for avoid Content Security Policy. Please try this version. https://github.com/ninjinkun/NJKWebViewProgress/pull/27

ninjinkun avatar Jun 29 '14 05:06 ninjinkun

@ninjinkun thanks for this pull, it looks like it works for me! :+1:

SPopenko avatar Jul 14 '14 13:07 SPopenko

@SPopenko Thank you!

ninjinkun avatar Jul 15 '14 08:07 ninjinkun

@ninjinkun I'm sorry so long time for issue. I use new source NJKWebViewProgress on GIT. but this issue still happen. Can you support me how to fix it. thanks!

minhtriphung avatar Sep 01 '15 02:09 minhtriphung