Opened on 07/11/2018 at 01:31:58 PM

Closed on 07/20/2018 at 01:39:58 PM

Last modified on 08/28/2018 at 12:25:07 PM

#6781 closed change (fixed)

Implement basic support for snippet filters

Reported by: mjethani Assignee: mjethani
Priority: P2 Milestone:
Module: Core Keywords: circumvention
Cc: kzar, hfiguiere, rscott, Ross Blocked By: #6689
Blocking: #6538, #6782, #6790, #6791, #6798, #6803 Platform: Unknown / Cross platform
Ready: yes Confidential: no
Tester: Unknown Verified working: no
Review URL(s):

Description (last modified by mjethani)


#6538 describes support for a new feature called "Snippets" in the Core module. We want to ship a basic version of this initially and develop it further as we learn from experience.

The initial implementation should have the following limitations:

  • Similar to element hiding emulation, if there are too many snippet filters then it won't perform well (this will be resolved by #6665)
  • It will not be possible to specify exceptions for snippet filters
  • Only snippet filters from our own "circumvention" list will be parsed, such filters from other lists will be ignored
  • The snippets library will be shipped statically with the extension and will not be updated periodically
  • Generic snippet filters will be allowed (#6797)

What to change

In lib/filterClasses.js:

  • Rename ElemHideBase to ContentFilter and the selector property to body. In the ContentFilter constructor, do not do any CSS escaping.
  • Create a new class ElemHideBase that extends from ContentFilter. Add a selector property getter that return the value of the superclass's body property, after applying CSS escaping.
  • Rename elemhideRegExp to contentRegExp.
  • Create a new SnippetFilter class that extends from ContentFilter. Add a script property getter that returns the value of the superclass's body property.

Create a new lib/snippets.js file that contains a new Snippets module, modeled on ElemHideEmulation in lib/elemHideEmulation.js. It should have a getScriptsForDomain(domain) function that returns all the snippet scripts that apply on the given domain, ignoring any exceptions.

In lib/filterListener.js, add and remove any snippet filters (instances of SnippetFilter) to the new Snippets module.

In the new lib/snippets.js:

  • Implement a parseScript(script) function that returns an array of arrays containing the "commands" (snippet calls) to execute, with the arguments to each command, after parsing the given script based on the specification in #6538.
  • Implement a compileScript(script, libraries) function that takes a script and a list of libraries (in source form) and returns executable JavaScript code, which includes the library sources followed by calls to one or more snippet functions with zero or more arguments based on the given script.

Add lib/content/snippets.js as the initial snippets library containing one simple function that logs its arguments to the console.

In lib/filterListener.js, add a snippet filter only if it belongs to a subscription of type circumvention (check the type property of the Subscription object (#6689)).

In lib/content/snippets.js, implement an API such that a snippet can be executed in either the content script's context (default) or the document's context. This would ideally be a function that wraps the snippet into an "injector" that is then exported in place of the snippet. When the injector is called, it should forward the call to the snippet, but in the form of a script injected directly into the document. The technique for injecting the script into the document should be copied from inject.preload.js in the adblockpluschrome repo.

Hints for testers

These changes affect element hiding and element hiding emulation. Make sure these features work as they did before. In particular, check that CSS escaping (#4684) works.

For Snippets, make sure that snippet filters, as described in #6538, are being parsed, compiled, and executed (via the web extension) correctly. This may be done using the log snippet, which logs its arguments to the DevTools console for the page. For example, the filter$#log 'Hello, world!' should log the string "Hello, world!" to the console on Make sure quoting and escaping within the snippet filter, as described in #6538, work correctly.

Also make sure that snippet filters are accepted only from the "circumvention" filter list (#6689) or the user's own filters. Any snippet filters in any other list (e.g. EasyList) should be ignored silently.

Known issues

#6811 is a known issue and will be addressed in a future version.

Attachments (0)

Change History (24)

comment:1 Changed on 07/11/2018 at 01:44:23 PM by mjethani

  • Review URL(s) modified (diff)
  • Status changed from new to reviewing

comment:2 Changed on 07/11/2018 at 01:46:49 PM by mjethani

  • Summary changed from Implement basic version of the Snippets feature to Implement basic support for snippet filters

comment:3 Changed on 07/11/2018 at 02:00:37 PM by mjethani

  • Blocking 6782 added

comment:4 Changed on 07/11/2018 at 03:10:01 PM by hfiguiere

  • Cc hfiguiere added

comment:5 Changed on 07/11/2018 at 03:12:12 PM by mjethani

  • Description modified (diff)

comment:6 Changed on 07/11/2018 at 03:53:05 PM by mjethani

  • Review URL(s) modified (diff)

comment:7 Changed on 07/12/2018 at 11:14:50 AM by mjethani

  • Sensitive set

comment:8 Changed on 07/12/2018 at 04:29:28 PM by mjethani

  • Blocking 6790 added

comment:9 Changed on 07/13/2018 at 02:20:40 PM by mjethani

  • Review URL(s) modified (diff)

comment:10 Changed on 07/13/2018 at 03:21:59 PM by mjethani

  • Blocking 6791 added

comment:11 Changed on 07/19/2018 at 01:43:57 PM by mjethani

  • Description modified (diff)

comment:12 Changed on 07/19/2018 at 04:46:11 PM by mjethani

  • Blocking 6798 added

comment:13 Changed on 07/20/2018 at 12:57:56 PM by mjethani

  • Blocked By 6689 added
  • Description modified (diff)

comment:14 Changed on 07/20/2018 at 01:34:44 PM by mjethani

  • Description modified (diff)

comment:15 Changed on 07/20/2018 at 01:39:58 PM by mjethani

  • Resolution set to fixed
  • Status changed from reviewing to closed

comment:16 Changed on 07/20/2018 at 01:54:34 PM by mjethani

  • Description modified (diff)

comment:17 Changed on 07/20/2018 at 02:31:18 PM by kzar

  • Description modified (diff)

Thanks, this is a really well written issue.

The testing instructions are good too. The only thing I could see to add was a concrete example of how to use the log snippet (did I get that right?).

comment:18 Changed on 07/20/2018 at 02:44:46 PM by mjethani

  • Description modified (diff)

I've updated the example slightly, thanks for adding it.

comment:19 Changed on 07/24/2018 at 08:01:33 PM by mjethani

  • Review URL(s) modified (diff)

comment:20 Changed on 07/25/2018 at 06:04:30 AM by mjethani

  • Blocking 6803 added

comment:21 Changed on 08/01/2018 at 01:57:05 PM by kzar

(Last week.)

A commit referencing this issue has landed:
Issue 6538, 6781 - Minimize access to ElemHideBase's selector property

comment:22 Changed on 08/01/2018 at 03:16:38 PM by mjethani

It seems all the commits are logged in #6538 because it appears first in the commit message.

comment:23 Changed on 08/11/2018 at 02:48:55 AM by mjethani

  • Cc rscott Ross added
  • Description modified (diff)

comment:24 Changed on 08/28/2018 at 12:25:07 PM by sebastian

  • Sensitive unset

Add Comment

Modify Ticket

Change Properties
as closed .
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from mjethani.
Note: See TracTickets for help on using tickets.