From AdBlocker Developer Summit 2020
Miyoung Shin and Lorenzo Tilve from Igalia discuss work in the Chromium open source browser project, performed by Igalia to improve things for ad Bbocking and content blocking use cases.
Fixing Gaps. Strengthening the Chromium platform for content blocking
1. Fixing Gaps: Strengthening the
Chromium Platform for Content
Blocking
myid.shin@igalia.com
ltilve@igalia.com
2. Agenda
โ About Igalia
โ New features for Content Blocking
โ The need for tabs.removeCSS and extending exension new API
โ What is Shadow Root / Why we need to access โclosed shadow rootโ?
โ Implement in Blink / Intent to Ship: blink-dev@
โ For new extension API
โ Implement in chrome / Proposal document / How to use
โ Release schedule
โ Future plans
3. About Igalia
โ Open Source Consultancy with HQ in Galicia, Spain
โ 90 employees all around the world
โ Mainly specialized on Browsers and Web Engines:
โ Chromium, Firefox, WebKit and WPE
โ Compilers, JavaScript engines, Graphics, Multimedia, Accessibility
4.
5. New features for Content Blocking
Add a chrome.tabs.removeCSS (https://crbug.com/608854)
Add a chrome.dom.openOrClosedShadowRoot (https://crbug.com/778816)
Apply content scripts to about: and data: urls (https://crbug.com/55084)
6. The need for tabs.removeCSS
โ A way to hide blocked ads is by adding new CSS rules through existing
chrome.tabs.insertCSS
โ https://developer.chrome.com/extensions/tabs#method-insertCSS
โ However, as content changes dynamically, it was necessary to have a
mechanism in Chromium to modify the visibility of elements that vary over
time.
โ A removeCSS method as already available on other engines:
โ https://bugzilla.mozilla.org/show_bug.cgi?id=1247455
7. The need for tabs.removeCSS
โ There was an open upstream issue for it (https://crbug.com/608854)
โ An initial CL for it had been started by Manish Jethani but got discontinued
โ https://crrev.com/c/918606
8. โ The bug was taken over and work completed by Antonio Gomes
โ Updated original CL to use the new APIs
โ Created new issue for โExtension API Modification: chrome.tabs.removeCSSโ
(https://crbug.com/1101473)
โ Added the necessary functional tests
โ Iterated the through the review process
โ Got it landed (https://crrev.com/c/2250506)
โ Implementation adds security restriction that extensions can only remove their
own injected CSS.
The need for tabs.removeCSS
9. tabs.removeCSS new API
โ The new API method definition is added to
chrome/common/extensions/api/tabs.json
"name": "removeCSS",
"type": "function",
"description" โRemove CSS injected by $(ref:tabs.insertCSS).",
"parameters":
"tabId" : โID of the tab from which to remove the CSS; defaults to active one.โ
"details" : โDetails of the CSS text to remove.โ
"callback" : โCalled when all the CSS has been removed.โ
10. โ And the new extension types objects into
extensions/common/api/extension_types.json
"id": "DeleteInjectionDetails",
"type": "object",
"description": "CSS to remove. Either the code or the file property, but not both",
"properties": {
"code" : โCSS code to removeโ,
"file" : โCSS file to removeโ,
"allFrames" : โIf should be removed from all frames or just the top oneโ,
"frameId": โThe frame from where the CSS should be removedโ
tabs.removeCSS new API
11. โ Function
chrome/test/data/extensions/api_test/executescript/remove_css/*
async function removeCSSWithFileShouldSucceed() {
// When no frame ID is specified, the CSS is removed from the top frame.
await testRemoveCSS({file}, [originalColor, , , , , ]);
chrome.test.succeed();
},
async function removeCSSWithDifferentFileShouldDoNothing() {
// The CSS is not removed even though "/file.css" and "/other.css" are identical.
await testRemoveCSS({file: '/other.css' , allFrames: true});
chrome.test.succeed();
},
tabs.removeCSS new API
14. What is Shadow Root
Encapsulation : a component to have its very own โshadowโ DOM tree.
https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM
15. What is Shadow Root
mode options to attach a shadow root
let shadow1 = element1.attachShadow({mode: 'open'});
let shadow2 = element2.attachShadow({mode: 'closed'});
element1.shadowRoot === shadow1; // true
element2.shadowRoot === null; // true
16. Why we need to access โclosed shadow rootโ?
โ Ads hidden behind closed shadow root
โ Extensions APIs on the user's behalf
โ Existing workaround using Extensions APIs
โ NOT a security issue
โ Firefox supports Element.openOrClosedShadowRoot
17. Implement in Blink
โ Element.prototype.openOrClosedShadowRoot
โ Specify API with Web IDL.
โ But,
โ Do not expose it to general Web
โ Expose it to only isolated content script of Extensions
[Affects=Nothing, ExposedPerWorld=IsolatedWorld , NotEnumerable,
CheckSecurity=ReturnValue, Custom=Getter] readonly attribute
ShadowRoot? openOrClosedShadowRoot;
third_party/blink/renderer/core/dom/element.idl
18. Intent to Ship: blink-dev@
โ The Chromium process to launch a new feature in Blink
โ https://www.chromium.org/blink/launching-features
โ Two main concerns
โ Web namespace pollution
โ Web IDL lack for custom
โ https://groups.google.com/a/chromium.org/g/blink-dev/c/VEVXgm83UXk/m/iiIBCA
kXAgAJ
Element.prototype.openOrClosedShadowRoot
19. For new extension API
โ Proposal :
https://chromium.googlesource.com/chromium/src/+/master/extensions/docs/
new_api_proposal.md
โ Implementing :
https://www.chromium.org/developers/design-documents/extensions/propose
d-changes/creating-new-apis
25. Release schedule
โ For chrome.tabs.removeCSS on M87
โ For chrome.dom.openOrClosedShadowRoot on M87 / M88
26. Future plans and ongoing work
โ Moving forward implementation of new CSS selectors to ease element hiding
โ Working on a prototype for :has() pseudo selector
https://github.com/w3c/csswg-drafts/issues/4903
โ Intent to proto type and ship of :dir() pseudo class
(https://chromium-review.googlesource.com/c/chromium/src/+/2460849)
โ Intent to ship complex :not()
(https://groups.google.com/a/chromium.org/g/blink-dev/c/0alTkXvDCL8/m/-ClOGv
OJBAAJ)
โ Ongoing progress on increasing Chromium capabilities for content-blocking useful
features as more selectors, or incoming JS spec implementations.