-
Notifications
You must be signed in to change notification settings - Fork 30
/
no-topics.js
45 lines (39 loc) · 1.11 KB
/
no-topics.js
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
import { hit, noopPromiseResolve } from '../helpers';
/**
* @scriptlet no-topics
*
* @description
* Prevents using the Topics API.
* https://developer.chrome.com/docs/privacy-sandbox/topics/
*
* ### Syntax
*
* ```adblock
* example.org#%#//scriptlet('no-topics')
* ```
*
* @added v1.6.18.
*/
export function noTopics(source) {
const TOPICS_PROPERTY_NAME = 'browsingTopics';
if (Document instanceof Object === false) {
return;
}
if (!Object.prototype.hasOwnProperty.call(Document.prototype, TOPICS_PROPERTY_NAME)
|| Document.prototype[TOPICS_PROPERTY_NAME] instanceof Function === false) {
return;
}
// document.browsingTopics() is async function so it's better to return noopPromiseResolve()
// https://github.com/patcg-individual-drafts/topics#the-api-and-how-it-works
Document.prototype[TOPICS_PROPERTY_NAME] = () => noopPromiseResolve('[]');
hit(source);
}
export const noTopicsNames = [
'no-topics',
];
// eslint-disable-next-line prefer-destructuring
noTopics.primaryName = noTopicsNames[0];
noTopics.injections = [
hit,
noopPromiseResolve,
];