-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
New C-S-S webcompat intervention: modifyLocalStorage #1026
Open
dharb
wants to merge
14
commits into
main
Choose a base branch
from
dharb/modify-localstorage
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+213
−67
Open
Changes from 12 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
1fc473a
add new function to delete specified localStorage entries
dharb 70ae715
Update webcompat-settings.d.ts
dharb fe5da2e
didn't read instructions :/
dharb 10a22a3
Update webcompat-settings.d.ts
dharb a40c410
Update webcompat-settings.d.ts
dharb 0b1e6cc
Merge branch 'main' into dharb/modify-localstorage
dharb 61cceb5
actually fix tests
dharb 9ee2097
add modified package-lock.json
dharb 54da104
add modify-localStorage privacy test page
dharb e37e70a
Merge branch 'main' into dharb/modify-localstorage
dharb 7eb0ed5
Merge branch 'main' into dharb/modify-localstorage
dharb 3a23f5f
fix paths in message-handlers.html
dharb d70f89f
improve modify-localstorage types
dharb 1742dd0
one more int test for a key that isn't present
dharb File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
integration-test/test-pages/webcompat/config/modify-localstorage.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{ | ||
"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" | ||
} | ||
} | ||
] | ||
} | ||
] | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
integration-test/test-pages/webcompat/pages/message-handlers.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Webcompat</title> | ||
<link rel="stylesheet" href="../../shared/style.css"> | ||
</head> | ||
<body> | ||
<script src="../../shared/utils.js"></script> | ||
|
||
<p>Webcompat, Message Handlers</p> | ||
<script> | ||
test('webkit.messageHandlers - polyfill prevents throw', async () => { | ||
let notThrown = true; | ||
try { | ||
window.webkit.messageHandlers.anythingatall.postMessage({}) | ||
} catch (e) { | ||
notThrown = false | ||
} | ||
return [ | ||
{ name: 'Error not thrown polyfil', result: notThrown, expected: true }, | ||
] | ||
}) | ||
test('webkit.messageHandlers - undefined should throw', async () => { | ||
let thrown = false; | ||
try { | ||
window.webkit.messageHandlers.jsHandler.postMessage({}) | ||
} catch (e) { | ||
thrown = true | ||
} | ||
return [ | ||
{ name: 'undefined handler should throw', result: thrown, expected: true }, | ||
] | ||
}) | ||
test('webkit.messageHandlers - reflected message', async () => { | ||
window.webkit.messageHandlers.printHandler = { | ||
postMessage() { | ||
return { test: "test" } | ||
} | ||
} | ||
|
||
const value = window.webkit.messageHandlers.printHandler.postMessage({}); | ||
|
||
return [ | ||
{ name: 'reflected message should pass through', result: value.test, expected: 'test' }, | ||
] | ||
}) | ||
renderResults(); | ||
|
||
async function captureError(fn) { | ||
try { | ||
// ensure Promise.reject is captured | ||
return fn().catch(e => e) | ||
} catch (e) { | ||
return e | ||
} | ||
} | ||
|
||
</script> | ||
</body> | ||
</html> |
35 changes: 35 additions & 0 deletions
35
integration-test/test-pages/webcompat/pages/modify-localstorage.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width"> | ||
<title>Modify localStorage</title> | ||
<link rel="stylesheet" href="../../shared/style.css"> | ||
<script> | ||
window.localStorage.setItem('keyToBeDeleted', 'valueToBeDeleted') | ||
window.localStorage.setItem('otherKey', 'valueToRemain') | ||
</script> | ||
</head> | ||
<body> | ||
<script src="../../shared/utils.js"></script> | ||
<p><a href="../index.html">[WebCompat]</a></p> | ||
|
||
<p>This page verifies that localStorage modifications work properly given the <a href="../config/modify-localstorage.json">config</a>. At this time, only deletion is supported.</p> | ||
|
||
<script> | ||
// eslint-disable-next-line no-undef | ||
test('Only specified localStorage entry should be removed', async () => { | ||
const specifiedKey = window.localStorage.getItem('keyToBeDeleted') | ||
const otherKey = window.localStorage.getItem('otherKey') | ||
|
||
return [ | ||
{ name: 'specified localStorage entry deleted', result: specifiedKey, expected: null }, | ||
{ name: 'other localStorage entry untouched', result: otherKey, expected: 'valueToRemain' } | ||
]; | ||
}); | ||
|
||
// eslint-disable-next-line no-undef | ||
renderResults(); | ||
</script> | ||
</body> | ||
</html> |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,7 +70,7 @@ | |
"@types/chrome": "^0.0.248", | ||
"@types/jasmine": "^5.1.4", | ||
"@typescript-eslint/eslint-plugin": "^6.9.1", | ||
"config-builder": "github:duckduckgo/privacy-configuration#main", | ||
"config-builder": "github:duckduckgo/privacy-configuration#dharb/modify-localstorage-config", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll flip this back once the config PR is merged. |
||
"esbuild": "^0.19.5", | ||
"eslint": "^8.57.1", | ||
"eslint-config-standard": "^17.1.0", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a test for a key that is also isn't present but the code deletes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This what you meant? https://github.com/duckduckgo/content-scope-scripts/pull/1026/files#diff-e8831dd92f5392a706f73b95990ac32c67e92544a34d094b502d63db301aad9eR27-R34 and line 28 below