Set window.navigator.languages correctly
This commit is contained in:
parent
ba8083c539
commit
cbf9da0b7e
@ -156,14 +156,17 @@ def _init_stylesheet(profile):
|
|||||||
profile.scripts().insert(script)
|
profile.scripts().insert(script)
|
||||||
|
|
||||||
|
|
||||||
def _set_user_agent(profile):
|
def _set_http_headers(profile):
|
||||||
"""Set the user agent for the given profile.
|
"""Set the user agent and accept-language for the given profile.
|
||||||
|
|
||||||
We override this per request in the URL interceptor (to allow for
|
We override those per request in the URL interceptor (to allow for
|
||||||
per-domain user agents), but this one still gets used for things like
|
per-domain values), but this one still gets used for things like
|
||||||
window.navigator.userAgent in JS.
|
window.navigator.userAgent/.languages in JS.
|
||||||
"""
|
"""
|
||||||
profile.setHttpUserAgent(config.val.content.headers.user_agent)
|
profile.setHttpUserAgent(config.val.content.headers.user_agent)
|
||||||
|
accept_language = config.val.content.headers.accept_language
|
||||||
|
if accept_language is not None:
|
||||||
|
profile.setHttpAcceptLanguage(accept_language)
|
||||||
|
|
||||||
|
|
||||||
def _update_settings(option):
|
def _update_settings(option):
|
||||||
@ -172,9 +175,10 @@ def _update_settings(option):
|
|||||||
if option in ['scrollbar.hide', 'content.user_stylesheets']:
|
if option in ['scrollbar.hide', 'content.user_stylesheets']:
|
||||||
_init_stylesheet(default_profile)
|
_init_stylesheet(default_profile)
|
||||||
_init_stylesheet(private_profile)
|
_init_stylesheet(private_profile)
|
||||||
elif option == 'content.headers.user_agent':
|
elif option in ['content.headers.user_agent',
|
||||||
_set_user_agent(default_profile)
|
'content.headers.accept_language']:
|
||||||
_set_user_agent(private_profile)
|
_set_http_headers(default_profile)
|
||||||
|
_set_http_headers(private_profile)
|
||||||
|
|
||||||
|
|
||||||
def _init_profiles():
|
def _init_profiles():
|
||||||
@ -186,12 +190,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)
|
_set_http_headers(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)
|
_set_http_headers(private_profile)
|
||||||
|
|
||||||
|
|
||||||
def init(args):
|
def init(args):
|
||||||
|
@ -346,6 +346,14 @@ Feature: Various utility commands.
|
|||||||
And I open headers
|
And I open headers
|
||||||
Then the header Accept-Language should be set to en,de
|
Then the header Accept-Language should be set to en,de
|
||||||
|
|
||||||
|
# This still doesn't set window.navigator.language
|
||||||
|
# See https://bugreports.qt.io/browse/QTBUG-61949
|
||||||
|
@qtwebkit_skip
|
||||||
|
Scenario: Accept-Language header (JS)
|
||||||
|
When I set content.headers.accept_language to it,fr
|
||||||
|
And I run :jseval console.log(window.navigator.languages)
|
||||||
|
Then the javascript message "it,fr" should be logged
|
||||||
|
|
||||||
Scenario: Setting a custom user-agent header
|
Scenario: Setting a custom user-agent header
|
||||||
When I set content.headers.user_agent to toaster
|
When I set content.headers.user_agent to toaster
|
||||||
And I open headers
|
And I open headers
|
||||||
|
Loading…
Reference in New Issue
Block a user