Skip to content

Commit aa3013c

Browse files
committed
qt: fix cam access by restoring window.isSecureContext
In d78380f, we switched from qrc:/ to the bitboxapp:/ custom scheme so we can force mimetypes in the scheme handler. This somehow made window.isSecureContext be false, breaking camera (which requires a secure context). The issue was that our scheme handler was never registered, because it was configued with HostAndPort but no default port was specified. We could specify one, or switch to Host only, but in our case Path seems to be most appropriate. The frontend navigation is changed from browser router to hash based router, as somehow navigation breaks in the custom scheme, as the frontend tries to actually request the individual pages from QtWebEngine. Not sure why it was working before or what causes it, but a local hash based router seems to work.
1 parent ab325eb commit aa3013c

File tree

3 files changed

+10
-13
lines changed

3 files changed

+10
-13
lines changed

frontends/qt/main.cpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,8 @@ class RequestInterceptor : public QWebEngineUrlRequestInterceptor {
184184
// We treat the exchange pages specially because we need to allow exchange
185185
// widgets to load in an iframe as well as let them open external links
186186
// in a browser.
187-
bool onExchangePage = currentUrl.contains(QRegularExpression(QString("^%1:/exchange/.*$").arg(scheme)));
188-
bool onBitsurancePage = currentUrl.contains(QRegularExpression(QString("^%1:/bitsurance/.*$").arg(scheme)));
187+
bool onExchangePage = currentUrl.contains(QRegularExpression(QString("^%1:/index\.html\#/exchange/.*$").arg(scheme)));
188+
bool onBitsurancePage = currentUrl.contains(QRegularExpression(QString("^%1:/index\.html\#/bitsurance/.*$").arg(scheme)));
189189
if (onExchangePage || onBitsurancePage) {
190190
if (info.firstPartyUrl().toString() == info.requestUrl().toString()) {
191191
// Ignore requests for certain file types (e.g., .js, .css) Somehow Moonpay loads
@@ -208,7 +208,7 @@ class RequestInterceptor : public QWebEngineUrlRequestInterceptor {
208208

209209
// All the requests originated in the wallet-connect section are allowed, as they are needed to
210210
// load the Dapp logos and it is not easy to filter out non-images requests.
211-
bool onWCPage = currentUrl.contains(QRegularExpression(QString(R"(^%1:/account/[^\/]+/wallet-connect/.*$)").arg(scheme)));
211+
bool onWCPage = currentUrl.contains(QRegularExpression(QString(R"(^%1:/index\.html\#/account/[^\/]+/wallet-connect/.*$)").arg(scheme)));
212212
if (onWCPage) {
213213
return;
214214
}
@@ -339,11 +339,8 @@ int main(int argc, char *argv[])
339339
}
340340

341341
QWebEngineUrlScheme bbappScheme(scheme);
342-
bbappScheme.setSyntax(QWebEngineUrlScheme::Syntax::HostAndPort);
343-
bbappScheme.setFlags(
344-
QWebEngineUrlScheme::LocalScheme |
345-
QWebEngineUrlScheme::SecureScheme |
346-
QWebEngineUrlScheme::LocalAccessAllowed);
342+
bbappScheme.setSyntax(QWebEngineUrlScheme::Syntax::Path);
343+
bbappScheme.setFlags(QWebEngineUrlScheme::SecureScheme);
347344
QWebEngineUrlScheme::registerScheme(bbappScheme);
348345

349346
view = new WebEngineView();

frontends/web/src/app.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ export const App = () => {
6363
}, [t]);
6464

6565
const maybeRoute = useCallback(() => {
66-
const currentURL = window.location.pathname;
67-
const isIndex = currentURL === '/' || currentURL === '/index.html' || currentURL === '/android_asset/web/index.html' || currentURL.endsWith('/assets/web/index.html');
66+
const currentURL = window.location.hash.replace(/^#/, '');
67+
const isIndex = currentURL === '' || currentURL === '/';
6868
const inAccounts = currentURL.startsWith('/account/');
6969

7070
// QT and Android start their apps in '/index.html' and '/android_asset/web/index.html' respectively

frontends/web/src/index.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
import React from 'react';
1919
import { createRoot } from 'react-dom/client';
2020
import { I18nextProvider } from 'react-i18next';
21-
import { BrowserRouter } from 'react-router-dom';
21+
import { HashRouter } from 'react-router-dom';
2222
import { App } from './app';
2323
import { i18n } from './i18n/i18n';
2424
import './style/index.css';
@@ -30,9 +30,9 @@ root.render(
3030
<React.StrictMode>
3131
<I18nextProvider i18n={i18n}>
3232
<React.Suspense fallback={null}>
33-
<BrowserRouter>
33+
<HashRouter>
3434
<App />
35-
</BrowserRouter>
35+
</HashRouter>
3636
</React.Suspense>
3737
</I18nextProvider>
3838
</React.StrictMode>

0 commit comments

Comments
 (0)