According to the docs:
The User-Agent request header contains a characteristic string that
allows the network protocol peers to identify the application type,
operating system, software vendor or software version of the
requesting software user agent.
Some web pages will use the User Agent to display personalized content for your browser, for example, with the user-agent information you could deduce whether it supports AJAX or not.
If I was to change the User Agent, could I mimic Chromes functionality?
Probably yes, although although Google Chrome and Qt Webengine are based on chromium, each development group has created a new layer that can have different functionalities, for example, QtWebEngine has suppressed many chromium functionalities that are added in the new versions.
How would I go about changing the User Agent?
It is not necessary to create a new QWebEngineProfile since you can use the profile of the page:
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5.QtWidgets import QApplication
if __name__ == "__main__":
app = QApplication(sys.argv)
web = QWebEngineView()
print(web.page().profile().httpUserAgent())
web.page().profile().setHttpUserAgent(
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
)
web.load(QUrl("https://stackoverflow.com"))
web.show()
web.resize(640, 480)
sys.exit(app.exec_())
If you want to use the QWebEngineProfile then create a new QWebEnginePage:
import sys
from PyQt5.QtCore import QUrl
from PyQt5.QtWebEngineWidgets import QWebEnginePage, QWebEngineProfile, QWebEngineView
from PyQt5.QtWidgets import QApplication
if __name__ == "__main__":
app = QApplication(sys.argv)
web = QWebEngineView()
profile = QWebEngineProfile()
profile.setHttpUserAgent(
"Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.132 Safari/537.36"
)
page = QWebEnginePage(profile, web)
web.setPage(page)
web.load(QUrl("https://stackoverflow.com"))
web.show()
web.resize(640, 480)
sys.exit(app.exec_())