diff --git a/CHANGELOG.asciidoc b/CHANGELOG.asciidoc index 8d0bf22f3..bae99847c 100644 --- a/CHANGELOG.asciidoc +++ b/CHANGELOG.asciidoc @@ -79,6 +79,8 @@ Fixed - The validation for colors in stylesheets is now less strict, allowing for all valid Qt values. - data: URLs now aren't added to the history anymore. +- window.navigator.userAgent is now set correctly when customizing the user + agent on QtWebEngine. v0.10.1 ------- diff --git a/qutebrowser/browser/webengine/webenginesettings.py b/qutebrowser/browser/webengine/webenginesettings.py index aebc4c7f7..a2135210c 100644 --- a/qutebrowser/browser/webengine/webenginesettings.py +++ b/qutebrowser/browser/webengine/webenginesettings.py @@ -147,12 +147,26 @@ def _init_stylesheet(profile): profile.scripts().insert(script) +def _set_user_agent(profile): + """Set the user agent for the given profile. + + We override this per request in the URL interceptor (to allow for per-domain + user agents), but this one still gets used for things like + window.navigator.userAgent in JS. + """ + user_agent = config.get('network', 'user-agent') + profile.setHttpUserAgent(user_agent) + + def update_settings(section, option): """Update global settings when qwebsettings changed.""" websettings.update_mappings(MAPPINGS, section, option) if section == 'ui' and option in ['hide-scrollbar', 'user-stylesheet']: _init_stylesheet(default_profile) _init_stylesheet(private_profile) + elif section == 'network' and option == 'user-agent': + _set_user_agent(default_profile) + _set_user_agent(private_profile) def _init_profiles(): @@ -164,10 +178,12 @@ def _init_profiles(): default_profile.setPersistentStoragePath( os.path.join(standarddir.data(), 'webengine')) _init_stylesheet(default_profile) + _set_user_agent(default_profile) private_profile = QWebEngineProfile() assert private_profile.isOffTheRecord() _init_stylesheet(private_profile) + _set_user_agent(private_profile) def init(args): diff --git a/tests/end2end/features/misc.feature b/tests/end2end/features/misc.feature index 21b220174..ac210e58c 100644 --- a/tests/end2end/features/misc.feature +++ b/tests/end2end/features/misc.feature @@ -471,12 +471,16 @@ Feature: Various utility commands. Scenario: Setting a custom user-agent header When I set network -> user-agent to toaster And I open headers + And I run :jseval console.log(window.navigator.userAgent) Then the header User-Agent should be set to toaster + And the javascript message "toaster" should be logged Scenario: Setting the default user-agent header When I set network -> user-agent to And I open headers + And I run :jseval console.log(window.navigator.userAgent) Then the header User-Agent should be set to Mozilla/5.0 * + And the javascript message "Mozilla/5.0 *" should be logged ## :messages