-
Notifications
You must be signed in to change notification settings - Fork 20
Conversation
@cezaraugusto @NejcZdovc @bbondy @jonathansampson @petemill ready for review 😄 |
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.
comments left. noticed you added the cosmeticFilterEventsTest.ts
but file is empty. let's remove it and add in a follow-up when we start writing tests for it
result.list[hostname] !== null && | ||
result.list[hostname].length !== 0) { | ||
result.list[hostname].map((rule: string) => { | ||
console.log('applying rule', rule) |
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.
ok we can remove this
console.log('report broken page sub-context menu created') | ||
}) | ||
|
||
// log storage |
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.
let's remove this code block as we don't require it
case 'addBlockElement': | ||
{ | ||
console.log(rule) | ||
console.log('blockElement clicked in cosmeticFilterEvents.ts', rule.host, rule.selector) |
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.
ditto
} | ||
case 'resetSiteFilterSettings': | ||
{ | ||
console.log('dispatching cosmeticFilterAction to cosmeticFilterReducer from events') |
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.
ditto
cosmeticFilterActions.siteCosmeticFilterRemoved(rule.host) | ||
break | ||
} | ||
case 'reportBrokenPage': |
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.
not sure if this is needed we are only logging the result inside the action handler
@@ -0,0 +1,41 @@ | |||
// import { Tab } from '../../types/state/shieldsPannelState' | |||
// import { getShieldSettingsForTabData, getTabData } from './shieldsAPI' |
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.
let's remove these imports as we don't need them
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.
done
|
||
export const addSiteCosmeticFilter = async (origin: string, cssfilter: string) => { | ||
chrome.storage.local.get('list', (result = {}) => { | ||
let l = Object.assign({}, result.list) |
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.
nit: can we have a more descriptive variable name here?
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.
are you referring to list
, l
, result
, or any combination of those 3?
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.
ya I mean the l
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.
fix'd
|
||
export const removeSiteFilter = (origin: string) => { | ||
chrome.storage.local.get('list', (result = {}) => { | ||
let l = Object.assign({}, result.list) |
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.
same as above
// import tabActions from '../actions/tabActions' | ||
|
||
// import * as cosmeticFilterAPI from '../api/cosmeticFilterAPI' | ||
// background |
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.
let's remove the imports above as we don't use them
|
||
// add context menu | ||
chrome.runtime.onInstalled.addListener(function () { | ||
|
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.
nit: can we remove this empty line? standardjs would complain but I'm not sure why it doesn't
|
||
// content script listener for right click DOM selection event | ||
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => { | ||
rule.host = msg.baseURI |
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.
should the rule host include port number?
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.
I propose filing that as a separate issue and keeping it as-is for now as there are several other features that have higher priority (mutation observer, UI > port for now).
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.
Great job getting this all setup and working with typescript and integrated in to the extension.
I know that we're going to work on some better UI than a simple text input prompt, but until we have that I think we can make a slight improvement here: I find the context menu titles a confusing UI since the first refers to Blocking an 'ad' but the others refer to filtering 'sites'. Secondly, the UI that pops up asks for a 'rule' but gives no explanation as to what to type.
I propose the following new strings for these menu item titles whilst the UI is in this state:
- Block element vis CSS rule
- Clear CSS rules for this site
- Clear CSS rules for all sites
Alternatively, instead of CSS Rule
we could use Selector
, since that's what we're asking for (we create the display: none
rule internally, the user does not provide it).
I've left more specific code comments inline.
We're also going to need to squash this down to 1 or 2 commits since this adds 1 feature. However I did notice at least 1 thing that should remain a separate commit / PR that this can rebase on.
@@ -0,0 +1,36 @@ | |||
export const addSiteCosmeticFilter = async (origin: string, cssfilter: string) => { | |||
chrome.storage.local.get('list', (result = {}) => { | |||
let l = Object.assign({}, result.list) |
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.
A more descriptive variable name here could be storeData
instead of result
and storeList
instead of l
.
parentId: 'brave', | ||
contexts: ['all'] | ||
}, () => { | ||
console.log('block custom ad sub-context menu created') |
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.
We shouldn't have all the menu items automatically log for all users. If we want to keep it in, please put behind a debug flag, even if it's simply a const at the top of the module.
break | ||
} | ||
default: { | ||
console.log('invalid context menu option - cosmeticFilterEvents.ts') |
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.
If you're going to log an invalid option then put what the invalid option was as part of the log string, e.g: [cosmeticFilterEvents] invalid context menu option: ${info.menuItemId}
} from '../api/cosmeticFilterAPI' | ||
|
||
const focusedWindowChanged = (state: State, windowId: number): State => { | ||
if (windowId !== -1) { |
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.
Might be nicer to return early here, instead of multiple levels of nesting conditionals, e.g.
if (windowId === -1) {
console.warn(...)
return state
}
...
setAllowBraveShields(tabData.origin, action.setting) | ||
.then(() => { | ||
reloadTab(tabId, true).catch(() => { | ||
console.error('Tab reload was not successful') |
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.
Shouldn't we log the error too? .catch(e => console.error('Tab reload was not successful', e))
app/content.js
Outdated
selector: selector, | ||
baseURI: baseURI | ||
}, ((response) => { | ||
console.log('content.js - response received: ', response) |
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.
Should remove console.log by default
const filter = '#cssFilter' | ||
|
||
let sampleValue: any | ||
console.log(sampleValue) |
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.
Well, that error is correct: you are only declaring or assigning the variable, but never reading it, so it doesn't seem necessary. Why do you need to assign it inside callsFake(
via sampleValue = value
if you're never using that value in any test, or in the stub for chrome.storage.local.get
? Looks like you can just use empty functions inside callsFake
, just have an empty stub, or use that value in the stub for get
(only if it needs it).
@@ -374,8 +374,8 @@ describe('Shields API', () => { | |||
it('resolves the returned promise', function (cb) { | |||
this.p | |||
.then(function () { |
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.
Don't need to create a function to call a function, can just pass in cb
as the argument. Alternatively, you can just return the whole promise instead of using a callback.
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.
I only fixed the typo, would you prefer if I changed all the shieldAPITests to conform to passing in cb
instead?
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.
ok, no that's ok - thanks anyway @Snuupy
.gitignore
Outdated
@@ -64,3 +64,7 @@ build/ | |||
|
|||
# Ignore python compiled files | |||
*.pyc | |||
|
|||
# VSCode config |
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 should really be done in a separate PR, or at least a separate commit once all of these commits are squashed.
|
||
// block ad child menu | ||
chrome.contextMenus.create({ | ||
title: 'Block ad', |
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.
I have an opinion on these context menu titles that I'll describe in the overall review comment
@@ -29,6 +29,7 @@ const focusedWindowChanged = (state: State, windowId: number): State => { | |||
requestShieldPanelData(shieldsPanelState.getActiveTabId(state)) | |||
} else { | |||
console.warn('no tab id so cannot request shield data from window focus change!') | |||
return state |
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.
I don't think you need the extra return state
here. The time to use that pattern is if you return early because of some condition, e.g.
if (condition) {
return state
}
...continue processing...
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.
done
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.
Thanks @Snuupy for a great start to the feature, and attention to all the review comments.
From a code / functionality POV, this lgtm and can be merged 👍
However, I did just notice that we're pointing to a github repo (although a Brave one) for a new package.json dependency - we may want to put this on npm as without that we won't benefit from semver or caching.
There aren't clear instructions in how to merge brave-extension and brave-browser. Is this in the dev builds of brave browser now? |
@dri94 Thanks for following up on the feature!
Your observation is correct. The way it works is the As you can see from line 8 in the
If you look at the merge/commit log in brave-extension, you'll see that my commit (d192d23) is before the one referenced (2ea4ff3) which means by default the build process will include the cosmetic filtering feature. Because of the way the build process works, I also had to update the I know this is not exactly intuitive, but I hope this clears things up.
Yes. |
At the point where I can take code feedback.
Testing notes: this does not work for any elements that are in-line. It will only work when we do a
.removeElement()
with theMutationObserver
implementationDone:
remove from DOM)To do for this PR:
.vscode/settings.json
,build-dev.js
console.log
statementsprod.config.js
to original versionFor next PR(s):