holzschu / a-shell

A terminal for iOS, with multiple windows
BSD 3-Clause "New" or "Revised" License
2.64k stars 116 forks source link

Feature Request: Python and WebView #708

Open peter-schwier opened 11 months ago

peter-schwier commented 11 months ago

How difficult would it be to register a new browser type in https://docs.python.org/3/library/webbrowser.html that would open the url in a popover web view? Similar to the view command, but, directed to the URL the code provides.

I'm thinking if this exists, then someone can write a "web server" in python, and trigger open the web view to connect to the web server hosted in the background. No special security rules needed for the web view, because it will just be using the normal http/https communication.

Python also supports the webbrowser command so that this could be used from shell scripts and/or lua. python -m webbrowser -t "https://www.python.org"

peter-schwier commented 11 months ago

I checked the current default behavior. Right now, it puts a-Shell in the background and opens the normal browser (Safari in my case). I'm hoping for something that would let the python continue running but show the webview.

holzschu commented 11 months ago

Well, you're in luck. The latest TestFlight version (https://testflight.apple.com/join/WUdKe3f4 for a-Shell, https://testflight.apple.com/join/REdHww5C for a-Shell mini) has a brand new internal web browser (internalbrowser) that opens the URL in an a-Shell window, which lets Python continue running but shows the webview. You can call it either by its name (internalbrowser url) or by setting the environment variable BROWSER to internalbrowser. Python will call the command BROWSER if it is set. The command openurl will open the browser defined by BROWSER. In my tests, it's robust enough to let you run Jupyter notebooks. You can navigate back and forward with left-edge-swipe and right-edge-swipe, so you can go back to the terminal. It's not perfect yet: I'd like to have buttons at the top (but I don't see how to do it), you don't always get keyboard control when you go back to the terminal, and there is no output while the terminal is masked by the web view. For the last point, if you have two windows side by side on an iPad (with newWindow), the webview will likely be on the second window, so you can have both web view and output.

peter-schwier commented 11 months ago

Awesome. I will test that out.

I was looking into writing some tools that I wanted to use on a desktop and on my phone. Being able to use an HTML webpage as the front-end for the tool was the last piece I needed so I didn't have to re-implement multiple UIs between windows, linux, iPhone, iPad, and my SteamDeck.

Emasoft commented 5 months ago

The internalbrowser is great. What about console output? Is there a way to see the console error messages from the current page? Otherwise debugging javascript would be impossible.

holzschu commented 5 months ago

For debugging, you can redefine console.log in any way you want, including writing to a file or displaying the text on screen. If you have a Mac, you can also connect it to the iPad. Then the "Develop" menu on Safari on the Mac lets you debug any JavaScript window on the iPad, including a-Shell.