Skip to content

armgit / cra

Public Imported from GitHub
0

The open-source Arc replacement for macOS. Spaces, pinned tabs, split view, Little Windows and Arc's shortcuts on Chromium, with your Arc sidebar imported in one go.

Arc parity: Block cookie banners (Arc's "Block Cookie Banners", off by default)

Victor93b20a638d0c
diff --git a/Packages/CraCore/Sources/CraCore/CookieBanners.swift b/Packages/CraCore/Sources/CraCore/CookieBanners.swift
new file mode 100644
index 0000000..b833084
--- /dev/null
+++ b/Packages/CraCore/Sources/CraCore/CookieBanners.swift
@@ -0,0 +1,26 @@
+import Foundation
+
+/// Arc's Settings ▸ General "Block Cookie Banners" (off by default, Arc 1.172.1). Cra's blocker
+/// filters requests by domain, so banners are hidden instead: the consent managers most sites use,
+/// by the containers they put on the page, and the scroll lock some of them set while showing.
+public enum CookieBanners {
+ /// The banners' containers (OneTrust, Cookiebot, Didomi, Quantcast, TrustArc, Usercentrics,
+ /// CookieYes, Osano, iubenda, Complianz, Termly, Sourcepoint, Klaro, Borlabs, Axeptio, Google's
+ /// Funding Choices, CookieConsent).
+ public static let selectors = [
+ "#onetrust-banner-sdk", "#onetrust-consent-sdk", "#CybotCookiebotDialog", "#CybotCookiebotDialogBodyUnderlay",
+ "#didomi-host", ".qc-cmp2-container", "#qc-cmp2-container", "#truste-consent-track", ".truste_overlay",
+ ".truste_box_overlay", "#usercentrics-root", "#usercentrics-cmp-ui", ".cky-consent-container", ".cky-overlay",
+ ".osano-cm-window", "#iubenda-cs-banner", "#cmplz-cookiebanner-container", ".cmplz-cookiebanner", "#termly-code-snippet-support",
+ "[id^=\"sp_message_container\"]", ".klaro .cookie-notice", "#BorlabsCookieBox", "#axeptio_overlay",
+ ".fc-consent-root", ".cc-window", ".cc-banner", "#cookie-law-info-bar", "#cookie-notice",
+ ]
+
+ /// The stylesheet a page gets: the banners hidden, scrolling back where a banner locked it.
+ public static let css: String = {
+ let hide = selectors.joined(separator: ", ") + " { display: none !important; visibility: hidden !important; }"
+ let unlock = "html.sp-message-open, body.didomi-popup-open, body.cmplz-blocked-content, body.cky-modal-open, "
+ + "body.onetrust-consent-sdk-open { overflow: auto !important; position: static !important; }"
+ return hide + " " + unlock
+ }()
+}
diff --git a/Packages/CraCore/Sources/CraCore/SidebarModel.swift b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
index dacf3c1..e43e03a 100644
--- a/Packages/CraCore/Sources/CraCore/SidebarModel.swift
+++ b/Packages/CraCore/Sources/CraCore/SidebarModel.swift
@@ -523,6 +523,8 @@ public struct AppSettings: Codable, Equatable {
public var restoreWindows: Bool = true
/// Arc's Settings ▸ Advanced "Allow websites to get your theme data" (ArcThemeData), on by default.
public var shareThemeWithWebsites: Bool = true
+ /// Arc's Settings ▸ General "Block Cookie Banners" (CookieBanners), off by default as in Arc.
+ public var blockCookieBanners: Bool = false
/// Arc's searchSuggestEnabled: the command bar asks the search engine for suggestions
/// as you type and fills its rows with them.
public var searchSuggestions: Bool = true
@@ -733,6 +735,7 @@ extension AppSettings {
littleWindowArchiveAfter = (try? c.decodeIfPresent(LittleWindowArchive.self, forKey: .littleWindowArchiveAfter)) ?? .sixHours
restoreWindows = try c.decodeIfPresent(Bool.self, forKey: .restoreWindows) ?? true
shareThemeWithWebsites = try c.decodeIfPresent(Bool.self, forKey: .shareThemeWithWebsites) ?? true
+ blockCookieBanners = try c.decodeIfPresent(Bool.self, forKey: .blockCookieBanners) ?? false
searchSuggestions = try c.decodeIfPresent(Bool.self, forKey: .searchSuggestions) ?? true
showSpaceHeaderOnSingleSpace = try c.decodeIfPresent(Bool.self, forKey: .showSpaceHeaderOnSingleSpace) ?? true
sharedFavorites = try c.decodeIfPresent(Bool.self, forKey: .sharedFavorites) ?? false
diff --git a/Packages/CraCore/Tests/CraCoreTests/CookieBannersTests.swift b/Packages/CraCore/Tests/CraCoreTests/CookieBannersTests.swift
new file mode 100644
index 0000000..48d66fc
--- /dev/null
+++ b/Packages/CraCore/Tests/CraCoreTests/CookieBannersTests.swift
@@ -0,0 +1,17 @@
+import CraCore
+import Testing
+
+/// Arc's "Block Cookie Banners": the consent managers' containers are hidden, nothing else.
+struct CookieBannersTests {
+ @Test(arguments: ["#onetrust-banner-sdk", "#CybotCookiebotDialog", "#didomi-host", ".qc-cmp2-container", "#usercentrics-root"])
+ func hidesTheBigConsentManagers(selector: String) {
+ #expect(CookieBanners.css.contains(selector))
+ }
+
+ @Test func hidesOnlyIdsClassesAndAttributes() {
+ // No bare element selectors: they would hide parts of every page.
+ for s in CookieBanners.selectors {
+ #expect(s.hasPrefix("#") || s.hasPrefix(".") || s.hasPrefix("["), "\(s)")
+ }
+ }
+}
diff --git a/Sources/Cra/Services/BrowserManager.swift b/Sources/Cra/Services/BrowserManager.swift
index f6cf9d5..254302f 100644
--- a/Sources/Cra/Services/BrowserManager.swift
+++ b/Sources/Cra/Services/BrowserManager.swift
@@ -1080,7 +1080,10 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
guard let id = tabID(of: browser) else { return }
// Start-up phases: firstPageShown, then the page's navigation committed, then loaded.
if committed, id == visibleTabID { Perf.phase("firstPageCommitted") }
- if committed { shareTheme(id, with: browser) }
+ if committed {
+ shareTheme(id, with: browser)
+ if let css = store.cookieBannerCSS(item: id) { adopt(css, as: "__craCookieBanners", in: browser) }
+ }
delegate?.browserManagerDidUpdate(id)
}
@@ -1090,8 +1093,14 @@ final class BrowserManager: NSObject, @preconcurrency CraBrowserDelegate {
private func shareTheme(_ id: UUID, with browser: CraBrowser) {
let systemDark = NSApp?.effectiveAppearance.bestMatch(from: [.darkAqua, .aqua]) == .darkAqua
guard let css = store.themeDataCSS(item: id, systemDark: systemDark) else { return }
+ adopt(css, as: "__craArcTheme", in: browser)
+ }
+
+ /// A stylesheet adopted by the page's document from Cra's world, kept under `name` there so a
+ /// later commit of the same document replaces it.
+ private func adopt(_ css: String, as name: String, in browser: CraBrowser) {
guard let literal = String(data: (try? JSONSerialization.data(withJSONObject: [css], options: [])) ?? Data(), encoding: .utf8) else { return }
- let script = "(()=>{let s=window.__craArcTheme;if(!s){s=window.__craArcTheme=new CSSStyleSheet();"
+ let script = "(()=>{let s=window.\(name);if(!s){s=window.\(name)=new CSSStyleSheet();"
+ "document.adoptedStyleSheets=[...document.adoptedStyleSheets,s];}s.replaceSync(\(literal)[0]);})()"
guard let params = try? JSONSerialization.data(withJSONObject: ["expression": script]),
let json = String(data: params, encoding: .utf8) else { return }
diff --git a/Sources/Cra/Services/SidebarStore.swift b/Sources/Cra/Services/SidebarStore.swift
index 4c7074e..2251659 100644
--- a/Sources/Cra/Services/SidebarStore.swift
+++ b/Sources/Cra/Services/SidebarStore.swift
@@ -426,6 +426,9 @@ final class SidebarStore {
/// Arc's "Allow websites to get your theme data": the `:root` rule a tab's pages get, from its
/// space's theme in the scheme pages see (View ▸ Appearance, else the Mac's); nil when off or
/// incognito.
+ /// Arc's "Block Cookie Banners": the stylesheet a tab's pages get, nil while it's off.
+ func cookieBannerCSS(item id: UUID) -> String? { settings.blockCookieBanners ? CookieBanners.css : nil }
+
func themeDataCSS(item id: UUID, systemDark: Bool) -> String? {
guard settings.shareThemeWithWebsites, !isIncognito(item: id),
let theme = spaceID(ofItem: id).flatMap({ spaces[$0]?.theme }) else { return nil }
diff --git a/Sources/Cra/UI/Settings/PrivacyPane.swift b/Sources/Cra/UI/Settings/PrivacyPane.swift
index 8987f4e..a07375b 100644
--- a/Sources/Cra/UI/Settings/PrivacyPane.swift
+++ b/Sources/Cra/UI/Settings/PrivacyPane.swift
@@ -25,8 +25,19 @@ struct PrivacyPane: View {
Toggle("Block ads and trackers", isOn: $store.settings.blockAdsAndTrackers)
.toggleStyle(.switch).labelsHidden()
}
+ SettingsCardDivider()
+ // Arc: Settings ▸ General "Block Cookie Banners", off by default.
+ SettingsCardRow {
+ HStack(spacing: 5.5) {
+ SettingsGlyph(symbol: "eye.slash.fill", color: Color(nsColor: .systemOrange))
+ Text("Block cookie banners").font(.system(size: 13))
+ }
+ } trailing: {
+ Toggle("Block cookie banners", isOn: $store.settings.blockCookieBanners)
+ .toggleStyle(.switch).labelsHidden()
+ }
}
- SettingsFootnote("Requests to known ad and tracker domains are cancelled unless they are first-party to the page.")
+ SettingsFootnote("Requests to known ad and tracker domains are cancelled unless they are first-party to the page. Cookie banners from the common consent tools are hidden; pages load again with the change.")
SettingsHeader("Connections").padding(.top, 20)
SettingsCard {
diff --git a/Tests/BrowserManagerLifecycleTests.swift b/Tests/BrowserManagerLifecycleTests.swift
index 747909b..57656ea 100644
--- a/Tests/BrowserManagerLifecycleTests.swift
+++ b/Tests/BrowserManagerLifecycleTests.swift
@@ -360,6 +360,11 @@ enum BrowserManagerLifecycleTests {
store.settings.shareThemeWithWebsites = false
manager.browser(rt.browser, didChangeCommittedLoad: true)
expect(themed() == before + 1, "with the setting off, pages get none")
+ // Arc's "Block Cookie Banners", off by default: on, a committed page gets the banner rules.
+ store.settings.blockCookieBanners = true
+ manager.browser(rt.browser, didChangeCommittedLoad: true)
+ expect(themed() == before + 2 && rt.browser.lastIsolatedParams.contains("__craCookieBanners")
+ && rt.browser.lastIsolatedParams.contains("#onetrust-banner-sdk"), "blocking cookie banners hides them on every committed page")
manager.closeAll()
}
diff --git a/Tests/BrowserManagerSupport/AppServices.swift b/Tests/BrowserManagerSupport/AppServices.swift
index cc3c040..40e6257 100644
--- a/Tests/BrowserManagerSupport/AppServices.swift
+++ b/Tests/BrowserManagerSupport/AppServices.swift
@@ -23,7 +23,9 @@ enum TestRoot { case today }
struct Settings {
var autoPictureInPicture = false
var shareThemeWithWebsites = true
+ var blockCookieBanners = false
}
+ func cookieBannerCSS(item: UUID) -> String? { settings.blockCookieBanners ? "#onetrust-banner-sdk { display: none !important; }" : nil }
func themeDataCSS(item: UUID, systemDark: Bool) -> String? {
settings.shareThemeWithWebsites ? ":root { --arc-palette-title: #211A00FF; }" : nil
}
diff --git a/Tests/Scenarios/cookie-banners.scenario b/Tests/Scenarios/cookie-banners.scenario
new file mode 100644
index 0000000..a8b4bfd
--- /dev/null
+++ b/Tests/Scenarios/cookie-banners.scenario
@@ -0,0 +1,9 @@
+# Arc's "Block Cookie Banners" (Arc 1.172.1, off by default; docs/arc-parity.md): on, a consent
+# manager's banner on a page is hidden.
+budget rss=700 stalls50=10
+seed settings.json {"hasSeenImportPrompt": true, "toolbarDefaultMigrated": true, "showToolbar": false, "blockCookieBanners": true}
+cra://open?url=${PAGE}?n=consent
+expect-log loaded 127\.0\.0\.1 \(HTTP 200\)
+wait 1
+cra://debug?cdp=Runtime.evaluate&params={"expression":"(()=>{const d=document.createElement('div');d.id='onetrust-banner-sdk';d.textContent='We use cookies';document.body.append(d);const k=document.createElement('div');k.id='kept';document.body.append(k);return 'banner-'+getComputedStyle(d).display+'-'+getComputedStyle(k).display})()"}
+expect-log Cra cdp Runtime.evaluate .*"value":"banner-none-block"
diff --git a/docs/arc-parity.md b/docs/arc-parity.md
index dc80e3c..bef5c1b 100644
--- a/docs/arc-parity.md
+++ b/docs/arc-parity.md
@@ -32,7 +32,7 @@ or Arc-only service), per CONTRIBUTING.md.
| Theme data for websites | Settings ▸ Advanced "Allow websites to get your theme data" | done | `--arc-palette-*` and `--arc-background-*` as #RRGGBBAA, from the space's theme (ArcThemeData; fitted to Arc's stored palette, checked live). |
| Window dragging from the top of webpages | Settings ▸ Advanced | measured | With the toolbar hidden, Arc drags the window from the top 56 pt of the page (66 pt below the window's top); 58 pt in, the page gets the drag. Cra's strip reaches 4 pt into the page. Needs clicks in that band held until the pointer moves, across Chromium's page windows. |
| Restore windows from previous session | Settings ▸ Advanced | done | Settings ▸ Advanced; off keeps the window in use last. |
-| Block Cookie Banners | Settings ▸ General | missing | Cra blocks ads and trackers only. |
+| Block Cookie Banners | Settings ▸ General | done | Settings ▸ Privacy; hides the common consent managers' banners (CookieBanners), off by default as in Arc. |
| Archive Little Arcs after | Settings ▸ Links (6 hours default) | done | Settings ▸ Tabs ▸ Links; a Little Window left alone that long closes into the archive. |
| Previews (Gmail, Calendar on Favorites) | Settings ▸ General ▸ Previews Settings… | missing | Fetches through the browser session; nothing leaves the Mac. |
| Join Meeting ⌃⌘J | Shortcuts | missing | Needs calendar previews first. |
@@ -83,7 +83,7 @@ gains "New Profile".
| Arc tab | Rows Cra lacks |
|---|---|
-| General | Previews Settings…, Block Cookie Banners |
+| General | Previews Settings… (Block Cookie Banners done, under Privacy) |
| Profiles | "New documents" app (Arc's Notes/Easels); Privacy, Passwords, Credit Cards and Notifications done |
| Links | "Open Little Arc when clicking on links with ⌥⌘ held"; Archive Little Windows after done |
| Advanced | window dragging from the top of webpages (measured), Shared Quotes (arc.net), Enable Boosts (sound effects, restore windows and theme data done) |
@@ -123,6 +123,7 @@ in this sweep (Essential Shortcuts window, Library pages).
measured live in Arc (names, #RRGGBBAA format, no trace in the page's markup) and fitted to the
semantic palette Arc stores per space.
- Edit ▸ Find ▸ Use Selection to Find and Jump to Selection (⌘J).
+- Settings ▸ Privacy ▸ Block cookie banners (Arc's "Block Cookie Banners", off by default).
- Easels, first version: File ▸ New Easel (⌃⇧E) opens a canvas in the tab (EaselBrowser, a page
engine of its own like WebKitBrowser, so sidebar.json is unchanged: the tab's address is
easel://<id>, the drawing Easels/<id>.json); Library ▸ Easels and Window ▸ View Easels….
@@ -146,5 +147,5 @@ in this sweep (Essential Shortcuts window, Library pages).
editor couldn't be put on screen to copy. Needs a site in Arc (Victor's OK to run the real Arc, or
a localhost server).
- AppleScript dictionary (a new way for other apps to drive Cra; worth a decision on what it may do,
- as for cra:// URLs), cookie banner blocking, window dragging from the top of pages (measured, above), Previews and
+ as for cra:// URLs), window dragging from the top of pages (measured, above), Previews and
Join Meeting: not started.