Set user agent correctly on QtWebEngine
This commit is contained in:
parent
086139110d
commit
d0dd1644af
@ -79,6 +79,8 @@ Fixed
|
|||||||
- The validation for colors in stylesheets is now less strict,
|
- The validation for colors in stylesheets is now less strict,
|
||||||
allowing for all valid Qt values.
|
allowing for all valid Qt values.
|
||||||
- data: URLs now aren't added to the history anymore.
|
- 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
|
v0.10.1
|
||||||
-------
|
-------
|
||||||
|
@ -147,12 +147,26 @@ def _init_stylesheet(profile):
|
|||||||
profile.scripts().insert(script)
|
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):
|
def update_settings(section, option):
|
||||||
"""Update global settings when qwebsettings changed."""
|
"""Update global settings when qwebsettings changed."""
|
||||||
websettings.update_mappings(MAPPINGS, section, option)
|
websettings.update_mappings(MAPPINGS, section, option)
|
||||||
if section == 'ui' and option in ['hide-scrollbar', 'user-stylesheet']:
|
if section == 'ui' and option in ['hide-scrollbar', 'user-stylesheet']:
|
||||||
_init_stylesheet(default_profile)
|
_init_stylesheet(default_profile)
|
||||||
_init_stylesheet(private_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():
|
def _init_profiles():
|
||||||
@ -164,10 +178,12 @@ def _init_profiles():
|
|||||||
default_profile.setPersistentStoragePath(
|
default_profile.setPersistentStoragePath(
|
||||||
os.path.join(standarddir.data(), 'webengine'))
|
os.path.join(standarddir.data(), 'webengine'))
|
||||||
_init_stylesheet(default_profile)
|
_init_stylesheet(default_profile)
|
||||||
|
_set_user_agent(default_profile)
|
||||||
|
|
||||||
private_profile = QWebEngineProfile()
|
private_profile = QWebEngineProfile()
|
||||||
assert private_profile.isOffTheRecord()
|
assert private_profile.isOffTheRecord()
|
||||||
_init_stylesheet(private_profile)
|
_init_stylesheet(private_profile)
|
||||||
|
_set_user_agent(private_profile)
|
||||||
|
|
||||||
|
|
||||||
def init(args):
|
def init(args):
|
||||||
|
@ -471,12 +471,16 @@ Feature: Various utility commands.
|
|||||||
Scenario: Setting a custom user-agent header
|
Scenario: Setting a custom user-agent header
|
||||||
When I set network -> user-agent to toaster
|
When I set network -> user-agent to toaster
|
||||||
And I open headers
|
And I open headers
|
||||||
|
And I run :jseval console.log(window.navigator.userAgent)
|
||||||
Then the header User-Agent should be set to toaster
|
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
|
Scenario: Setting the default user-agent header
|
||||||
When I set network -> user-agent to <empty>
|
When I set network -> user-agent to <empty>
|
||||||
And I open headers
|
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 *
|
Then the header User-Agent should be set to Mozilla/5.0 *
|
||||||
|
And the javascript message "Mozilla/5.0 *" should be logged
|
||||||
|
|
||||||
## :messages
|
## :messages
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user