Skip to content
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

Resolve extension startup errors #802

Closed
wants to merge 3 commits into from

Conversation

jonathanKingston
Copy link
Collaborator

@jonathanKingston jonathanKingston commented Aug 12, 2021

Reviewer:

Description:

Fixes issue with tracker methods that check the list without knowing if the list has loaded.

Errors such as:

  • TypeError: Cannot read property 'duckduckgo.com' of undefined
  • tried to detect trackers before rules were loaded

This makes all tracker checks fail open which I think is essentially what we are doing currently whilst also breaking other code.

This also handles missing tab data for getArgumentsObject calls by creating a tab given the sender info. This only happens on extension startup time:
image

This also handles getSettings calls not returning as they've not loaded yet:
image

Steps to test this PR:

  1. Load the extension
  2. Check the extension console for these messages

Automated tests:

  • Unit tests
  • Integration tests
Reviewer Checklist:
  • Ensure the PR solves the problem
  • Review every line of code
  • Ensure the PR does no harm by testing the changes thoroughly
  • Get help if you're uncomfortable with any of the above!
  • Determine if there are any quick wins that improve the implementation
PR Author Checklist:
  • Get advice or leverage existing code
  • Agree on technical approach with reviewer (if the changes are nuanced)
  • Ensure that there is a testing strategy (and documented non-automated tests)
  • Ensure there is a documented monitoring strategy (if necessary)
  • Consider systems implications

@jonathanKingston jonathanKingston force-pushed the ignore-tracker-checks-until-loaded branch from ee66cdc to 9c064d8 Compare August 12, 2021 12:55
@jonathanKingston jonathanKingston changed the title Wait until tracker list is loaded before making checks Resolve extension startup errors Aug 12, 2021
@jonathanKingston jonathanKingston force-pushed the ignore-tracker-checks-until-loaded branch from 9c064d8 to eb4672f Compare August 12, 2021 13:10
@jonathanKingston jonathanKingston force-pushed the ignore-tracker-checks-until-loaded branch from eb4672f to dadf073 Compare August 12, 2021 13:20
Copy link
Collaborator

@sammacbeth sammacbeth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this wrapping and guarding of these functions is the correct approach. As a consumer of that API I don't know if a result is correct, or just because loading isn't finish. We should instead use a hasTrackerListLoaded on the features, e.g. in the webRequest listeners return early when the list isn't loaded yet.

@@ -629,7 +629,7 @@ chrome.runtime.onMessage.addListener((req, sender, res) => {
let sessionKey = getHash()

function getArgumentsObject (tabId, sender, documentUrl) {
const tab = tabManager.get({ tabId })
const tab = tabManager.createOrUpdateTab(tabId, sender.tab)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write down which cases this is for? Is there a case when a content-script message comes before chrome.tabs.onUpdated fires? Or is this just for the case when the extension is loaded/reload and content-scripts trigger for existing tabs (in which case we could do chrome.tabs.query on startup)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or is this just for the case when the extension is loaded/reload and content-scripts trigger for existing tabs (in which case we could do chrome.tabs.query on startup)?

This is the case I was testing. I will check.

Comment on lines -96 to +95
let tracker = trackers.getTrackerData(requestData.url, thisTab.site.url, requestData)
let tracker = trackerutils.getTrackerData(requestData.url, thisTab.site.url, requestData)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't we make this change upstream, or extend from Trackers in trackers.es6.js? I think there is a lot of cases where we are using trackers directly, would we have to update every one to trackerutils?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, I was trying not to modify this code given the short timeline however I think we should as you mention do it upstream and propagate it back.

@jonathanKingston
Copy link
Collaborator Author

As a consumer of that API I don't know if a result is correct, or just because loading isn't finish. We should instead use a hasTrackerListLoaded on the features

Arguably the consumer here is in control of tracking when they've pushed data in. However I'm happy to update the producer to fail gracefully and expect the consumer to check a method that they expose.

I'm going to close this as we picked another avenue for now. I'll create a new issue to track this so we can get it resolved properly.

@ghostwords
Copy link

You could also delay registering the listeners until completion of all async tasks required by the listeners.

Here is a related extension/browser startup issue, by the way: EFForg/privacybadger#1845.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants