-
Notifications
You must be signed in to change notification settings - Fork 32
Expand file tree
/
Copy pathdebug-on-property-read.js
More file actions
83 lines (76 loc) · 1.94 KB
/
debug-on-property-read.js
File metadata and controls
83 lines (76 loc) · 1.94 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import {
randomId,
setPropertyAccess,
getPropertyInChain,
createOnErrorHandler,
hit,
noopFunc,
isEmptyObject,
interceptChainProp,
} from '../helpers';
/* eslint-disable max-len */
/**
* @scriptlet debug-on-property-read
*
* @description
* This scriptlet is basically the same as [abort-on-property-read](#abort-on-property-read),
* but instead of aborting it starts the debugger.
*
* > It is not allowed for prod versions of filter lists.
*
* ### Examples
*
* 1. Debug script if it tries to access `window.alert`
*
* ```adblock
* example.org#%#//scriptlet('debug-on-property-read', 'alert')
* ```
*
* 1. Debug script if it tries to access `window.open`
*
* ```adblock
* example.org#%#//scriptlet('debug-on-property-read', 'open')
* ```
*
* @added v1.0.4.
*/
/* eslint-enable max-len */
export function debugOnPropertyRead(source, property) {
if (!property) {
return;
}
const rid = randomId();
const abort = () => {
hit(source);
debugger; // eslint-disable-line no-debugger
};
const setChainPropAccess = (owner, property) => {
const chainInfo = getPropertyInChain(owner, property);
const { base, prop, chain } = chainInfo;
if (chain) {
interceptChainProp(owner, prop, chain, setChainPropAccess);
return;
}
setPropertyAccess(base, prop, {
get: abort,
set: noopFunc,
});
};
setChainPropAccess(window, property);
window.onerror = createOnErrorHandler(rid).bind();
}
export const debugOnPropertyReadNames = [
'debug-on-property-read',
];
// eslint-disable-next-line prefer-destructuring
debugOnPropertyRead.primaryName = debugOnPropertyReadNames[0];
debugOnPropertyRead.injections = [
randomId,
setPropertyAccess,
getPropertyInChain,
createOnErrorHandler,
hit,
noopFunc,
isEmptyObject,
interceptChainProp,
];