Skip to content

Commit e43c38a

Browse files
Device enumeration blocking WebCompat feature (#1724)
* Add enum devices debugging * Disable device enumeration remotely * Fix lint * Add frame flexibility * Move to webCompat * Remove webCompat from extension build
1 parent bd88071 commit e43c38a

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

injected/src/features.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,16 @@ export const platformSupport = {
4646
android: [...baseFeatures, 'webCompat', 'breakageReporting', 'duckPlayer', 'messageBridge'],
4747
'android-broker-protection': ['brokerProtection'],
4848
'android-autofill-password-import': ['autofillPasswordImport'],
49-
windows: ['cookie', ...baseFeatures, 'windowsPermissionUsage', 'duckPlayer', 'brokerProtection', 'breakageReporting', 'messageBridge'],
49+
windows: [
50+
'cookie',
51+
...baseFeatures,
52+
'windowsPermissionUsage',
53+
'duckPlayer',
54+
'brokerProtection',
55+
'breakageReporting',
56+
'messageBridge',
57+
'webCompat',
58+
],
5059
firefox: ['cookie', ...baseFeatures, 'clickToLoad'],
5160
chrome: ['cookie', ...baseFeatures, 'clickToLoad'],
5261
'chrome-mv3': ['cookie', ...baseFeatures, 'clickToLoad'],

injected/src/features/web-compat.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import ContentFeature from '../content-feature.js';
22
// eslint-disable-next-line no-redeclare
33
import { URL } from '../captured-globals.js';
4-
4+
import { DDGProxy } from '../utils';
55
/**
66
* Fixes incorrect sizing value for outerHeight and outerWidth
77
*/
@@ -126,6 +126,9 @@ export class WebCompat extends ContentFeature {
126126
if (this.getFeatureSettingEnabled('modifyCookies')) {
127127
this.modifyCookies();
128128
}
129+
if (this.getFeatureSettingEnabled('disableDeviceEnumeration') || this.getFeatureSettingEnabled('disableDeviceEnumerationFrames')) {
130+
this.preventDeviceEnumeration();
131+
}
129132
}
130133

131134
/** Shim Web Share API in Android WebView */
@@ -753,6 +756,27 @@ export class WebCompat extends ContentFeature {
753756
this.forceViewportTag(viewportTag, newContent.join(', '));
754757
}
755758
}
759+
760+
preventDeviceEnumeration() {
761+
if (!window.MediaDevices) {
762+
return;
763+
}
764+
let disableDeviceEnumeration = false;
765+
const isFrame = window.self !== window.top;
766+
if (isFrame) {
767+
disableDeviceEnumeration = this.getFeatureSettingEnabled('disableDeviceEnumerationFrames');
768+
} else {
769+
disableDeviceEnumeration = this.getFeatureSettingEnabled('disableDeviceEnumeration');
770+
}
771+
if (disableDeviceEnumeration) {
772+
const enumerateDevicesProxy = new DDGProxy(this, MediaDevices.prototype, 'enumerateDevices', {
773+
apply() {
774+
return Promise.resolve([]);
775+
},
776+
});
777+
enumerateDevicesProxy.overload();
778+
}
779+
}
756780
}
757781

758782
/** @typedef {{title?: string, url?: string, text?: string}} ShareRequestData */

0 commit comments

Comments
 (0)