-
Notifications
You must be signed in to change notification settings - Fork 3
Add a script injector for debugging #3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
ff0e1cd
07b2fc8
9c66e82
6aee80a
0f95d2f
577a54c
1fcea55
cc77c06
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,16 @@ BUILD_DIR="${ROOT_DIR}/build" | |
|
|
||
| mkdir -p "${BUILD_DIR}" | ||
| pushd "${BUILD_DIR}" >/dev/null | ||
| qmake6 ../seb-linux-qt.pro | ||
| CONFIG="debug" | ||
| for arg in "$@"; do | ||
| if [ "$arg" == "-r" ] || [ "$arg" == "--release" ]; then | ||
| CONFIG="release" | ||
| break | ||
| fi | ||
| done | ||
|
|
||
| qmake6 CONFIG+="${CONFIG}" ../seb-linux-qt.pro | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: cat -n scripts/build.sh | head -40Repository: Jvr2022/seb-linux Length of output: 697 🏁 Script executed: # Search for any documentation or comments in the repo about build configuration
rg -i "config|debug|release" scripts/ -A 2 -B 2Repository: Jvr2022/seb-linux Length of output: 675 🌐 Web query:
💡 Result: qmake (including qmake6 in Qt6) does not have a specific CONFIG option to control object file reuse detection when changing CONFIG modes (like switching between debug/release) in the same build directory. qmake generates dependency information based on source files, headers (via DEPENDPATH), and Makefile regeneration triggers, but CONFIG changes primarily affect which Makefile is used (e.g., Makefile.Debug vs Makefile.Release when CONFIG += debug_and_release). Key behaviors: - When using CONFIG += debug_and_release (default on Windows, optional elsewhere), qmake generates separate Makefiles for each mode: Makefile, Makefile.Debug, Makefile.Release. Building 'debug' uses Makefile.Debug (which builds objects with debug flags), 'release' uses Makefile.Release (release flags). Objects are typically placed in mode-specific directories if configured via OBJECTS_DIR in CONFIG(debug,debug|release) scopes (e.g., OBJECTS_DIR = .obj/debug). Thus, objects are not shared/reused across modes due to different compiler flags and usually separate paths. - In the same build directory without debug_and_release, changing CONFIG (e.g., adding/removing 'debug') invalidates the Makefile, forcing qmake re-run and full rebuild (no incremental object reuse across config changes). - No evidence of qmake6-specific changes to this behavior; Qt6 docs confirm qmake remains supported for apps with same core logic. - To avoid rebuilds on CONFIG changes, use separate build directories per config (shadow builds, recommended). For object reuse across subprojects, object files are not automatically shared; each subdir rebuilds unless using static libs. - Use 'qmake -nodepend' to disable dependency generation (not recommended, breaks incremental builds). No official CONFIG like 'object_reuse_detection' exists. Best practice: separate OBJECTS_DIR per config, separate build dirs. Citations:
🏁 Script executed: find . -name "seb-linux-qt.pro" -o -name "*.pro" | head -5Repository: Jvr2022/seb-linux Length of output: 151 🏁 Script executed: cat -n seb-linux-qt.pro | head -50Repository: Jvr2022/seb-linux Length of output: 2506 🏁 Script executed: cat seb-linux-qt.pro | grep -i "debug_and_release\|CONFIG.*debug\|CONFIG.*release\|OBJECTS_DIR.*CONFIG"Repository: Jvr2022/seb-linux Length of output: 43 🏁 Script executed: wc -l seb-linux-qt.pro && tail -50 seb-linux-qt.proRepository: Jvr2022/seb-linux Length of output: 2692 🏁 Script executed: grep -n "CONFIG\|debug_and_release" seb-linux-qt.proRepository: Jvr2022/seb-linux Length of output: 120 🏁 Script executed: grep -n "include\|qt_module" seb-linux-qt.pro | head -20Repository: Jvr2022/seb-linux Length of output: 43 🏁 Script executed: # Check if there are any cache/state files generated by qmake that might track CONFIG
find . -name ".qmake*" -o -name "*.stash" -o -name "Makefile*" | grep -v ".git" | head -20Repository: Jvr2022/seb-linux Length of output: 43 🌐 Web query:
💡 Result: In Qt6, qmake does not automatically detect changes to the CONFIG variable (or other .pro file changes) in the same build directory during incremental builds with make/nmake. The generated Makefile lacks a dependency on the .pro file itself, so changes to CONFIG (e.g., adding debug, release, or custom features) do not trigger qmake regeneration or rebuilds of affected targets. To apply CONFIG changes: - Manually run qmake in the build directory to regenerate the Makefile. - In Qt Creator: Right-click project > Run qmake, or use Build > Run qmake, or delete Makefile(s) to force regeneration. - Use 'make clean' followed by 'make', but this performs a full rebuild. This behavior persists from Qt5 to Qt6 as qmake remains supported for applications. Official docs confirm qmake usage but note CMake preference for Qt6 builds. Qt Creator may not always auto-run qmake on .pro changes (known longstanding issue). Shadow builds (separate build dir) are recommended to avoid source pollution, but the issue remains for .pro changes. Citations:
🏁 Script executed: # Check what happens when qmake runs with CONFIG changes
# Show the build.sh logic again for clarity
cat -n scripts/build.shRepository: Jvr2022/seb-linux Length of output: 697 Use separate build directories or force clean rebuild when CONFIG changes. Line 17 reconfigures qmake6 in the same Solutions: (1) Use separate build directories per mode (e.g., 🤖 Prompt for AI Agents |
||
| make -j"$(nproc)" | ||
| popd >/dev/null | ||
|
|
||
| echo "Build output: ${BUILD_DIR}/bin/safe-exam-browser" | ||
| echo "Build output: ${BUILD_DIR}/bin/safe-exam-browser (mode: ${CONFIG})" | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -7,19 +7,78 @@ | |||||||||||||||
| #include <QApplication> | ||||||||||||||||
| #include <QAuthenticator> | ||||||||||||||||
| #include <QCryptographicHash> | ||||||||||||||||
| #include <QDebug> | ||||||||||||||||
| #include <QDir> | ||||||||||||||||
| #include <QEventLoop> | ||||||||||||||||
| #include <QFile> | ||||||||||||||||
| #include <QFileDialog> | ||||||||||||||||
| #include <QFileInfo> | ||||||||||||||||
| #include <QInputDialog> | ||||||||||||||||
| #include <QJsonDocument> | ||||||||||||||||
| #include <QJsonObject> | ||||||||||||||||
| #include <QLocale> | ||||||||||||||||
| #include <QMessageBox> | ||||||||||||||||
| #include <QNetworkAccessManager> | ||||||||||||||||
| #include <QNetworkReply> | ||||||||||||||||
| #include <QNetworkRequest> | ||||||||||||||||
| #include <QRegularExpression> | ||||||||||||||||
| #include <QStandardPaths> | ||||||||||||||||
| #include <QTemporaryDir> | ||||||||||||||||
| #include <QTextStream> | ||||||||||||||||
| #include <QUrl> | ||||||||||||||||
| #include <QWebEngineCookieStore> | ||||||||||||||||
| #include <QWebEngineDownloadRequest> | ||||||||||||||||
| #include <QWebEngineProfile> | ||||||||||||||||
| #include <QWebEngineScript> | ||||||||||||||||
| #include <QWebEngineScriptCollection> | ||||||||||||||||
| #include <QWebEngineSettings> | ||||||||||||||||
| #include <QTimer> | ||||||||||||||||
|
|
||||||||||||||||
| namespace { | ||||||||||||||||
|
|
||||||||||||||||
| QString getCachedSebVersion() | ||||||||||||||||
| { | ||||||||||||||||
| static QString cachedVersion; | ||||||||||||||||
| if (!cachedVersion.isEmpty()) { | ||||||||||||||||
| return cachedVersion; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| cachedVersion = QStringLiteral("3.10.1"); | ||||||||||||||||
|
|
||||||||||||||||
| QNetworkAccessManager manager; | ||||||||||||||||
| QNetworkRequest request(QUrl(QStringLiteral("https://api.github.com/repos/SafeExamBrowser/seb-win-refactoring/releases/latest"))); | ||||||||||||||||
| request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy); | ||||||||||||||||
| request.setHeader(QNetworkRequest::UserAgentHeader, QStringLiteral("SEB Linux Qt/") + QApplication::applicationVersion()); | ||||||||||||||||
|
|
||||||||||||||||
| QEventLoop loop; | ||||||||||||||||
| QNetworkReply *reply = manager.get(request); | ||||||||||||||||
| QObject::connect(reply, &QNetworkReply::finished, &loop, &QEventLoop::quit); | ||||||||||||||||
| QTimer::singleShot(5000, &loop, &QEventLoop::quit); | ||||||||||||||||
| loop.exec(); | ||||||||||||||||
|
|
||||||||||||||||
| if (!reply->isFinished()) { | ||||||||||||||||
| reply->abort(); | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| if (reply->error() == QNetworkReply::NoError) { | ||||||||||||||||
| const QByteArray responseData = reply->readAll(); | ||||||||||||||||
| QJsonDocument json = QJsonDocument::fromJson(responseData); | ||||||||||||||||
| if (json.isObject()) { | ||||||||||||||||
| QString tag = json.object().value(QStringLiteral("tag_name")).toString(); | ||||||||||||||||
| if (!tag.isEmpty()) { | ||||||||||||||||
| if (tag.startsWith(QLatin1Char('v'), Qt::CaseInsensitive)) { | ||||||||||||||||
| tag = tag.mid(1); | ||||||||||||||||
| } | ||||||||||||||||
| cachedVersion = tag; | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
| reply->deleteLater(); | ||||||||||||||||
|
|
||||||||||||||||
| return cachedVersion; | ||||||||||||||||
| } | ||||||||||||||||
|
incomplete-tree marked this conversation as resolved.
|
||||||||||||||||
|
|
||||||||||||||||
| } // namespace | ||||||||||||||||
|
|
||||||||||||||||
| SebSession::SebSession(const seb::SebSettings &settings, ResourceOpener opener, QObject *parent) | ||||||||||||||||
| : QObject(parent) | ||||||||||||||||
|
|
@@ -61,6 +120,24 @@ SebSession::SebSession(const seb::SebSettings &settings, ResourceOpener opener, | |||||||||||||||
| profile_->setSpellCheckLanguages(QStringList{QLocale::system().bcp47Name()}); | ||||||||||||||||
| profile_->setHttpUserAgent(buildUserAgent()); | ||||||||||||||||
|
|
||||||||||||||||
| #ifdef QT_DEBUG | ||||||||||||||||
| if (!settings_.browser.injectedScript.isEmpty()) { | ||||||||||||||||
| QFile scriptFile(settings_.browser.injectedScript); | ||||||||||||||||
| if (scriptFile.open(QIODevice::ReadOnly | QIODevice::Text)) { | ||||||||||||||||
| QWebEngineScript script; | ||||||||||||||||
| script.setName(QStringLiteral("InjectScript")); | ||||||||||||||||
| QTextStream in(&scriptFile); | ||||||||||||||||
| script.setSourceCode(in.readAll()); | ||||||||||||||||
| script.setInjectionPoint(QWebEngineScript::DocumentReady); | ||||||||||||||||
| script.setWorldId(QWebEngineScript::UserWorld); | ||||||||||||||||
| script.setRunsOnSubFrames(true); | ||||||||||||||||
| profile_->scripts()->insert(script); | ||||||||||||||||
| } else { | ||||||||||||||||
| qWarning() << "Failed to open injection script:" << scriptFile.fileName() << scriptFile.errorString(); | ||||||||||||||||
| } | ||||||||||||||||
| } | ||||||||||||||||
|
incomplete-tree marked this conversation as resolved.
|
||||||||||||||||
| #endif | ||||||||||||||||
|
|
||||||||||||||||
| interceptor_.reset(new seb::browser::RequestInterceptor(settings_, this)); | ||||||||||||||||
| profile_->setUrlRequestInterceptor(interceptor_.data()); | ||||||||||||||||
|
|
||||||||||||||||
|
|
@@ -361,11 +438,24 @@ void SebSession::handleDownloadRequested(QWebEngineDownloadRequest *download) | |||||||||||||||
|
|
||||||||||||||||
| QString SebSession::buildUserAgent() const | ||||||||||||||||
| { | ||||||||||||||||
| QString agent = profile_->httpUserAgent(); | ||||||||||||||||
| QString agent; | ||||||||||||||||
|
|
||||||||||||||||
| if (settings_.browser.useCustomUserAgent && !settings_.browser.customUserAgent.isEmpty()) { | ||||||||||||||||
| agent = settings_.browser.customUserAgent.trimmed(); | ||||||||||||||||
| } else { | ||||||||||||||||
|
Comment on lines
443
to
+445
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trim before deciding whether to honor Line 443 only checks 🛠️ Proposed fix- if (settings_.browser.useCustomUserAgent && !settings_.browser.customUserAgent.isEmpty()) {
- agent = settings_.browser.customUserAgent.trimmed();
+ const QString customAgent = settings_.browser.customUserAgent.trimmed();
+ if (settings_.browser.useCustomUserAgent && !customAgent.isEmpty()) {
+ agent = customAgent;
} else {📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||
| QString defaultAgent = profile_->httpUserAgent(); | ||||||||||||||||
| QRegularExpression regex(QStringLiteral("Chrome/([0-9.]+)")); | ||||||||||||||||
| QRegularExpressionMatch match = regex.match(defaultAgent); | ||||||||||||||||
| QString chromeVersion = match.hasMatch() ? match.captured(1) : QStringLiteral("110.0.0.0"); | ||||||||||||||||
|
|
||||||||||||||||
| agent = QStringLiteral("Mozilla/5.0 (Windows NT 10.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/") + chromeVersion; | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| const QString sebVersion = QStringLiteral("SEB/") + getCachedSebVersion(); | ||||||||||||||||
| if (!agent.endsWith(' ')) { | ||||||||||||||||
| agent += QLatin1Char(' '); | ||||||||||||||||
| } | ||||||||||||||||
| agent += sebVersion; | ||||||||||||||||
|
|
||||||||||||||||
| if (!settings_.browser.userAgentSuffix.trimmed().isEmpty()) { | ||||||||||||||||
| if (!agent.endsWith(' ')) { | ||||||||||||||||
|
|
||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.