Skip to content

Commit 99e25ec

Browse files
committed
Document webview debug mode as a copy/paste workaround if needed
1 parent c1945ca commit 99e25ec

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ On macOS the setup and installation instructions above should automatically inst
7777

7878
When first launching on Linux you may encounter errors similar to `Namespace […] not available`. This is caused by missing dependencies for [pystray](https://github.com/moses-palmer/pystray/) and [pywebview](https://github.com/r0x0r/pywebview/), which are used to display the menu bar icon and login windows. See the [pywebview dependencies](https://pywebview.flowrl.com/guide/installation.html#dependencies) page and [issue 1](https://github.com/simonrob/email-oauth2-proxy/issues/1#issuecomment-831746642) in this repository for a summary and suggestions about how to resolve this.
7979

80-
A similar issue may occur on Windows with the [pythonnet](https://github.com/pythonnet/pythonnet) package, which is required for pywebview. If you are unable to resolve this by following the [pythonnet installation instructions](https://github.com/pythonnet/pythonnet/wiki/Installation), you may find that installing a [prebuilt wheel](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet) helps fix the issue. Note that pythonnet can take some time to be compatible with the latest major python release, so it can be worth using a slightly older version of python.
80+
A similar issue may occur on Windows with the [pythonnet](https://github.com/pythonnet/pythonnet) package, which is required by [pywebview](https://github.com/r0x0r/pywebview). If you are unable to resolve this by following the [pythonnet installation instructions](https://github.com/pythonnet/pythonnet/wiki/Installation), you may find that installing a [prebuilt wheel](https://www.lfd.uci.edu/~gohlke/pythonlibs/#pythonnet) helps fix the issue. Note that the public releases of pythonnet can take some time to be compatible with the latest major python release, so it can be worth using a slightly older version of python, or a prerelease version of pythonnet. This should be handled by the proxy's `requirements.txt`, but see [issue 45](https://github.com/simonrob/email-oauth2-proxy/issues/45) for a workaround if needed.
8181

8282
### Known issues
83+
- With some combinations of operating systems, web engines and virtual environments, keyboard control or input to the proxy's popup authorisation window may not always work. On Windows this is normally limited to keyboard shortcuts (i.e., copy/paste), but in some virtual environments on macOS the entire keyboard may not work. As a workaround, the proxy will enable pywebview's debug mode when you run the proxy in debug mode, which should allow you to use the right-click context menu to copy/paste to enter text.
8384
- On more recent macOS versions (10.14 and later), you may find that you need to manually load the proxy's launch agent in order to trigger a file access permission prompt when first running as a service. You will know if intervention is necessary if the proxy exits (rather than restarts) the first time you click `Start at login` from its menu bar icon. To resolve this, exit the proxy and then run `launchctl load ~/Library/LaunchAgents/ac.robinson.email-oauth2-proxy.plist` from a terminal. A permission pop-up should appear requesting file access for python. Once this has been approved, the proxy's menu bar icon will appear as normal. In some cases — particularly when running the proxy in a virtual environment, or using the built-in macOS python, rather than the python.org version, or installations managed by, e.g., homebrew, pyenv, etc — the permission prompt does not appear. If this happens it is worth first trying to `unload` and then `load` the service via `launchctl`. If this still does not cause the prompt to appear, the only currently-known resolution is to run the proxy outside of a virtual environment and manually grant Full Disk Access to your python executable via the privacy settings in the macOS System Preferences. You may also need to edit the proxy's launch agent plist file, which is found at the location given in the command above, to set the path to your python executable – it must be the real path rather than a symlink (the `readlink` command can help here). Fortunately this is a one-time fix, and once the proxy loads successfully via this method you will not need to adjust its startup configuration again (except perhaps when upgrading to a newer major macOS version, in which case just repeat the procedure).
8485
- On Windows, [pywebview](https://github.com/r0x0r/pywebview/) versions prior to 3.5 had a [bug](https://github.com/r0x0r/pywebview/issues/720) which caused a crash when the proxy's authentication window was opened. To fix this, make sure you have version 3.5 or later of pywebview (which is automatic if you use the proxy's `requirements.txt`).
8586

emailproxy.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
__author__ = 'Simon Robinson'
55
__copyright__ = 'Copyright (c) 2022 Simon Robinson'
66
__license__ = 'Apache 2.0'
7-
__version__ = '2022-08-03' # ISO 8601 (YYYY-MM-DD)
7+
__version__ = '2022-08-17' # ISO 8601 (YYYY-MM-DD)
88

99
import argparse
1010
import asyncore
@@ -1753,15 +1753,18 @@ def authorise_account(self, _, item):
17531753
if not self.web_view_started:
17541754
# pywebview on macOS needs start() to be called only once, so we use a dummy window to keep it open
17551755
# Windows is the opposite - the macOS technique freezes the tray icon; Linux is fine either way
1756+
# (we also set pywebview debug mode to match our own mode because copy/paste via keyboard shortcuts
1757+
# can be unreliable with 'mshtml'; and, python virtual environments sometimes break keyboard entry
1758+
# entirely on macOS - debug mode works around this in both cases via the right-click context menu)
17561759
self.create_authorisation_window(request)
17571760
if sys.platform == 'darwin':
1758-
webview.start(self.handle_authorisation_windows)
1761+
webview.start(self.handle_authorisation_windows, debug=Log.get_level() == logging.DEBUG)
17591762
self.web_view_started = True # note: not set for other platforms so we start() every time
17601763
else:
17611764
# on Windows, most pywebview engine options return None for get_current_url() on pages created
17621765
# using 'html=' even on redirection to an actual URL; 'mshtml', though archaic, does work
17631766
forced_gui = 'mshtml' if sys.platform == 'win32' and self.args.external_auth else None
1764-
webview.start(gui=forced_gui)
1767+
webview.start(gui=forced_gui, debug=Log.get_level() == logging.DEBUG)
17651768
else:
17661769
WEBVIEW_QUEUE.put(request) # future requests need to use the same thread
17671770
return
@@ -1828,6 +1831,9 @@ def authorisation_window_loaded(self):
18281831
RESPONSE_QUEUE.put({'connection': request['connection'], 'response_url': url})
18291832
self.authorisation_requests.remove(request)
18301833
completed_request = request
1834+
else:
1835+
Log.debug('Waiting for URL matching `redirect_uri`; following browser redirection to',
1836+
'%s/[...]' % urllib.parse.urlparse(url).hostname)
18311837

18321838
if completed_request is None:
18331839
continue # no requests processed for this window - nothing to do yet

0 commit comments

Comments
 (0)