|
2 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | 4 |
|
5 | | -/* This script re-encodes the current URL’s query parameters to ensure that any special |
| 5 | +/* This script re-encodes the current URL's query parameters to ensure that any special |
6 | 6 | * characters (such as '+') are properly encoded. This re-encoding is necessary due to |
7 | 7 | * backwards compatibility requirements for clients (e.g., the VPN client) that send |
8 | 8 | * unencoded query components, which can cause issues with parameter validation in the app. |
|
31 | 31 | }) |
32 | 32 | .join('&'); |
33 | 33 | 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); |
40 | 44 | } |
41 | 45 | })(); |
0 commit comments