From 1ed569676555d493c9c5575eaed22aa02569aac9 Mon Sep 17 00:00:00 2001 From: jonathanKingston Date: Wed, 25 Sep 2024 20:06:25 +0000 Subject: [PATCH] Release build 6.19.0 [ci release] --- .../ContentScopeScripts/dist/contentScope.js | 16 +++++ build/android/contentScope.js | 20 ++++++ build/contentScope.js | 20 ++++++ build/integration/contentScope.js | 20 ++++++ integration-test/playwright/webcompat.spec.js | 2 +- integration-test/test-pages.js | 7 +++ .../webcompat/config/modify-localstorage.json | 41 ++++++++++++ .../test-pages/webcompat/index.html | 59 +++--------------- .../webcompat/pages/message-handlers.html | 62 +++++++++++++++++++ .../webcompat/pages/modify-localstorage.html | 37 +++++++++++ package-lock.json | 6 +- src/features/web-compat.js | 20 ++++++ src/types/webcompat-settings.d.ts | 28 ++++++++- 13 files changed, 280 insertions(+), 58 deletions(-) create mode 100644 integration-test/test-pages/webcompat/config/modify-localstorage.json create mode 100644 integration-test/test-pages/webcompat/pages/message-handlers.html create mode 100644 integration-test/test-pages/webcompat/pages/modify-localstorage.html diff --git a/Sources/ContentScopeScripts/dist/contentScope.js b/Sources/ContentScopeScripts/dist/contentScope.js index 454756ccf..5b862ec4d 100644 --- a/Sources/ContentScopeScripts/dist/contentScope.js +++ b/Sources/ContentScopeScripts/dist/contentScope.js @@ -2583,6 +2583,9 @@ if (this.getFeatureSettingEnabled("screenLock")) { this.screenLockFix(); } + if (this.getFeatureSettingEnabled("modifyLocalStorage")) { + this.modifyLocalStorage(); + } } /** Shim Web Share API in Android WebView */ shimWebShare() { @@ -2948,6 +2951,19 @@ } catch { } } + /** + * Support for modifying localStorage entries + */ + modifyLocalStorage() { + const settings = this.getFeatureSetting("modifyLocalStorage"); + if (!settings || !settings.changes) + return; + settings.changes.forEach((change) => { + if (change.action === "delete") { + localStorage.removeItem(change.key); + } + }); + } /** * Support for proxying `window.webkit.messageHandlers` */ diff --git a/build/android/contentScope.js b/build/android/contentScope.js index f30a2128e..939df52f5 100644 --- a/build/android/contentScope.js +++ b/build/android/contentScope.js @@ -7899,6 +7899,10 @@ if (this.getFeatureSettingEnabled('screenLock')) { this.screenLockFix(); } + + if (this.getFeatureSettingEnabled('modifyLocalStorage')) { + this.modifyLocalStorage(); + } } /** Shim Web Share API in Android WebView */ @@ -8313,6 +8317,22 @@ } } + /** + * Support for modifying localStorage entries + */ + modifyLocalStorage () { + /** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */ + const settings = this.getFeatureSetting('modifyLocalStorage'); + + if (!settings || !settings.changes) return + + settings.changes.forEach((change) => { + if (change.action === 'delete') { + localStorage.removeItem(change.key); + } + }); + } + /** * Support for proxying `window.webkit.messageHandlers` */ diff --git a/build/contentScope.js b/build/contentScope.js index 47590fe44..8762f10a5 100644 --- a/build/contentScope.js +++ b/build/contentScope.js @@ -14606,6 +14606,10 @@ if (this.getFeatureSettingEnabled('screenLock')) { this.screenLockFix(); } + + if (this.getFeatureSettingEnabled('modifyLocalStorage')) { + this.modifyLocalStorage(); + } } /** Shim Web Share API in Android WebView */ @@ -15020,6 +15024,22 @@ } } + /** + * Support for modifying localStorage entries + */ + modifyLocalStorage () { + /** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */ + const settings = this.getFeatureSetting('modifyLocalStorage'); + + if (!settings || !settings.changes) return + + settings.changes.forEach((change) => { + if (change.action === 'delete') { + localStorage.removeItem(change.key); + } + }); + } + /** * Support for proxying `window.webkit.messageHandlers` */ diff --git a/build/integration/contentScope.js b/build/integration/contentScope.js index 47590fe44..8762f10a5 100644 --- a/build/integration/contentScope.js +++ b/build/integration/contentScope.js @@ -14606,6 +14606,10 @@ if (this.getFeatureSettingEnabled('screenLock')) { this.screenLockFix(); } + + if (this.getFeatureSettingEnabled('modifyLocalStorage')) { + this.modifyLocalStorage(); + } } /** Shim Web Share API in Android WebView */ @@ -15020,6 +15024,22 @@ } } + /** + * Support for modifying localStorage entries + */ + modifyLocalStorage () { + /** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */ + const settings = this.getFeatureSetting('modifyLocalStorage'); + + if (!settings || !settings.changes) return + + settings.changes.forEach((change) => { + if (change.action === 'delete') { + localStorage.removeItem(change.key); + } + }); + } + /** * Support for proxying `window.webkit.messageHandlers` */ diff --git a/integration-test/playwright/webcompat.spec.js b/integration-test/playwright/webcompat.spec.js index e8319128a..1a19a6970 100644 --- a/integration-test/playwright/webcompat.spec.js +++ b/integration-test/playwright/webcompat.spec.js @@ -30,7 +30,7 @@ test('web compat', async ({ page }, testInfo) => { }) export class WebcompatSpec { - htmlPage = '/webcompat/index.html' + htmlPage = '/webcompat/pages/message-handlers.html' config = './integration-test/test-pages/webcompat/config/message-handlers.json' /** diff --git a/integration-test/test-pages.js b/integration-test/test-pages.js index a0c25bb18..b9b638b11 100644 --- a/integration-test/test-pages.js +++ b/integration-test/test-pages.js @@ -94,4 +94,11 @@ describe('Test integration pages', () => { `${process.cwd()}/integration-test/test-pages/webcompat/config/shims.json` ) }) + + it('Properly modifies localStorage entries', async () => { + await testPage( + 'webcompat/pages/modify-localstorage.html', + `${process.cwd()}/integration-test/test-pages/webcompat/config/modify-localstorage.json` + ) + }) }) diff --git a/integration-test/test-pages/webcompat/config/modify-localstorage.json b/integration-test/test-pages/webcompat/config/modify-localstorage.json new file mode 100644 index 000000000..83ef58de3 --- /dev/null +++ b/integration-test/test-pages/webcompat/config/modify-localstorage.json @@ -0,0 +1,41 @@ +{ + "unprotectedTemporary": [], + "features": { + "webCompat": { + "exceptions": [], + "state": "enabled", + "settings": { + "windowSizing": "enabled", + "navigatorCredentials": "enabled", + "safariObject": "enabled", + "modifyLocalStorage": { + "state": "enabled", + "changes": [] + }, + "domains": [ + { + "domain": ["localhost", "privacy-test-pages.site"], + "patchSettings": [ + { + "op": "add", + "path": "/modifyLocalStorage/changes/-", + "value": { + "key": "keyToBeDeleted", + "action": "delete" + } + }, + { + "op": "add", + "path": "/modifyLocalStorage/changes/-", + "value": { + "key": "nonexistentKey", + "action": "delete" + } + } + ] + } + ] + } + } + } +} diff --git a/integration-test/test-pages/webcompat/index.html b/integration-test/test-pages/webcompat/index.html index 92deefa6f..c7210bcb7 100644 --- a/integration-test/test-pages/webcompat/index.html +++ b/integration-test/test-pages/webcompat/index.html @@ -3,60 +3,15 @@ - Webcompat + Webcompat Interventions - - -

Webcompat, Message Handlers

- +

[Home]

+ diff --git a/integration-test/test-pages/webcompat/pages/message-handlers.html b/integration-test/test-pages/webcompat/pages/message-handlers.html new file mode 100644 index 000000000..04b024a67 --- /dev/null +++ b/integration-test/test-pages/webcompat/pages/message-handlers.html @@ -0,0 +1,62 @@ + + + + + + Webcompat + + + + + +

Webcompat, Message Handlers

+ + + diff --git a/integration-test/test-pages/webcompat/pages/modify-localstorage.html b/integration-test/test-pages/webcompat/pages/modify-localstorage.html new file mode 100644 index 000000000..3635293ef --- /dev/null +++ b/integration-test/test-pages/webcompat/pages/modify-localstorage.html @@ -0,0 +1,37 @@ + + + + + + Modify localStorage + + + + + +

[WebCompat]

+ +

This page verifies that localStorage modifications work properly given the config. At this time, only deletion is supported.

+ + + + diff --git a/package-lock.json b/package-lock.json index 010c65635..902117501 100644 --- a/package-lock.json +++ b/package-lock.json @@ -2056,8 +2056,7 @@ }, "node_modules/config-builder": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/duckduckgo/privacy-configuration.git#efd2ca108cf353dbe272b6da53da41d5d1c1be85", - "integrity": "sha512-r3D3aSGYS7yQfHDJmOdegaezHWkkBUaXsKBe5gN70+czvFE49Tb87ANSspa4t2iylF+4ZPywbths7rdwY7ai5w==", + "resolved": "git+ssh://git@github.com/duckduckgo/privacy-configuration.git#02473639825f8e763265fd45b21788b4be8595c4", "dev": true, "license": "Apache 2.0", "dependencies": { @@ -7777,8 +7776,7 @@ "dev": true }, "config-builder": { - "version": "git+ssh://git@github.com/duckduckgo/privacy-configuration.git#efd2ca108cf353dbe272b6da53da41d5d1c1be85", - "integrity": "sha512-r3D3aSGYS7yQfHDJmOdegaezHWkkBUaXsKBe5gN70+czvFE49Tb87ANSspa4t2iylF+4ZPywbths7rdwY7ai5w==", + "version": "git+ssh://git@github.com/duckduckgo/privacy-configuration.git#02473639825f8e763265fd45b21788b4be8595c4", "dev": true, "from": "config-builder@github:duckduckgo/privacy-configuration#main", "requires": { diff --git a/src/features/web-compat.js b/src/features/web-compat.js index cdc7aabcd..8d5c924c7 100644 --- a/src/features/web-compat.js +++ b/src/features/web-compat.js @@ -117,6 +117,10 @@ export class WebCompat extends ContentFeature { if (this.getFeatureSettingEnabled('screenLock')) { this.screenLockFix() } + + if (this.getFeatureSettingEnabled('modifyLocalStorage')) { + this.modifyLocalStorage() + } } /** Shim Web Share API in Android WebView */ @@ -531,6 +535,22 @@ export class WebCompat extends ContentFeature { } } + /** + * Support for modifying localStorage entries + */ + modifyLocalStorage () { + /** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */ + const settings = this.getFeatureSetting('modifyLocalStorage') + + if (!settings || !settings.changes) return + + settings.changes.forEach((change) => { + if (change.action === 'delete') { + localStorage.removeItem(change.key) + } + }) + } + /** * Support for proxying `window.webkit.messageHandlers` */ diff --git a/src/types/webcompat-settings.d.ts b/src/types/webcompat-settings.d.ts index 99b5a3375..bf84e2282 100644 --- a/src/types/webcompat-settings.d.ts +++ b/src/types/webcompat-settings.d.ts @@ -29,7 +29,33 @@ export interface WebCompatSettings { undefined: string[]; }; }; + modifyLocalStorage?: { + state: State; + changes: { + key: string; + action: string; + }[]; + }; + notification?: { + state: State; + }; + permissions?: { + state: State; + supportedPermissions: {}; + }; + mediaSession?: State; + presentation?: State; + webShare?: State; + viewportWidth?: + | State + | { + state: State; + forcedDesktopValue?: string; + forcedMobileValue?: string; + }; + screenLock?: State; domains?: Domains; + plainTextViewPort?: State; } export interface Domain { /** @@ -53,5 +79,5 @@ export interface PatchSetting { /** * The value to replace at the specified path */ - value: string; + value: string | unknown[] | {} | number; }