My project requires the the Fetch API which is not supported in PyQt5. I have largely upgraded to PyQt6 and most of the things I needed to change worked right away. The only issue I have is setting the Flags CorsEnabled
and FetchApiAllowed
which was implied by this answer. The code is in C++ and does not directly help me any further.
The PyQt5 way to do it was as shown below (Fetch API is not supported):
scheme = QWebEngineUrlScheme(b"qt")
scheme.setFlags(QWebEngineUrlRequestJob.CorsEnabled)
QWebEngineUrlScheme.registerScheme(scheme)
But when I try it in PyQt6 I get this error: AttributeError: type object 'QWebEngineUrlScheme' has no attribute 'CorsEnabled'
, apparently it does not work any more. At first I thought they must habe moved it but here they clearly state that this feature had been removed by default:¨
QRC Scheme
Can no longer be accessed from custom schemes by default, nor can it access local content directly. If the Qt 5 behavior is needed, it can be restored by registering the qrc scheme like a custom URL scheme, and setting the CorsEnabled and LocalAccessAllowed access flags.
QWebEngineUrlScheme qrcScheme(QByteArrayLiteral("qrc")); qrcScheme.setFlags(QWebEngineUrlScheme::SecureScheme | QWebEngineUrlScheme::LocalAccessAllowed | QWebEngineUrlScheme::CorsEnabled | QWebEngineUrlScheme::ViewSourceAllowed); QWebEngineUrlScheme::registerScheme(qrcScheme);
Now the only thing I get from this is that the feature I’m looking for is no longer as easy to access as before. Other than that they only include C++ code and some description on what to do. Sadly I do not understand any of it.
How can I add CorsEnabled and FetchApiAllowed into my PyQt6 project as described above?