Skip to content

Commit 1bfb6d1

Browse files
committed
fix(fxa-settings): Preserve URL hash in query-fix.js for iOS WKWebView
Because: - On iOS WKWebView, window.location.hash is empty when inline scripts run early in the page lifecycle - query-fix.js calls replaceState to re-encode query params (e.g. + to %2B) and was appending window.location.hash which was empty in WKWebView - This stripped the #channel_id and #channel_key fragment needed by the pairing supplicant flow, causing "Invalid pairing configuration" This commit: - Falls back to parsing the hash from window.location.href when window.location.hash is empty
1 parent 11a364e commit 1bfb6d1

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

packages/fxa-settings/public/query-fix.js

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* License, v. 2.0. If a copy of the MPL was not distributed with this
33
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
44

5-
/* This script re-encodes the current URLs query parameters to ensure that any special
5+
/* This script re-encodes the current URL's query parameters to ensure that any special
66
* characters (such as '+') are properly encoded. This re-encoding is necessary due to
77
* backwards compatibility requirements for clients (e.g., the VPN client) that send
88
* unencoded query components, which can cause issues with parameter validation in the app.
@@ -31,11 +31,15 @@
3131
})
3232
.join('&');
3333
if (newSearch !== search) {
34-
// IMPORTANT: preserve `window.location.hash`. The pairing supplicant
35-
// flow encodes `channel_id` and `channel_key` in the URL fragment
36-
// (e.g. `/pair/supp?client_id=...#channel_id=...&channel_key=...`),
37-
// and stripping the hash here would break the supplicant before the
38-
// React app has a chance to read it.
39-
window.history.replaceState({}, '', newSearch + window.location.hash);
34+
// IMPORTANT: preserve the URL hash fragment. The pairing supplicant
35+
// flow encodes channel_id and channel_key in the fragment. On iOS
36+
// WKWebView, window.location.hash may be empty when inline scripts
37+
// run early, so fall back to parsing the hash from the full href.
38+
const hash =
39+
window.location.hash ||
40+
(window.location.href.includes('#')
41+
? window.location.href.substring(window.location.href.indexOf('#'))
42+
: '');
43+
window.history.replaceState({}, '', newSearch + hash);
4044
}
4145
})();

0 commit comments

Comments
 (0)