prevent-window-open
The prevent-window-open snippet prevents window.open calls whose arguments match a pattern, optionally returning a decoy pop-up handle so the page cannot detect the block by inspecting the returned window. Calls that do not match are passed through to the native window.open, so legitimate pop-ups keep working.
window.open is wrapped once, on the first filter; further filters append rules, and the first rule that matches wins. The wrapper preserves the native property descriptor and toString() output. If window.open cannot be wrapped, the snippet logs a warning and leaves the page untouched.
Parameters
|
Name |
Description |
Mandatory |
Default |
|---|---|---|---|
|
pattern |
Matched against all |
No |
'', matches every call |
|
delay |
Milliseconds. If omitted, prevented calls return |
No |
'', returns |
|
decoy |
Which decoy to hand back — see below. Only relevant when |
No |
|
Decoy values
|
Value |
Behaviour |
|---|---|
|
|
The requested URL is loaded in a hidden 1×1 |
|
|
The same, backed by an |
|
|
A real pop-up is opened, but pointed at |
For iframe and obj the handle is a facade over an object owned by the snippet, never a real window. It serves closed, close, opener, frameElement, parent, top, self, window, globalThis, frames, location, document and history, and never returns live host objects such as navigator or storage. popup.location is an inert about:blank whose assign, replace and reload do nothing.
Filter examples
For parameter syntax and escaping rules, see Snippets Overview.
|
Filter |
Result |
|---|---|
|
|
Prevents every |
|
|
Prevents only calls whose joined arguments match |
|
|
Same, case-insensitive. |
|
|
Literal match: prevents calls whose joined arguments contain |
|
|
Returns a decoy pop-up handle backed by a hidden |
|
|
Same, but the decoy is backed by an |
|
|
Opens a real pop-up pointed at |
|
|
Inverted match: prevents every call except the ones aimed at example.com or one of its subdomains, returning a decoy iframe removed after 1000 ms. |
Debugging
|
Message |
When |
Definition |
|---|---|---|
|
|
Beginning of snippet execution |
|
|
|
After |
Calls are now intercepted. Logged once per page, for the first filter. |
|
|
Each time a call matches a rule |
The call was prevented. The logged arguments are the haystack the pattern was tested against, so use them to refine |
|
|
Each time a call matches no rule |
The call went through to the native |
Pop-ups opened by a hidden <form target="_blank"> and submit(), or by a hijacked anchor click, never call window.open and are not affected by this snippet.