0

I have an application that uses Chromium Embedded Framework. As an alternative for a setup where CEF is not usable (Python 3.10+ for example), I would like to fallback to a webbrowser to launch a local webapp.

Since I don't have any hook to pass data to the webapp without CEF, I tried to pass a configuration string through a GET parameter. I don't know why, but the query string disappears when I use one with the file:// protocol

example :

webbrowser.open_new_tab('https://google.com?foo=bar')  # this works.
webbrowser.open_new_tab('file:///c:/some/dir/somefile.html?foo=bar')  # this doesn't works.

on the second example. A browser window is open and the URL in the address bar is file:///c:/some/dir/somefile.html

Any idea?

  • Which webbrowser (and on what OS) is your fallback? I can't reproduce using Firefox or Google Chrome on Linux. In any case you may need [this type of fallback](https://stackoverflow.com/questions/35557531/parameters-are-removed-when-opening-local-url-in-default-browser) involving an intermediate temporary file to redirect to your target. – metatoaster Jun 09 '22 at 01:47
  • I'm on windows 10. I fallback on the default browser, which is Chrome Version 102.0.5005.63 (Official Build) (64-bit) . Python 3.10.5 – Pier-Yves Lessard Jun 09 '22 at 01:48
  • You probably will need to create a temporary redirect file as per the linked fallback, or alternative, use [`#` instead of `?` to pass arguments](https://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript) (i.e. instead of using `window.location.search`, use `window.location.hash`). – metatoaster Jun 09 '22 at 01:52
  • Interesting. I indeed think I will have to embed Tornado or something similar in my code. – Pier-Yves Lessard Jun 09 '22 at 01:54
  • A simple [`http.server`](https://docs.python.org/3/library/http.server.html) might be enough if what you have is effective a single page client-side only webapp. Just run it long enough to serve everything the client requires and terminate it. – metatoaster Jun 09 '22 at 01:57
  • Thanks. I kind of designed this non-standard hoping to keep things simple. I actually have a websocket server using the websockets module and I talk to it from a webapp opened with the file:// protocol. If i'm to move to something that serves HTTP, I will go for something that supports websocket and I will kick out the websockets module that run in standalone – Pier-Yves Lessard Jun 09 '22 at 01:59
  • Well, try to see if you can pass data by replace the `?` with `#` (i.e. `#foo=bar`) and see if that works with `webbrowser.open` on Windows, and have a handler that parse that instead to keep things simpler. – metatoaster Jun 09 '22 at 02:01
  • # doesn't go through either.. :( I have a friend who opposed my doubtful will of simplicity. Guess he was right ! – Pier-Yves Lessard Jun 09 '22 at 02:07

0 Answers0