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.


    3.4: URL schemes not working in built-in browser

    Pythonista
    url schemes webbrowser pythonista 3
    4
    12
    147
    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.
    • jimrhiz
      jimrhiz last edited by

      Thanks very much for the new release, @omz!

      There seems to be an issue with pythonista:// and other URL schemes in the built-in browser. Consider this HTML file:

      <!doctype html>
      <html>
      <head>
          <meta charset="utf-8">
          <title>Test URL schemes</title>
      </head>
      <body>
      <h1>Test URL schemes in Pythonista 3.4 built-in web browser</h1>
      
      <ul>
          <li><a href="https://google.com/">https://google.com/</a>
          <li><a href="pythonista://test.py?action=run">pythonista://test.py?action=run</a>
          <li><a href="shortcuts://">shortcuts://</a>
      </ul>
      
      </body>
      </html>
      

      It can be loaded into the built-in browser with

      webbrowser.open(f'file:{path}')
      

      where path is the full absolute path to the HTML file.

      In Pythonista 3.3, all three links open: for the Google link, within the built-in browser; with the other two in the respective app. Further, if you long-press on any of the links, there is a popup previewing the URL with an action menu.

      At 3.4, the Google link behaves as before. But the other two do nothing, either on a quick tap or a long press. This is on an old iPad running iPadOS 15.7.5.

      I have an extensive web app within Pythonista that relies on the 3.3 behaviour. I hope there is a solution which will make it work again in 3.4, so I can upgrade my main iPad. I'd appreciate any suggestions.

      cvp 1 Reply Last reply Reply Quote 1
      • cvp
        cvp @jimrhiz last edited by cvp

        @jimrhiz this works

        webbrowser.open('shortcuts://')
        

        Not sure you could use as workaround of your html way

        I know that ObjectiveC SFSafariViewController allows to open https[s] only.

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

          Thank you for the reply, @cvp.

          Right, webbrowser.open works with app URL schemes from within a running Pythonista script. But it does not help with calling apps from the HTML page that I construct and display in the built-in Pythonista web browser.

          I know that ObjectiveC SFSafariViewController allows to open https[s] only

          Is ObjectiveC SFSafariViewController the tool that implements the built-in web browser in Pythonista 3.4? If so, there must have been a change since Pythonista 3.3, because the built-in browser there was able to open schemes other than http[s].

          Also, Safari itself can open app URL schemes, including pythonista:// for example, from a suitable web page. It puts up an annoying confirmation dialogue, which is one of the reasons I want to avoid it, but then it does goes ahead.

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

            @jimrhiz said

            Is ObjectiveC SFSafariViewController the tool that implements the built-in web browser in Pythonista 3.4

            Pythonista doc, in "What’s New in Pythonista Version 3.4 " says

            The in-app browser for the webbrowser module now uses WKWebView and has a new “Open in Safari” button

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

              Thanks for the information, @cvp.

              This is also seems to mean that JavaScript no longer works at all in file: pages in the built-in web browser. If there's no workaround, it's a major loss of functionality.

              cvp 2 Replies Last reply Reply Quote 0
              • cvp
                cvp @jimrhiz last edited by

                @jimrhiz said

                This is also seems to mean that JavaScript no longer works at all in file: pages in the built-in web browser

                Why do you say that?

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

                  @jimrhiz you could try this

                  #import webbrowser
                  import os
                  import ui
                  path = os.path.abspath('a9.html')
                  
                  #webbrowser.open(f'file:{path}')
                  
                  wv = ui.WebView()
                  wv.load_url(f'file:{path}')
                  wv.present()
                  
                  1 Reply Last reply Reply Quote 0
                  • jimrhiz
                    jimrhiz last edited by

                    @cvp asked

                    Why do you say that?

                    The reason I say JavaScript no longer works is this file:

                    <!doctype html>
                    <html>
                    <head>
                        <meta charset="utf-8">
                        <title>Test JavaScript</title>
                        <script>
                            alert("Hello world!")
                        </script>
                    </head>
                    <body>
                        <h1>Test JavaScript in Pythonista 3.4 built-in web browser</h1>
                    </body>
                    </html>
                    

                    As before it can be loaded with webbrowser.open(f'file:{path}') . On Pythonista 3.3 the "Hello World!" message appears immediately, but on 3.4 it's not there at all.

                    Thanks for the ui.WebView idea. I'll experiment.

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

                      @jimrhiz ui.WebView uses the old (deprecated) ObjectiveC UIWebView class which is exactly what WebBrowser of Pythonista before 3.4 was using

                      And there, your JavaScript html works

                      1 Reply Last reply Reply Quote 0
                      • omz
                        omz last edited by omz

                        I made a last-minute change to use WKWebView instead of UIWebView for the in-App browser, and it looks like I forgot about some details.

                        Here's sort of a workaround, similar to the one @cvp suggested, but opening in a tab, like the built-in one.

                        import ui
                        import webbrowser
                        from urllib.parse import urlparse
                        
                        class WebDelegate (object):
                          def webview_should_start_load(self, webview, url, nav_type):
                            if urlparse(url).scheme in  ['http', 'https', 'file']:
                              return True
                            else:
                              webbrowser.open(url)
                        
                        def open_browser(url):
                          v = ui.WebView()
                          v.name = 'Web Browser'
                          v.delegate = WebDelegate()
                          v.load_url(url)
                          v.present('panel')
                        
                        import os
                        url = 'file://' + os.path.abspath('test.html')
                        open_browser(url)
                        
                        
                        P 1 Reply Last reply Reply Quote 0
                        • P
                          pleasehelp @omz last edited by

                          @omz Back/forward button also sometimes wrongly disabled in builtin browser. You should update them by KVO observing the WKWebView’s canGoBack and canGoForward properties, not just every time a page is loaded, due to a new feature that allows back-forward buttons to work within single page navigation, by the JavaScript history API

                          1 Reply Last reply Reply Quote 1
                          • jimrhiz
                            jimrhiz last edited by

                            Great, @omz, thank you very much for this solution! It is working like a charm so far. I'm looking forward to upgrading to 3.4 on my main iPad soon.

                            Thanks also @cvp for helpful information and suggestions.

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