-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathno-protected-audience.ts
73 lines (64 loc) · 2 KB
/
no-protected-audience.ts
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import {
hit,
noopStr,
noopFunc,
noopResolveVoid,
noopResolveNull,
} from '../helpers';
import { type Source } from './scriptlets';
/**
* @scriptlet no-protected-audience
*
* @description
* Prevents using the Protected Audience API.
* https://wicg.github.io/turtledove/
*
* ### Syntax
*
* ```adblock
* example.org#%#//scriptlet('no-protected-audience')
* ```
*
* @added v1.10.25.
*/
export function noProtectedAudience(source: Source) {
// Prevent XMLDocuments from being tampered with generic scriptlet rule
if (Document instanceof Object === false) {
return;
}
// This is not a complete list of methods, but rather a minimal set to suppress the API
const protectedAudienceMethods = {
joinAdInterestGroup: noopResolveVoid,
runAdAuction: noopResolveNull,
leaveAdInterestGroup: noopResolveVoid,
clearOriginJoinedAdInterestGroups: noopResolveVoid,
createAuctionNonce: noopStr,
updateAdInterestGroups: noopFunc,
};
for (const key of Object.keys(protectedAudienceMethods)) {
/**
* TODO Remove type castings when Protected Audience API types become available on DOM definitions.
* https://github.com/WICG/turtledove/issues/759
*/
const methodName = key as keyof typeof protectedAudienceMethods;
const prototype = Navigator.prototype as unknown as Record<keyof typeof protectedAudienceMethods, Function>;
if (!Object.prototype.hasOwnProperty.call(prototype, methodName)
|| prototype[methodName] instanceof Function === false) {
continue;
}
prototype[methodName] = protectedAudienceMethods[methodName];
}
hit(source);
}
export const noProtectedAudienceNames = [
'no-protected-audience',
];
// eslint-disable-next-line prefer-destructuring
noProtectedAudience.primaryName = noProtectedAudienceNames[0];
noProtectedAudience.injections = [
hit,
noopStr,
noopFunc,
noopResolveVoid,
noopResolveNull,
];