Skip to content

Commit 655eddb

Browse files
committed
Align content_cosmetic_ios.js with changes to SelectorsPollerScript.js:
- Generic cosmetic filter list rules are not applied on some sites (brave/brave-browser#42471). - Local frames fix (brave/brave-browser#40649). - Use secure $.windowOrigin (brave/brave-browser#42539). - Fix pulse on some subreddits with Shields and Night Mode enabled on iOS (brave/brave-browser#43096)
1 parent 75b0687 commit 655eddb

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

components/cosmetic_filters/resources/data/content_cosmetic_ios.js

+18-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { applyCompiledSelector, compileProceduralSelector } from './procedural_f
1515
return $.postNativeMessage(messageHandler, {
1616
"securityToken": SECURITY_TOKEN,
1717
"data": {
18-
sourceURL: window.location.href,
18+
windowOrigin: $.windowOrigin,
1919
ids: ids,
2020
classes: classes
2121
}
@@ -32,7 +32,7 @@ import { applyCompiledSelector, compileProceduralSelector } from './procedural_f
3232
return $.postNativeMessage(partinessMessageHandler, {
3333
"securityToken": SECURITY_TOKEN,
3434
"data": {
35-
sourceURL: window.location.href,
35+
windowOrigin: $.windowOrigin,
3636
urls: urls,
3737
}
3838
})
@@ -201,8 +201,11 @@ import { applyCompiledSelector, compileProceduralSelector } from './procedural_f
201201
* @returns True or false indicating if anything was extracted
202202
*/
203203
const extractIDSelectorIfNeeded = (element) => {
204-
const id = element.id
204+
const id = element.getAttribute('id')
205205
if (!id) { return false }
206+
if (typeof id !== 'string' && !(id instanceof String)) {
207+
return false
208+
}
206209
const selector = `#${id}`
207210
if (!CC.allSelectors.has(selector)) {
208211
CC.allSelectors.add(selector)
@@ -1012,12 +1015,24 @@ import { applyCompiledSelector, compileProceduralSelector } from './procedural_f
10121015
styleElm.setAttribute('type', 'text/css')
10131016
targetElm.appendChild(styleElm)
10141017
CC.cosmeticStyleSheet = styleElm
1018+
// The previous `nextElementSibling` we moved our stylesheet below
1019+
var prevNextElementSibling = null;
10151020

10161021
// Start a timer that moves the stylesheet down
10171022
window.setInterval(() => {
10181023
if (styleElm.nextElementSibling === null || styleElm.parentElement !== targetElm) {
10191024
return
10201025
}
1026+
if (styleElm.nextElementSibling !== null) {
1027+
// if we already moved below this element
1028+
if (prevNextElementSibling === styleElm.nextElementSibling) {
1029+
// Avoid a loop where we are repeatedly swapping places with another
1030+
// element. This can happen with `darkreader` (night mode) for
1031+
// example and cause unwanted animations to repeat.
1032+
return
1033+
}
1034+
prevNextElementSibling = styleElm.nextElementSibling;
1035+
}
10211036
moveStyle()
10221037
}, 1000)
10231038
}

0 commit comments

Comments
 (0)