omz:forum

    • Register
    • Login
    • Search
    • Recent
    • Popular

    Welcome!

    This is the community forum for my apps Pythonista and Editorial.

    For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.


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

    Pythonista
    2
    8
    2696
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • mikael
      mikael last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • cvp
        cvp last edited by 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) 
        
        
        1 Reply Last reply Reply Quote 1
        • cvp
          cvp last edited by

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

          mikael 3 Replies Last reply Reply Quote 0
          • mikael
            mikael @cvp last edited by

            @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.

            cvp 1 Reply Last reply Reply Quote 0
            • mikael
              mikael @cvp last edited by

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

              1 Reply Last reply Reply Quote 0
              • mikael
                mikael @cvp last edited by

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

                cvp 1 Reply Last reply Reply Quote 0
                • cvp
                  cvp @mikael last edited by

                  @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.

                  1 Reply Last reply Reply Quote 0
                  • cvp
                    cvp @mikael last edited by

                    @mikael said:

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

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

                    1 Reply Last reply Reply Quote 0
                    • First post
                      Last post
                    Powered by NodeBB Forums | Contributors