Change user agent string

This commit is contained in:
Gres 2020-04-02 19:23:16 +03:00
parent a85dafa18d
commit 040d0ff540
2 changed files with 14 additions and 0 deletions

View File

@ -19,6 +19,8 @@ WebPage::WebPage(Translator &translator, const QString &script,
{ {
profile()->setParent(this); profile()->setParent(this);
changeUserAgent();
connect(this, &WebPage::proxyAuthenticationRequired, this, connect(this, &WebPage::proxyAuthenticationRequired, this,
&WebPage::authenticateProxy); &WebPage::authenticateProxy);
@ -84,6 +86,17 @@ void WebPage::addErrorToTask(const QString &text) const
task_->translatorErrors.append(QString("%1: %2").arg(scriptName_, text)); task_->translatorErrors.append(QString("%1: %2").arg(scriptName_, text));
} }
void WebPage::changeUserAgent()
{
auto userAgent = profile()->httpUserAgent().split(' ');
userAgent.erase(std::remove_if(userAgent.begin(), userAgent.end(),
[](const QString &part) {
return part.startsWith("QtWebEngine");
}),
userAgent.end());
profile()->setHttpUserAgent(userAgent.join(' '));
}
void WebPage::setIgnoreSslErrors(bool ignoreSslErrors) void WebPage::setIgnoreSslErrors(bool ignoreSslErrors)
{ {
ignoreSslErrors_ = ignoreSslErrors; ignoreSslErrors_ = ignoreSslErrors;

View File

@ -42,6 +42,7 @@ private:
void scheduleWebchannelInitScript(); void scheduleWebchannelInitScript();
void scheduleTranslatorScript(const QString &script); void scheduleTranslatorScript(const QString &script);
void addErrorToTask(const QString &text) const; void addErrorToTask(const QString &text) const;
void changeUserAgent();
Translator &translator_; Translator &translator_;
QString scriptName_; QString scriptName_;