-
Notifications
You must be signed in to change notification settings - Fork 879
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
Add support for checking de_amp_enabled user pref in cosmetic js filter #12923
Conversation
@@ -41,12 +41,12 @@ const char kObservingScriptletEntryPoint[] = | |||
|
|||
const char kScriptletInitScript[] = | |||
R"((function() { | |||
let text = %s; | |||
let text = 'let deAmpEnabled = %s;\n' + %s; |
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 is a bit ugly, but we can't just add let deAmpEnabled = %s;
before this line because deAmpEnabled
will then not be visible to the scriptlet when the script is actually executed as part of appendChild
on line 50.
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.
do we need
let text = '(function() {\nlet deAmpEnabled = %s;\n' + %s + '})()';
?
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.
In the current form, deAmpEnabled
just becomes part of the scriplet and will go out of scope once the scriptlet is done executing, right? Which is what we want.
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.
The actual scriptlet is that second %s
above. text
becomes essentially <script>text</script>
, so I think the deAmpEnabled
needs its own IIF scope as well.
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.
In other words, the code you have right now will currently inject something like this:
<script>
let deAmpEnabled = true;
try {
(function() {
// scriptlet 1
})()
} catch (e) {}
try {
(function() {
// scriptlet 2
})()
} catch (e) {}
</script>
which makes deAmpEnabled
visible to other scripts, so we'd want something like this instead:
<script>
(function() {
let deAmpEnabled = true;
try {
(function() {
// scriptlet 1
})()
} catch (e) {}
try {
(function() {
// scriptlet 2
})()
} catch (e) {}
})()
</script>
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.
Ah that's right, good catch. Updated
78eec0d
to
1d50dc8
Compare
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.
Would be nice to have a browsertest - you can see an example of injecting a custom scriptlet in a test using AdBlockServiceTest.CosmeticFilteringWindowScriptlet
.
Otherwise it looks good to me, but @bridiver should probably take a look as well
59c972e
to
14ec86c
Compare
14ec86c
to
9facd25
Compare
@@ -1,4 +1,5 @@ | |||
include_rules = [ | |||
"+brave/common", |
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 isn't allowed, it's a layering violation. Instead of passing in GetDynamicParamsCallback
you can wrap it in a closure that just returns the value of de_amp_enabled
@@ -102,7 +109,11 @@ void BraveRendererUpdater::UpdateRenderer( | |||
default_wallet == | |||
brave_wallet::mojom::DefaultWallet::BraveWalletPreferExtension; | |||
|
|||
PrefService* pref_service = profile_->GetPrefs(); | |||
bool de_amp_enabled = pref_service->GetBoolean(de_amp::kDeAmpPrefEnabled); |
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 make this the combined value of the pref plus the feature? And also create a utility method in the component that gives the result of both given the PrefService and also use that in DeAmpThrottle? Easy to make a mistake otherwise when checking.
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.
But then this would rely on components/de_amp/browser. I thought we didn't want that, and hence the suggestion to just check using the PrefService.
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.
no, it would rely on components/de_amp/common :)
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.
sorry, actually this code wouldn't access it at all, the combined value would be sent to the renderer
Verification PASSED on
Went through the STR/Cases outlined via #12923 (comment).
|
Example |
Example |
Example |
Example |
---|---|---|---|
de-AMP Enabled
- ensured that
Auto-redirect AMP pages
was enabled viabrave://settings/privacy
- loaded
https://www.google.com
and then searched forTop Stories
- inspected the first article via
DevTools
and ensured thatjsaction
attribute wasn't appeared in the anchor link - clicked on the link and ensured that the de-AMP version of the website/news article was being loaded
Example |
Example |
Example |
---|---|---|
Quick note: I also tried https://www.google.ca
& https://www.google.co.uk
Brave | 1.40.2 Chromium: 101.0.4951.41 (Official Build) nightly (64-bit)
-- | --
Revision | 93c720db8323b3ec10d056025ab95c23a31997c9-refs/branch-heads/4951@{#904}
OS | Windows 11 Version 21H2 (Build 22000.613)
Went through the STR/Cases outlined via #12923 (comment).
de-AMP Disabled
- ensured that
Auto-redirect AMP pages
was disabled viabrave://settings/privacy
- loaded
https://www.google.com
and then searched forTop Stories
- inspected the first article via
DevTools
and ensured thatjsaction
attribute appeared in the anchor link - clicked on the link and ensured that the AMP version of the website/news article was being loaded
- Example -->
https://www.google.com/amp/s/www.cbc.ca/amp/1.6425708
- Example -->
Example |
Example |
Example |
---|---|---|
de-AMP Enabled
- ensured that
Auto-redirect AMP pages
was enabled viabrave://settings/privacy
- loaded
https://www.google.com
and then searched forTop Stories
- inspected the first article via
DevTools
and ensured thatjsaction
attribute wasn't appeared in the anchor link - clicked on the link and ensured that the de-AMP version of the website/news article was being loaded
Example |
Example |
Example |
---|---|---|
Resolves brave/brave-browser#22228
This PR adds support for a new scriptlet that will remove
jsaction
attribute from anchor tags on SERPs, if DeAmp flag and pref is enabled. After this PR we will merge in brave/adblock-resources#63 (for the de-amp resource) and brave/adblock-lists#818 (for the rule)Submitter Checklist:
QA/Yes
orQA/No
;release-notes/include
orrelease-notes/exclude
;OS/...
) to the associated issuenpm run test -- brave_browser_tests
,npm run test -- brave_unit_tests
,npm run lint
,npm run gn_check
,npm run tslint
git rebase master
(if needed)Reviewer Checklist:
gn
After-merge Checklist:
changes has landed on
Test Plan:
Given that the adblock component containing the DeAMP scriplet is already deployed, it's a lot easier to just verify that the scriplet is working as intended which it would only do if this PR is properly working.
To manually test:
These steps can be repeated for google.co.uk, google.co.in, etc. - they should work on all google search TLDs.