Skip to content

Add "window-close" scriptlet #158

Closed
Closed
@ameshkov

Description

@ameshkov

Here's the problem description:

  1. There are some applications that open new ad popups randomly.
  2. The problem is that we cannot handle them with $popup rules for several reasons. First, this may be a new browser instance (so the extension is not yet initialized and the popup rule does not match). Second, a new browser window is not counted as a popup.
  3. Instead of that we could add a scriptlet rule that would handle those cases and simply close the window.

There's a real demand for that, see AceStream example:
https://github.com/AdguardTeam/AdguardFilters/issues?q=is%3Aissue+acestream

The solution would be to use this rule:
acestream.com[$path='/plan/select?popup=noads']#%#//scriplet('window-close')

Alternatively (for older versions of AdGuard) we should also allow specifying the path pattern in the parameter:
acestream.com#%#//scriplet('window-close', '/plan/select?popup=noads')

Also, I see a couple of rules in the filters that could be replaced with this new scriptlet (maybe there are more):

deloplen.com#%#!function(){setTimeout(function() { window.close(); }, 1000);}();
givirsou.net#%#window.close();

⚡️ window-close

This scriptlet immediately closes the browser tab.

Syntax

example.org#%#//scriptlet('window-close'[, path])
  • path - optional, string or a regular expression that must match the current location's path (window.location.pathname + window.location.search). If not specified, the scriptlet is executed on every page.

Examples

! Closes the window if it's URL is like `http(s)://example.org/path/param=value`:
`example.org#%#//scriplet('window-close', '/path/param=value')`

! Closes the window if it's URL is like `http(s)://example.org/0123.html`:
`example.org#%#//scriplet('window-close', '/[0-9]+.html/')`

Alternatively, instead of specifying path as a scriptlet parameter, you can use the $path modifier:

! Closes the window if it's URL is like `http(s)://example.org/0123.html`:
`[$path=/[0-9]+.html/]example.org#%#//scriplet('window-close')`

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions