Skip to content

Commit 8e286cf

Browse files
Release build 4.14.0 [ci release]
1 parent 9a07d09 commit 8e286cf

File tree

17 files changed

+243
-148
lines changed

17 files changed

+243
-148
lines changed

Sources/ContentScopeScripts/dist/contentScope.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,6 @@
548548
allowlisted,
549549
enabledFeatures
550550
});
551-
// TODO
552-
output.cookie = {};
553551

554552
// Copy feature settings from remote config to preferences object
555553
output.featureSettings = parseFeatureSettings(data, enabledFeatures);
@@ -1755,7 +1753,9 @@
17551753

17561754
// Delay removal of the custom element so if the script calls removeChild it will still be in the DOM and not throw.
17571755
setTimeout(() => {
1758-
this.remove();
1756+
try {
1757+
super.remove();
1758+
} catch {}
17591759
}, elementRemovalTimeout);
17601760
}
17611761

@@ -1877,7 +1877,12 @@
18771877
}
18781878

18791879
remove () {
1880-
return this._callMethod('remove')
1880+
let returnVal;
1881+
try {
1882+
returnVal = this._callMethod('remove');
1883+
super.remove();
1884+
} catch {}
1885+
return returnVal
18811886
}
18821887

18831888
// @ts-expect-error TS node return here

build/android/contentScope.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,6 @@
548548
allowlisted,
549549
enabledFeatures
550550
});
551-
// TODO
552-
output.cookie = {};
553551

554552
// Copy feature settings from remote config to preferences object
555553
output.featureSettings = parseFeatureSettings(data, enabledFeatures);
@@ -1755,7 +1753,9 @@
17551753

17561754
// Delay removal of the custom element so if the script calls removeChild it will still be in the DOM and not throw.
17571755
setTimeout(() => {
1758-
this.remove();
1756+
try {
1757+
super.remove();
1758+
} catch {}
17591759
}, elementRemovalTimeout);
17601760
}
17611761

@@ -1877,7 +1877,12 @@
18771877
}
18781878

18791879
remove () {
1880-
return this._callMethod('remove')
1880+
let returnVal;
1881+
try {
1882+
returnVal = this._callMethod('remove');
1883+
super.remove();
1884+
} catch {}
1885+
return returnVal
18811886
}
18821887

18831888
// @ts-expect-error TS node return here

build/chrome-mv3/inject.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,9 @@
17101710

17111711
// Delay removal of the custom element so if the script calls removeChild it will still be in the DOM and not throw.
17121712
setTimeout(() => {
1713-
this.remove();
1713+
try {
1714+
super.remove();
1715+
} catch {}
17141716
}, elementRemovalTimeout);
17151717
}
17161718

@@ -1832,7 +1834,12 @@
18321834
}
18331835

18341836
remove () {
1835-
return this._callMethod('remove')
1837+
let returnVal;
1838+
try {
1839+
returnVal = this._callMethod('remove');
1840+
super.remove();
1841+
} catch {}
1842+
return returnVal
18361843
}
18371844

18381845
// @ts-expect-error TS node return here

build/chrome/inject.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/contentScope.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,9 @@
16841684

16851685
// Delay removal of the custom element so if the script calls removeChild it will still be in the DOM and not throw.
16861686
setTimeout(() => {
1687-
this.remove();
1687+
try {
1688+
super.remove();
1689+
} catch {}
16881690
}, elementRemovalTimeout);
16891691
}
16901692

@@ -1806,7 +1808,12 @@
18061808
}
18071809

18081810
remove () {
1809-
return this._callMethod('remove')
1811+
let returnVal;
1812+
try {
1813+
returnVal = this._callMethod('remove');
1814+
super.remove();
1815+
} catch {}
1816+
return returnVal
18101817
}
18111818

18121819
// @ts-expect-error TS node return here

build/firefox/inject.js

Lines changed: 10 additions & 3 deletions
Large diffs are not rendered by default.

build/integration/contentScope.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,9 @@
16841684

16851685
// Delay removal of the custom element so if the script calls removeChild it will still be in the DOM and not throw.
16861686
setTimeout(() => {
1687-
this.remove();
1687+
try {
1688+
super.remove();
1689+
} catch {}
16881690
}, elementRemovalTimeout);
16891691
}
16901692

@@ -1806,7 +1808,12 @@
18061808
}
18071809

18081810
remove () {
1809-
return this._callMethod('remove')
1811+
let returnVal;
1812+
try {
1813+
returnVal = this._callMethod('remove');
1814+
super.remove();
1815+
} catch {}
1816+
return returnVal
18101817
}
18111818

18121819
// @ts-expect-error TS node return here

build/windows/contentScope.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,6 @@
548548
allowlisted,
549549
enabledFeatures
550550
});
551-
// TODO
552-
output.cookie = {};
553551

554552
// Copy feature settings from remote config to preferences object
555553
output.featureSettings = parseFeatureSettings(data, enabledFeatures);
@@ -1755,7 +1753,9 @@
17551753

17561754
// Delay removal of the custom element so if the script calls removeChild it will still be in the DOM and not throw.
17571755
setTimeout(() => {
1758-
this.remove();
1756+
try {
1757+
super.remove();
1758+
} catch {}
17591759
}, elementRemovalTimeout);
17601760
}
17611761

@@ -1877,7 +1877,12 @@
18771877
}
18781878

18791879
remove () {
1880-
return this._callMethod('remove')
1880+
let returnVal;
1881+
try {
1882+
returnVal = this._callMethod('remove');
1883+
super.remove();
1884+
} catch {}
1885+
return returnVal
18811886
}
18821887

18831888
// @ts-expect-error TS node return here

integration-test/test-pages/runtime-checks/config/basic-run.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"matchAllDomains": "enabled",
99
"matchAllStackDomains": "enabled",
1010
"overloadInstanceOf": "enabled",
11-
"elementRemovalTimeout": 1000,
11+
"elementRemovalTimeout": 100,
1212
"injectGlobalStyles": "enabled",
1313
"domains": [
1414
],

integration-test/test-pages/runtime-checks/pages/basic-run.html

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,51 @@
4141
];
4242
});
4343

44+
test('Script removal', async () => {
45+
window.scripty1Ran = false;
46+
const scriptElement = document.createElement('script');
47+
scriptElement.innerText = 'window.scripty1Ran = true';
48+
scriptElement.id = 'scriptyRemove';
49+
scriptElement.setAttribute('type', 'application/evilscript');
50+
51+
const section = document.createElement('section');
52+
section.innerHTML = '<a id="anchorEl">hello</a><div id="me">world</div>';
53+
document.body.appendChild(section);
54+
const anchorEl = document.querySelector('#anchorEl');
55+
anchorEl.insertAdjacentElement('afterend', scriptElement);
56+
57+
const hadInspectorNode = scriptElement === document.querySelector('ddg-runtime-checks:last-of-type');
58+
// Continue to modify the script element after it has been added to the DOM
59+
scriptElement.madeUpProp = 'val';
60+
const childCount = section.children.length;
61+
scriptElement.remove();
62+
const childCountAfter = section.children.length;
63+
const instanceofResult = scriptElement instanceof HTMLScriptElement;
64+
const scripty = document.querySelector('#scriptyRemove');
65+
await new Promise(resolve => setTimeout(resolve, 300));
66+
67+
const htmlCache = section.innerHTML;
68+
69+
const scriptElement2 = document.createElement('script');
70+
scriptElement2.innerText = 'console.log(1)';
71+
scriptElement2.id = 'scripty2Remove';
72+
scriptElement2.setAttribute('type', 'application/javascript');
73+
anchorEl.insertAdjacentElement('afterend', scriptElement2);
74+
const childCountAfter2 = section.children.length;
75+
await new Promise(resolve => setTimeout(resolve, 300));
76+
const childCountAfter3 = section.children.length;
77+
78+
return [
79+
{ name: 'instanceof matches HTMLScriptElement', result: instanceofResult, expected: true },
80+
{ name: 'script ran', result: window.scripty1Ran, expected: false },
81+
{ name: 'expected children', result: childCount, expected: 4 },
82+
{ name: 'expected children after remove', result: childCountAfter, expected: 2 },
83+
{ name: 'expected children after remove2', result: childCountAfter2, expected: 4 },
84+
{ name: 'expected children after remove3', result: childCountAfter3, expected: 3 },
85+
{ name: 'expected HTML content', result: htmlCache, expected: `<a id="anchorEl">hello</a><div id="me">world</div>` }
86+
];
87+
});
88+
4489
test('Script that should execute', async () => {
4590
window.scripty2Ran = false;
4691
const scriptElement = document.createElement('script');

0 commit comments

Comments
 (0)