Skip to content

Commit 1ed5696

Browse files
Release build 6.19.0 [ci release]
1 parent 381f152 commit 1ed5696

File tree

13 files changed

+280
-58
lines changed

13 files changed

+280
-58
lines changed

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2583,6 +2583,9 @@
25832583
if (this.getFeatureSettingEnabled("screenLock")) {
25842584
this.screenLockFix();
25852585
}
2586+
if (this.getFeatureSettingEnabled("modifyLocalStorage")) {
2587+
this.modifyLocalStorage();
2588+
}
25862589
}
25872590
/** Shim Web Share API in Android WebView */
25882591
shimWebShare() {
@@ -2948,6 +2951,19 @@
29482951
} catch {
29492952
}
29502953
}
2954+
/**
2955+
* Support for modifying localStorage entries
2956+
*/
2957+
modifyLocalStorage() {
2958+
const settings = this.getFeatureSetting("modifyLocalStorage");
2959+
if (!settings || !settings.changes)
2960+
return;
2961+
settings.changes.forEach((change) => {
2962+
if (change.action === "delete") {
2963+
localStorage.removeItem(change.key);
2964+
}
2965+
});
2966+
}
29512967
/**
29522968
* Support for proxying `window.webkit.messageHandlers`
29532969
*/

build/android/contentScope.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7899,6 +7899,10 @@
78997899
if (this.getFeatureSettingEnabled('screenLock')) {
79007900
this.screenLockFix();
79017901
}
7902+
7903+
if (this.getFeatureSettingEnabled('modifyLocalStorage')) {
7904+
this.modifyLocalStorage();
7905+
}
79027906
}
79037907

79047908
/** Shim Web Share API in Android WebView */
@@ -8313,6 +8317,22 @@
83138317
}
83148318
}
83158319

8320+
/**
8321+
* Support for modifying localStorage entries
8322+
*/
8323+
modifyLocalStorage () {
8324+
/** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */
8325+
const settings = this.getFeatureSetting('modifyLocalStorage');
8326+
8327+
if (!settings || !settings.changes) return
8328+
8329+
settings.changes.forEach((change) => {
8330+
if (change.action === 'delete') {
8331+
localStorage.removeItem(change.key);
8332+
}
8333+
});
8334+
}
8335+
83168336
/**
83178337
* Support for proxying `window.webkit.messageHandlers`
83188338
*/

build/contentScope.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14606,6 +14606,10 @@
1460614606
if (this.getFeatureSettingEnabled('screenLock')) {
1460714607
this.screenLockFix();
1460814608
}
14609+
14610+
if (this.getFeatureSettingEnabled('modifyLocalStorage')) {
14611+
this.modifyLocalStorage();
14612+
}
1460914613
}
1461014614

1461114615
/** Shim Web Share API in Android WebView */
@@ -15020,6 +15024,22 @@
1502015024
}
1502115025
}
1502215026

15027+
/**
15028+
* Support for modifying localStorage entries
15029+
*/
15030+
modifyLocalStorage () {
15031+
/** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */
15032+
const settings = this.getFeatureSetting('modifyLocalStorage');
15033+
15034+
if (!settings || !settings.changes) return
15035+
15036+
settings.changes.forEach((change) => {
15037+
if (change.action === 'delete') {
15038+
localStorage.removeItem(change.key);
15039+
}
15040+
});
15041+
}
15042+
1502315043
/**
1502415044
* Support for proxying `window.webkit.messageHandlers`
1502515045
*/

build/integration/contentScope.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14606,6 +14606,10 @@
1460614606
if (this.getFeatureSettingEnabled('screenLock')) {
1460714607
this.screenLockFix();
1460814608
}
14609+
14610+
if (this.getFeatureSettingEnabled('modifyLocalStorage')) {
14611+
this.modifyLocalStorage();
14612+
}
1460914613
}
1461014614

1461114615
/** Shim Web Share API in Android WebView */
@@ -15020,6 +15024,22 @@
1502015024
}
1502115025
}
1502215026

15027+
/**
15028+
* Support for modifying localStorage entries
15029+
*/
15030+
modifyLocalStorage () {
15031+
/** @type {import('../types//webcompat-settings').WebCompatSettings['modifyLocalStorage']} */
15032+
const settings = this.getFeatureSetting('modifyLocalStorage');
15033+
15034+
if (!settings || !settings.changes) return
15035+
15036+
settings.changes.forEach((change) => {
15037+
if (change.action === 'delete') {
15038+
localStorage.removeItem(change.key);
15039+
}
15040+
});
15041+
}
15042+
1502315043
/**
1502415044
* Support for proxying `window.webkit.messageHandlers`
1502515045
*/

integration-test/playwright/webcompat.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test('web compat', async ({ page }, testInfo) => {
3030
})
3131

3232
export class WebcompatSpec {
33-
htmlPage = '/webcompat/index.html'
33+
htmlPage = '/webcompat/pages/message-handlers.html'
3434
config = './integration-test/test-pages/webcompat/config/message-handlers.json'
3535

3636
/**

integration-test/test-pages.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,11 @@ describe('Test integration pages', () => {
9494
`${process.cwd()}/integration-test/test-pages/webcompat/config/shims.json`
9595
)
9696
})
97+
98+
it('Properly modifies localStorage entries', async () => {
99+
await testPage(
100+
'webcompat/pages/modify-localstorage.html',
101+
`${process.cwd()}/integration-test/test-pages/webcompat/config/modify-localstorage.json`
102+
)
103+
})
97104
})
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"unprotectedTemporary": [],
3+
"features": {
4+
"webCompat": {
5+
"exceptions": [],
6+
"state": "enabled",
7+
"settings": {
8+
"windowSizing": "enabled",
9+
"navigatorCredentials": "enabled",
10+
"safariObject": "enabled",
11+
"modifyLocalStorage": {
12+
"state": "enabled",
13+
"changes": []
14+
},
15+
"domains": [
16+
{
17+
"domain": ["localhost", "privacy-test-pages.site"],
18+
"patchSettings": [
19+
{
20+
"op": "add",
21+
"path": "/modifyLocalStorage/changes/-",
22+
"value": {
23+
"key": "keyToBeDeleted",
24+
"action": "delete"
25+
}
26+
},
27+
{
28+
"op": "add",
29+
"path": "/modifyLocalStorage/changes/-",
30+
"value": {
31+
"key": "nonexistentKey",
32+
"action": "delete"
33+
}
34+
}
35+
]
36+
}
37+
]
38+
}
39+
}
40+
}
41+
}

integration-test/test-pages/webcompat/index.html

Lines changed: 7 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -3,60 +3,15 @@
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width">
6-
<title>Webcompat</title>
6+
<title>Webcompat Interventions</title>
77
<link rel="stylesheet" href="../shared/style.css">
88
</head>
99
<body>
10-
<script src="../shared/utils.js"></script>
11-
12-
<p>Webcompat, Message Handlers</p>
13-
<script>
14-
test('webkit.messageHandlers - polyfill prevents throw', async () => {
15-
let notThrown = true;
16-
try {
17-
window.webkit.messageHandlers.anythingatall.postMessage({})
18-
} catch (e) {
19-
notThrown = false
20-
}
21-
return [
22-
{ name: 'Error not thrown polyfil', result: notThrown, expected: true },
23-
]
24-
})
25-
test('webkit.messageHandlers - undefined should throw', async () => {
26-
let thrown = false;
27-
try {
28-
window.webkit.messageHandlers.jsHandler.postMessage({})
29-
} catch (e) {
30-
thrown = true
31-
}
32-
return [
33-
{ name: 'undefined handler should throw', result: thrown, expected: true },
34-
]
35-
})
36-
test('webkit.messageHandlers - reflected message', async () => {
37-
window.webkit.messageHandlers.printHandler = {
38-
postMessage() {
39-
return { test: "test" }
40-
}
41-
}
42-
43-
const value = window.webkit.messageHandlers.printHandler.postMessage({});
44-
45-
return [
46-
{ name: 'reflected message should pass through', result: value.test, expected: 'test' },
47-
]
48-
})
49-
renderResults();
50-
51-
async function captureError(fn) {
52-
try {
53-
// ensure Promise.reject is captured
54-
return fn().catch(e => e)
55-
} catch (e) {
56-
return e
57-
}
58-
}
59-
60-
</script>
10+
<p><a href="../../index.html">[Home]</a></p>
11+
<ul>
12+
<li><a href="./pages/message-handlers.html">Message Handlers</a> - <a href="./config/message-handlers.json">Config</a></li>
13+
<li><a href="./pages/shims.html">Shims</a> - <a href="./config/shims.json">Config</a></li>
14+
<li><a href="./pages/modify-localstorage.html">Modify localStorage</a> - <a href="./config/modify-localstorage.json">Config</a></li>
15+
</ul>
6116
</body>
6217
</html>
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Webcompat</title>
7+
<link rel="stylesheet" href="../../shared/style.css">
8+
</head>
9+
<body>
10+
<script src="../../shared/utils.js"></script>
11+
12+
<p>Webcompat, Message Handlers</p>
13+
<script>
14+
test('webkit.messageHandlers - polyfill prevents throw', async () => {
15+
let notThrown = true;
16+
try {
17+
window.webkit.messageHandlers.anythingatall.postMessage({})
18+
} catch (e) {
19+
notThrown = false
20+
}
21+
return [
22+
{ name: 'Error not thrown polyfil', result: notThrown, expected: true },
23+
]
24+
})
25+
test('webkit.messageHandlers - undefined should throw', async () => {
26+
let thrown = false;
27+
try {
28+
window.webkit.messageHandlers.jsHandler.postMessage({})
29+
} catch (e) {
30+
thrown = true
31+
}
32+
return [
33+
{ name: 'undefined handler should throw', result: thrown, expected: true },
34+
]
35+
})
36+
test('webkit.messageHandlers - reflected message', async () => {
37+
window.webkit.messageHandlers.printHandler = {
38+
postMessage() {
39+
return { test: "test" }
40+
}
41+
}
42+
43+
const value = window.webkit.messageHandlers.printHandler.postMessage({});
44+
45+
return [
46+
{ name: 'reflected message should pass through', result: value.test, expected: 'test' },
47+
]
48+
})
49+
renderResults();
50+
51+
async function captureError(fn) {
52+
try {
53+
// ensure Promise.reject is captured
54+
return fn().catch(e => e)
55+
} catch (e) {
56+
return e
57+
}
58+
}
59+
60+
</script>
61+
</body>
62+
</html>
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta name="viewport" content="width=device-width">
6+
<title>Modify localStorage</title>
7+
<link rel="stylesheet" href="../../shared/style.css">
8+
<script>
9+
window.localStorage.setItem('keyToBeDeleted', 'valueToBeDeleted')
10+
window.localStorage.setItem('otherKey', 'valueToRemain')
11+
</script>
12+
</head>
13+
<body>
14+
<script src="../../shared/utils.js"></script>
15+
<p><a href="../index.html">[WebCompat]</a></p>
16+
17+
<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>
18+
19+
<script>
20+
// eslint-disable-next-line no-undef
21+
test('Only specified localStorage entry should be removed', async () => {
22+
const specifiedKey = window.localStorage.getItem('keyToBeDeleted')
23+
const nonexistentKey = window.localStorage.getItem('nonexistentKey')
24+
const otherKey = window.localStorage.getItem('otherKey')
25+
26+
return [
27+
{ name: 'specified localStorage entry deleted', result: specifiedKey, expected: null },
28+
{ name: 'specified localStorage entry that is not present on page load', result: nonexistentKey, expected: null },
29+
{ name: 'other localStorage entry untouched', result: otherKey, expected: 'valueToRemain' }
30+
];
31+
});
32+
33+
// eslint-disable-next-line no-undef
34+
renderResults();
35+
</script>
36+
</body>
37+
</html>

0 commit comments

Comments
 (0)