Skip to content

Commit 2ab6695

Browse files
Conditional frame matching
1 parent 489f654 commit 2ab6695

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

injected/src/config-feature.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ export default class ConfigFeature {
109109
* @property {object} [experiment]
110110
* @property {string} [experiment.experimentName]
111111
* @property {string} [experiment.cohort]
112+
* @property {object} [context]
113+
* @property {boolean} [context.frame] - true if the condition applies to frames
114+
* @property {boolean} [context.top] - true if the condition applies to the top frame
112115
*/
113116

114117
/**
@@ -134,6 +137,7 @@ export default class ConfigFeature {
134137
/** @type {Record<string, (conditionBlock: ConditionBlock) => boolean>} */
135138
const conditionChecks = {
136139
domain: this._matchDomainConditional,
140+
context: this._matchContextConditional,
137141
urlPattern: this._matchUrlPatternConditional,
138142
experiment: this._matchExperimentConditional,
139143
};
@@ -197,6 +201,23 @@ export default class ConfigFeature {
197201
});
198202
}
199203

204+
/**
205+
* Takes a condition block and returns true if the current context matches the context.
206+
* @param {ConditionBlock} conditionBlock
207+
* @returns {boolean}
208+
*/
209+
_matchContextConditional(conditionBlock) {
210+
if (!conditionBlock.context) return false;
211+
const isFrame = window.self !== window.top;
212+
if (conditionBlock.context.frame && isFrame) {
213+
return true;
214+
}
215+
if (conditionBlock.context.top && !isFrame) {
216+
return true;
217+
}
218+
return false;
219+
}
220+
200221
/**
201222
* Takes a condtion block and returns true if the current url matches the urlPattern.
202223
* @param {ConditionBlock} conditionBlock

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', 'webCompat'],
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', 'webCompat'],

injected/src/features/web-compat.js

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export class WebCompat extends ContentFeature {
126126
if (this.getFeatureSettingEnabled('modifyCookies')) {
127127
this.modifyCookies();
128128
}
129-
if (this.getFeatureSettingEnabled('disableDeviceEnumeration') || this.getFeatureSettingEnabled('disableDeviceEnumerationFrames')) {
129+
if (this.getFeatureSettingEnabled('disableDeviceEnumeration')) {
130130
this.preventDeviceEnumeration();
131131
}
132132
}
@@ -761,21 +761,12 @@ export class WebCompat extends ContentFeature {
761761
if (!window.MediaDevices) {
762762
return;
763763
}
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-
}
764+
const enumerateDevicesProxy = new DDGProxy(this, MediaDevices.prototype, 'enumerateDevices', {
765+
apply() {
766+
return Promise.resolve([]);
767+
},
768+
});
769+
enumerateDevicesProxy.overload();
779770
}
780771
}
781772

0 commit comments

Comments
 (0)