Details
Description
QWebEngineScript::setSourceUrl doesn't load scripts from qrc, i.e it can't be used such way:
QWebEngineScript script;
script.setSourceUrl(QUrl("qrc:///qtwebchannel/qwebchannel.js"));
...
or in QML:
let script = WebEngine.script()
script.sourceUrl = "qrc:///qtwebchannel/qwebchannel.js"
...
There is wrong code introduced by https://codereview.qt-project.org/c/qt/qtwebengine/+/311566
void QWebEngineScript::setSourceUrl(const QUrl &url) { if (url == sourceUrl()) return; d->setSourceUrl(url); QFile file; if (url.scheme().compare(QLatin1String("qrc"), Qt::CaseInsensitive) == 0) { if (url.authority().isEmpty()) // <---- wrong? file.setFileName(QLatin1Char(':') + url.path()); return; // <---- wrong! } else { file.setFileName(url.toLocalFile()); } if (!file.open(QIODevice::ReadOnly)) { qWarning() << "Can't open user script " << url; return; } QString source = QString::fromUtf8(file.readAll()); setSourceCode(source); }