From aa10be339ba2dd6a3aec30495ebd68ebcc09b541 Mon Sep 17 00:00:00 2001 From: hensm Date: Mon, 30 Sep 2019 11:16:57 +0100 Subject: [PATCH] Refine page media type availability --- ext/src/lib/utils.ts | 51 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/ext/src/lib/utils.ts b/ext/src/lib/utils.ts index 810584d..10d0a54 100644 --- a/ext/src/lib/utils.ts +++ b/ext/src/lib/utils.ts @@ -35,20 +35,49 @@ export function stringify ( export function getMediaTypesForPageUrl ( pageUrl: string): ReceiverSelectorMediaType { - let availableMediaTypes = - ReceiverSelectorMediaType.App - | ReceiverSelectorMediaType.Tab - | ReceiverSelectorMediaType.Screen - | ReceiverSelectorMediaType.File; + const url = new URL(pageUrl); + let availableMediaTypes = ReceiverSelectorMediaType.File; /** - * Remove "Screen" option when on an insecure origin as - * MediaDevices.getDisplayMedia will not exist (and legacy - * MediaDevices.getUserMedia mediaSource constraint will - * fail). + * Content scripts are prohibited from running on some + * Mozilla domains. */ - if (!pageUrl.startsWith("https://")) { - availableMediaTypes &= ~ReceiverSelectorMediaType.Screen; + const blockedHosts = [ + "accounts-static.cdn.mozilla.net" + , "accounts.firefox.com" + , "addons.cdn.mozilla.net" + , "addons.mozilla.org" + , "api.accounts.firefox.com" + , "content.cdn.mozilla.net" + , "content.cdn.mozilla.net" + , "discovery.addons.mozilla.org" + , "input.mozilla.org" + , "install.mozilla.org" + , "oauth.accounts.firefox.com" + , "profile.accounts.firefox.com" + , "support.mozilla.org" + , "sync.services.mozilla.com" + , "testpilot.firefox.com" + ]; + + if (blockedHosts.includes(url.host)) { + return availableMediaTypes; + } + + // Only meant to run on normal web pages + if (url.protocol === "http:" || url.protocol === "https:") { + availableMediaTypes |= ( + ReceiverSelectorMediaType.App + | ReceiverSelectorMediaType.Tab); + } + + /** + * When on an insecure origin, MediaDevices.getDisplayMedia + * will not exist (and legacy MediaDevices.getUserMedia + * mediaSource constraint will fail). + */ + if (url.protocol === "https:") { + availableMediaTypes |= ReceiverSelectorMediaType.Screen; } return availableMediaTypes;