Forum Archive

Any way to find the URL of a page opened in a tab

mikael

I have a third-party module that opens a page in a tab (beside the Console). I would need to know the url of the actual page opened after some redirects. This is difficult as the tab does not show page address?

@cvp, I think you are the tabs master, do you have something ready?

cvp

@mikael See here if only one tab and if I correctly understand the request 😀

from   objc_util import *
# open tab with url, then swipe to right and run this script
@on_main_thread
def searchTabURL():
    win = ObjCClass('UIApplication').sharedApplication().keyWindow()
    main_view = win.rootViewController().view() 
    ret = '' 
    def analyze(v,indent):
        ret = None
        for sv in v.subviews():
            #print(indent,sv._get_objc_classname())
            if 'UIWebBrowserView' in str(sv._get_objc_classname()):
                return sv.webView().mainFrameURL()
            ret = analyze(sv,indent+'  ')
            if ret:
                return ret
    ret = analyze(main_view,'')
    return ret

if __name__ == "__main__":
    url = searchTabURL() 
    print(url) 

cvp

@mikael Is that not what you wanted or does it not work for you?

mikael

@cvp, thanks! Sorry for the delay. 3 kids in home schooling are severely cutting into my ability to concentrate on something deemed ”non-critical”... I expect I will not be quite as online as I have been before.

It looks like you are doing the right thing, but for some reason I am just getting None. Might be an iPad/iPhone thing – I will experiment.

mikael

@cvp, ho, just running it the second time gave me the URL, so now we can move forward in the other thread.

mikael

@cvp, now I got it. The web tab needs to be the active one to get URL.

cvp

@mikael said:

Sorry for the delay. 3 kids in home schooling ...

I'm the one who apologizes, I'm retired with my wife and actually without physical contact with my sons and grandchildren, thus I forgot other people have a big load of their children at home.

cvp

@mikael said:

The web tab needs to be the active one to get URL.

I had only tested with one tab, thus...