@@ -2952,13 +2952,45 @@ function preventXhr(...args) {
2952
2952
return preventXhrFn ( false , ...args ) ;
2953
2953
}
2954
2954
2955
- /******************************************************************************/
2955
+ /**
2956
+ * @scriptlet prevent-window-open
2957
+ *
2958
+ * @description
2959
+ * Prevent a webpage from opening new tabs through `window.open()`.
2960
+ *
2961
+ * @param pattern
2962
+ * A plain string or regex to match against the `url` argument for the
2963
+ * prevention to be triggered. If not provided, all calls to `window.open()`
2964
+ * are prevented.
2965
+ * If set to the special value `debug` *and* the logger is opened, the scriptlet
2966
+ * will trigger a `debugger` statement and the prevention will not occur.
2967
+ *
2968
+ * @param [delay]
2969
+ * If provided, a decoy will be created or opened, and this parameter states
2970
+ * the number of seconds to wait for before the decoy is terminated, i.e.
2971
+ * either removed from the DOM or closed.
2972
+ *
2973
+ * @param [decoy]
2974
+ * A string representing the type of decoy to use:
2975
+ * - `blank`: replace the `url` parameter with `about:blank`
2976
+ * - `object`: create and append an `object` element to the DOM, and return
2977
+ * its `contentWindow` property.
2978
+ * - `frame`: create and append an `iframe` element to the DOM, and return
2979
+ * its `contentWindow` property.
2980
+ *
2981
+ * @example
2982
+ * ##+js(prevent-window-open, ads.example.com/)
2983
+ *
2984
+ * @example
2985
+ * ##+js(prevent-window-open, ads.example.com/, 1, iframe)
2986
+ *
2987
+ * */
2956
2988
2957
2989
builtinScriptlets . push ( {
2958
- name : 'no -window-open-if .js' ,
2990
+ name : 'prevent -window-open.js' ,
2959
2991
aliases : [
2960
2992
'nowoif.js' ,
2961
- 'prevent -window-open.js' ,
2993
+ 'no -window-open-if .js' ,
2962
2994
'window.open-defuser.js' ,
2963
2995
] ,
2964
2996
fn : noWindowOpenIf ,
@@ -2994,6 +3026,10 @@ function noWindowOpenIf(
2994
3026
} ;
2995
3027
const noopFunc = function ( ) { } ;
2996
3028
proxyApplyFn ( 'open' , function open ( context ) {
3029
+ if ( pattern === 'debug' && safe . logLevel !== 0 ) {
3030
+ debugger ; // eslint-disable-line no-debugger
3031
+ return context . reflect ( ) ;
3032
+ }
2997
3033
const { callArgs } = context ;
2998
3034
const haystack = callArgs . join ( ' ' ) ;
2999
3035
if ( rePattern . test ( haystack ) !== targetMatchResult ) {
0 commit comments