Webview didFinishLoadForFrame

Discussion in 'Mac Programming' started by DennisBlah, Feb 20, 2014.

  1. DennisBlah macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #1
    Hey guys, im struggling with an new project which I'm working on to automize a load of workflows over website forms. For now I'm doing it with applescript by injecting jQuery into Safari. Now I need to make this userfriendly and all.

    I'm known how to inject jquery into an webview. And I found this function:

    Code:
    - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame {
    }
    
    This function should kick in when the webview finished loading the frame.

    However, it seems to get called for every ?'subframe'?? aswell?
    At loading 1 page, it gets called twice. Sometimes 3 till 6 times.

    So I cannot rely on this function to wait till an page is fully finished loading. So I can start running certain jQuery funtions.

    Does anyone have any idea for me, how I can check for tha page being loaded completly??
     
  2. Anim, Feb 24, 2014
    Last edited by a moderator: Feb 24, 2014

    Anim macrumors 6502a

    Anim

    Joined:
    Dec 16, 2011
    Location:
    Macclesfield, UK
    #2
    Check the sender or your webView for mainFrame

    Code:
        if (frame != [sender mainFrame])
    	{
            return;
    	}
     
  3. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #3
    Ok this is almost what I'm looking for, but not exactly. It does only gets called once. Only when
    Code:
    [[[self myWebView] mainFrame] loadRequest:urlRequest];
    
    is being called. But not when I'm manually inside the frame following an link.

    Anything I can do about this ?
    Looking through
    Code:
    [myWebView stringByEvaluatingJavaScriptFromString:@"document.documentElement.outerHTML"];
    
    Also issnt an real success cus it will comes up every time at the didFinishLoadForFrame.
     
  4. Anim macrumors 6502a

    Anim

    Joined:
    Dec 16, 2011
    Location:
    Macclesfield, UK
    #4
  5. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #5
    I'm not sure I really understand what you mean with that tho.
    The state changes functions arent making sense to me. I put in seperate counters for the didFinshLoadForFrame, didStartProvisionalLoadForFrame, didCommitLoadForFrame and didChangeLocationWithinPageForFrame.
    But its not making sense to me, none of any counters are equal when an page is fully loaded.
     
  6. DennisBlah, Mar 4, 2014
    Last edited: Mar 4, 2014

    DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #6
    For now I'm running an timer with an check if the WebView is still loading.

    Code:
    -(void)checkLoading {
        [self runEscalationsScript];
        if([myWebView estimatedProgress] == 0.00) {
            doneLoading = YES;
        } else {
            doneLoading = NO;
        }
    }
    
     
  7. DennisBlah thread starter macrumors 6502

    DennisBlah

    Joined:
    Dec 5, 2013
    Location:
    The Netherlands
    #7
    Anyone having an good sollution for this?
    My sollution up here, is only working when the user has changed page. Not when the app itself changes an page, for example the first load of the webview.

    Cheers!
     

Share This Page