From 813dbfee5b3d11db49a134a130110b6d787ce536 Mon Sep 17 00:00:00 2001 From: Jordi Bunster Date: Tue, 30 Mar 2021 14:01:30 -0700 Subject: [PATCH] Defensively set feature flags from window.parent (#594) This doesn't really fix the fact that portal feature flags are not being set, but it does re-enable feature flags in hosted mode. --- src/Platform/Hosted/extractFeatures.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/Platform/Hosted/extractFeatures.ts b/src/Platform/Hosted/extractFeatures.ts index 4636c947e..eda8458ff 100644 --- a/src/Platform/Hosted/extractFeatures.ts +++ b/src/Platform/Hosted/extractFeatures.ts @@ -23,11 +23,18 @@ export type Features = { readonly ttl90Days: boolean; }; -export function extractFeatures(params?: URLSearchParams): Features { - params = params || new URLSearchParams(window.location.search); +export function extractFeatures(given = new URLSearchParams()): Features { const downcased = new URLSearchParams(); - params.forEach((value, key) => downcased.append(key.toLocaleLowerCase(), value)); - const get = (key: string) => downcased.get("feature." + key.toLocaleLowerCase()) ?? undefined; + const set = (value: string, key: string) => downcased.set(key.toLowerCase(), value); + const get = (key: string) => downcased.get("feature." + key) ?? undefined; + + try { + new URLSearchParams(window.parent.location.search).forEach(set); + } catch { + // + } finally { + given.forEach(set); + } return { canExceedMaximumValue: "true" === get("canexceedmaximumvalue"),