From 695182c44fefecd461bbe88679bebf2aea25a6af Mon Sep 17 00:00:00 2001 From: claudi Date: Wed, 4 Mar 2026 12:56:49 +0100 Subject: [PATCH] fix: enhance authorization token capture logic based on checkout feature status --- .../ui/bridge_script_intercept.js | 23 +++++++++++-------- src/webdrop_bridge/ui/main_window.py | 8 ++++--- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/webdrop_bridge/ui/bridge_script_intercept.js b/src/webdrop_bridge/ui/bridge_script_intercept.js index 67ec302..f7a2b04 100644 --- a/src/webdrop_bridge/ui/bridge_script_intercept.js +++ b/src/webdrop_bridge/ui/bridge_script_intercept.js @@ -17,16 +17,21 @@ var listenerPatchActive = true; var dragHandlerInstalled = false; - // Capture Authorization token from XHR requests + // Capture Authorization token from XHR requests (only if checkout is enabled) window.capturedAuthToken = null; - var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader; - XMLHttpRequest.prototype.setRequestHeader = function(header, value) { - if (header === 'Authorization' && value.startsWith('Bearer ')) { - window.capturedAuthToken = value; - console.log('[Intercept] Captured auth token'); - } - return originalXHRSetRequestHeader.apply(this, arguments); - }; + if (window.webdropConfig && window.webdropConfig.enableCheckout) { + console.log('[Intercept] Auth token capture enabled (checkout feature active)'); + var originalXHRSetRequestHeader = XMLHttpRequest.prototype.setRequestHeader; + XMLHttpRequest.prototype.setRequestHeader = function(header, value) { + if (header === 'Authorization' && value.startsWith('Bearer ')) { + window.capturedAuthToken = value; + console.log('[Intercept] Captured auth token'); + } + return originalXHRSetRequestHeader.apply(this, arguments); + }; + } else { + console.log('[Intercept] Auth token capture disabled (checkout feature inactive)'); + } // ============================================================================ // PART 1: Intercept Angular's dragstart listener registration diff --git a/src/webdrop_bridge/ui/main_window.py b/src/webdrop_bridge/ui/main_window.py index c161621..8b9a119 100644 --- a/src/webdrop_bridge/ui/main_window.py +++ b/src/webdrop_bridge/ui/main_window.py @@ -667,10 +667,11 @@ class MainWindow(QMainWindow): logger.debug(f" [{i+1}] {m['url_prefix']} -> {m['local_path']}") # Generate config object as JSON - config_obj = {"urlMappings": mappings} + config_obj = {"urlMappings": mappings, "enableCheckout": self.config.enable_checkout} config_json = json.dumps(config_obj) logger.debug(f"Config JSON size: {len(config_json)} bytes") + logger.debug(f"Checkout enabled: {self.config.enable_checkout}") # Generate JavaScript code - Safe injection with error handling config_js = f""" @@ -680,6 +681,7 @@ class MainWindow(QMainWindow): console.log('[WebDrop Config] Starting configuration injection...'); window.webdropConfig = {config_json}; console.log('[WebDrop Config] Configuration object created'); + console.log('[WebDrop Config] Checkout enabled: ' + window.webdropConfig.enableCheckout); if (window.webdropConfig && window.webdropConfig.urlMappings) {{ console.log('[WebDrop Config] SUCCESS: ' + window.webdropConfig.urlMappings.length + ' URL mappings loaded'); @@ -1335,11 +1337,11 @@ class MainWindow(QMainWindow): sessions. Also disconnects and reconnects the page to ensure clean state. """ logger.info("Clearing cache and cookies") - + try: # Clear cache and cookies in the web view profile self.web_view.clear_cache_and_cookies() - + # Show confirmation message QMessageBox.information( self,