From 3c6b29e8574b64b801344c7ba4f9e76d7ec4fa69 Mon Sep 17 00:00:00 2001 From: Mally Dang Date: Mon, 7 Sep 2026 18:06:43 +0700 Subject: [PATCH] chore: move header setting thing to `RewardsTaskUtils` --- src/main.py | 8 -------- src/rewards_tasks.py | 10 ++++++++++ 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/main.py b/src/main.py index fbae9f3..64cb5fc 100644 --- a/src/main.py +++ b/src/main.py @@ -42,14 +42,6 @@ def run_account(account: accounts.Account) -> bool: """Work one account. Returns whether the browser started.""" try: driver = webdriver.Edge(options=build_options(account)) - # Set headers to spoof the rewards app for the rewards only quests - driver.execute_cdp_cmd("Network.enable", {}) - headers = { - "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 Edg/151.0.0.0 MSRewards/Desktop/1.1.0", - "X-Rewards-Source": "msrewards-desktop", - } - - driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": headers}) except SessionNotCreatedException as exc: # Chromium allows one process per user data directory. When the profile # is already open the driver's copy exits during startup, and selenium diff --git a/src/rewards_tasks.py b/src/rewards_tasks.py index ffa1b42..595cf93 100644 --- a/src/rewards_tasks.py +++ b/src/rewards_tasks.py @@ -24,6 +24,16 @@ class RewardsTaskUtils: def __init__(self, driver: webdriver.Edge): self.driver = driver + # Set headers to spoof the rewards app for the rewards only quests + self.driver.execute_cdp_cmd("Network.enable", {}) + + headers = { + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36 Edg/151.0.0.0 MSRewards/Desktop/1.1.0", + "X-Rewards-Source": "msrewards-desktop", + } + + self.driver.execute_cdp_cmd("Network.setExtraHTTPHeaders", {"headers": headers}) + self.driver.get("https://rewards.bing.com/") self.tab_utils = tab_utils.TabUtils(driver)