mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-08 08:39:59 +00:00
Refine page media type availability
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user