Skip to content

Commit

Permalink
Merge pull request #132 from jacekszymanski/profile-patch
Browse files Browse the repository at this point in the history
QWebEngineProfile may be offTheRecord
  • Loading branch information
vlaci authored Jul 14, 2023
2 parents b08bb84 + 6a8863d commit 222c8ff
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions openconnect_sso/browser/webengine_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@


app = None
profile = None
logger = structlog.get_logger("webengine")


Expand Down Expand Up @@ -68,6 +69,7 @@ async def get_state_async(self):
def run(self):
# To work around funky GC conflicts with C++ code by ensuring QApplication terminates last
global app
global profile

signal.signal(signal.SIGTERM, on_sigterm)
signal.signal(signal.SIGINT, signal.SIG_DFL)
Expand All @@ -78,6 +80,7 @@ def run(self):
if self.display_mode == config.DisplayMode.HIDDEN:
argv += ["-platform", "minimal"]
app = QApplication(argv)
profile = QWebEngineProfile("openconnect-sso")

if self.proxy:
parsed = urlparse(self.proxy)
Expand All @@ -99,7 +102,7 @@ def ignore():
pass

force_python_execution.timeout.connect(ignore)
web = WebBrowser(cfg.auto_fill_rules, self._states.put)
web = WebBrowser(cfg.auto_fill_rules, self._states.put, profile)

startup_info = self._commands.get()
logger.info("Browser started", startup_info=startup_info)
Expand All @@ -121,6 +124,7 @@ async def wait(self):


def on_sigterm(signum, frame):
global profile
logger.info("Terminate requested.")
# Force flush cookieStore to disk. Without this hack the cookieStore may
# not be synced at all if the browser lives only for a short amount of
Expand All @@ -129,7 +133,7 @@ def on_sigterm(signum, frame):

# See: https://github.com/qutebrowser/qutebrowser/commit/8d55d093f29008b268569cdec28b700a8c42d761
cookie = QNetworkCookie()
QWebEngineProfile.defaultProfile().cookieStore().deleteCookie(cookie)
profile.cookieStore().deleteCookie(cookie)

# Give some time to actually save cookies
exit_timer = QTimer(app)
Expand All @@ -138,10 +142,12 @@ def on_sigterm(signum, frame):


class WebBrowser(QWebEngineView):
def __init__(self, auto_fill_rules, on_update):
def __init__(self, auto_fill_rules, on_update, profile):
super().__init__()
self._on_update = on_update
self._auto_fill_rules = auto_fill_rules
page = QWebEnginePage(profile, self)
self.setPage(page)
cookie_store = self.page().profile().cookieStore()
cookie_store.cookieAdded.connect(self._on_cookie_added)
self.page().loadFinished.connect(self._on_load_finished)
Expand Down

0 comments on commit 222c8ff

Please sign in to comment.