mirror of
https://github.com/hensm/fx_cast.git
synced 2026-06-11 10:09:59 +00:00
Refine page media type availability
This commit is contained in:
@@ -35,20 +35,49 @@ export function stringify (
|
|||||||
export function getMediaTypesForPageUrl (
|
export function getMediaTypesForPageUrl (
|
||||||
pageUrl: string): ReceiverSelectorMediaType {
|
pageUrl: string): ReceiverSelectorMediaType {
|
||||||
|
|
||||||
let availableMediaTypes =
|
const url = new URL(pageUrl);
|
||||||
ReceiverSelectorMediaType.App
|
let availableMediaTypes = ReceiverSelectorMediaType.File;
|
||||||
| ReceiverSelectorMediaType.Tab
|
|
||||||
| ReceiverSelectorMediaType.Screen
|
|
||||||
| ReceiverSelectorMediaType.File;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove "Screen" option when on an insecure origin as
|
* Content scripts are prohibited from running on some
|
||||||
* MediaDevices.getDisplayMedia will not exist (and legacy
|
* Mozilla domains.
|
||||||
* MediaDevices.getUserMedia mediaSource constraint will
|
|
||||||
* fail).
|
|
||||||
*/
|
*/
|
||||||
if (!pageUrl.startsWith("https://")) {
|
const blockedHosts = [
|
||||||
availableMediaTypes &= ~ReceiverSelectorMediaType.Screen;
|
"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;
|
return availableMediaTypes;
|
||||||
|
|||||||
Reference in New Issue
Block a user