diff --git a/src/utils.py b/src/utils.py index 52609d9..242d45f 100644 --- a/src/utils.py +++ b/src/utils.py @@ -153,11 +153,34 @@ def get_webdriver(proxy: dict = None) -> WebDriver: options.add_argument('--disable-gpu-sandbox') options.add_argument('--ignore-certificate-errors') options.add_argument('--ignore-ssl-errors') - # disable breaking popup - options.add_argument("--disable-features=LocalNetworkAccessChecks") - # disable AI model download - options.add_argument("--disable-features=OptimizationGuideOnDeviceModel") - options.add_argument("--disable-features=GlicActor,GlicActorUi,PromptAPIForGeminiNano,PromptAPIX,PromptAPINoTranslation,SummarizationAPIForGeminiNano,WriterAPIForGeminiNano,TranslationAPI,LanguageDetectionAPI,AIPromptAPI,AIRewriteAPI,AIWritingAssistant,AIGenerativeSuggestions,AIGeneratedFlags,AICompositionFeature,HistoryAI,TabOrganizer,SmartSuggestion") + + # Chrome parses --disable-features as a single value: passing the switch a + # second time keeps the last value and silently discards the earlier one + # whole, along with every feature it named. Collect the names here and emit + # one switch once, below, after every branch that may add to them. + disabled_features = [ + 'LocalNetworkAccessChecks', # disable breaking popup + # disable AI model download + 'OptimizationGuideOnDeviceModel', + 'GlicActor', + 'GlicActorUi', + 'PromptAPIForGeminiNano', + 'PromptAPIX', + 'PromptAPINoTranslation', + 'SummarizationAPIForGeminiNano', + 'WriterAPIForGeminiNano', + 'TranslationAPI', + 'LanguageDetectionAPI', + 'AIPromptAPI', + 'AIRewriteAPI', + 'AIWritingAssistant', + 'AIGenerativeSuggestions', + 'AIGeneratedFlags', + 'AICompositionFeature', + 'HistoryAI', + 'TabOrganizer', + 'SmartSuggestion', + ] language = os.environ.get('LANG', None) if language is not None: @@ -170,13 +193,15 @@ def get_webdriver(proxy: dict = None) -> WebDriver: proxy_extension_dir = None if proxy and all(key in proxy for key in ['url', 'username', 'password']): proxy_extension_dir = create_proxy_extension(proxy) - options.add_argument("--disable-features=DisableLoadExtensionCommandLineSwitch") + disabled_features.append('DisableLoadExtensionCommandLineSwitch') options.add_argument("--load-extension=%s" % os.path.abspath(proxy_extension_dir)) elif proxy and 'url' in proxy: proxy_url = proxy['url'] logging.debug("Using webdriver proxy: %s", proxy_url) options.add_argument('--proxy-server=%s' % proxy_url) + options.add_argument('--disable-features=%s' % ','.join(disabled_features)) + # note: headless mode is detected (headless = True) # we launch the browser in head-full mode with the window hidden windows_headless = False