-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathweb-interference-detection.js
More file actions
50 lines (44 loc) · 2.04 KB
/
web-interference-detection.js
File metadata and controls
50 lines (44 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import ContentFeature from '../content-feature.js';
import { runBotDetection } from '../detectors/detections/bot-detection.js';
import { runFraudDetection } from '../detectors/detections/fraud-detection.js';
import { runAdwallDetection } from '../detectors/detections/adwall-detection.js';
import { runYoutubeAdDetection } from '../detectors/detections/youtube-ad-detection.js';
/**
* @typedef {object} DetectInterferenceParams
* @property {string[]} [types]
*/
/**
* Note: breakageReporting also runs these detectors directly by reading this
* feature's `interferenceTypes` settings via getFeatureSetting. Those calls
* execute in breakageReporting's world (apple-isolated), independent of which
* world this feature is bundled into.
*/
export default class WebInterferenceDetection extends ContentFeature {
init() {
// Get settings with conditionalChanges already applied by framework
const settings = this.getFeatureSetting('interferenceTypes');
const fireEvent = async (type) => {
try {
await this.callFeatureMethod('webEvents', 'fireEvent', { type });
} catch {
// webEvents may not be loaded on this platform — silently ignore
}
};
runYoutubeAdDetection(settings?.youtubeAds, this.log, fireEvent);
// Register messaging handler for PIR/native requests
this.messaging.subscribe('detectInterference', (params) => {
const { types = [] } = /** @type {DetectInterferenceParams} */ (params ?? {});
const results = {};
if (types.includes('botDetection')) {
results.botDetection = runBotDetection(settings?.botDetection);
}
if (types.includes('fraudDetection')) {
results.fraudDetection = runFraudDetection(settings?.fraudDetection);
}
if (types.includes('adwallDetection')) {
results.adwallDetection = runAdwallDetection(settings?.adwallDetection);
}
return results;
});
}
}