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

Save Brave Fixes #4270 #4524

Merged
merged 9 commits into from
Jun 14, 2018
Merged

Save Brave Fixes #4270 #4524

merged 9 commits into from
Jun 14, 2018

Conversation

jennypollack
Copy link
Contributor

In Brave Browser extension.i18n.getAcceptLanguages throws:
"Unchecked runtime.lastError while running i18n.getAcceptLanguages: Access to extension API denied."

Once Brave Browser implementation lands for locale support, no further change will be needed in MM to support language preferences.

Meanwhile this check should allow MetaMask to load on Brave.


// safeguard for Brave Browser until they implement chrome.i18n.getAcceptLanguages
// https://github.com/MetaMask/metamask-extension/issues/4270
if(!userPreferredLocaleCodes){
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can I catch it? Not really; it's not raised by your code, but the cleanup code that handles async tasks in Chrome API; therefore using try ... catch in your callback won't help. Since it's asynchronous, using try around the original API call won't help either.

shoutouts to: https://stackoverflow.com/questions/28431505/unchecked-runtime-lasterror-when-using-chrome-api

@jennypollack jennypollack requested review from kumavis and danfinlay June 7, 2018 16:29
Copy link
Contributor

@danfinlay danfinlay left a comment

Choose a reason for hiding this comment

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

I think this leaves out part of the fix that Brave recommended, could you verify? Had this fixed the problem after you'd reproduced it?

@@ -2,8 +2,7 @@ const extension = require('extensionizer')
const promisify = require('pify')
const allLocales = require('../../_locales/index.json')

const isSupported = extension.i18n && extension.i18n.getAcceptLanguages
const getPreferredLocales = isSupported ? promisify(
const getPreferredLocales = extension.i18n ? promisify(
Copy link
Contributor

@danfinlay danfinlay Jun 7, 2018

Choose a reason for hiding this comment

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

My understanding is that Brave does expose a extension.i18n object, and even a getAcceptLanguages method on it, so they would pass this test.

From what they reported and I relayed in this comment, the only way to check their failure right now is to check chrome.runtime.lastError within the callback, and if there's an error, then fall back.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, both evaluate successfully for Brave. Do you think it makes sense to keep the extension.i18n check for protection in browsers that don't expose i18n at all?
(am not sure how prevalent this is/would be)

Checking for the runtime.lastError did not seem to resolve, but possibly due to how it was wrapped in pify - I'll take another look.

Copy link
Contributor

Choose a reason for hiding this comment

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

Per feedback from Brave, we are now handling errors from this function, because Brave currently throws for this.

@jennypollack
Copy link
Contributor Author

Without evaluating the runtime.lastError, Brave returns undefined so the proposed change does fix the issue.

danfinlay
danfinlay previously approved these changes Jun 7, 2018
Copy link
Contributor

@danfinlay danfinlay left a comment

Choose a reason for hiding this comment

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

Sounds like this works, and it shouldn't break any normally compatible browsers, so this is safe to merge.

@metamaskbot
Copy link
Collaborator

Builds ready [fd8bcc9]: mascara, chrome, firefox, edge, opera

@danfinlay
Copy link
Contributor

@jennypollack Would you mind adding a user-facing entry to the CHANGELOG.md file?

kumavis
kumavis previously approved these changes Jun 7, 2018
@jennypollack jennypollack dismissed stale reviews from kumavis and danfinlay via 93bdfc0 June 7, 2018 21:15
@metamaskbot
Copy link
Collaborator

Builds ready [93bdfc0]: mascara, chrome, firefox, edge, opera

kumavis
kumavis previously approved these changes Jun 9, 2018
CHANGELOG.md Outdated
@@ -3,6 +3,7 @@
## Current Master

- Fix bug where account reset did not work with custom RPC providers.
- Fix for Brave i18n getAcceptLanguages [#4270](https://github.com/MetaMask/metamask-extension/issues/4270)
Copy link
Member

Choose a reason for hiding this comment

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

@jennypollack we add changelog entries under "current master" and then move that to a version number of release

kumavis
kumavis previously approved these changes Jun 9, 2018
@danfinlay
Copy link
Contributor

From Brave Sampson:

chrome.i18n will return truthy in Brave. But calling the getAcceptLanguage method will throw. We do support chrome.i18n.getUILanguage at the moment (with getAcceptLanguage support coming very soon). A test today would need to fingerprint Brave, or wrap a call to getAcceptLanguage in a try...catch.

Copy link
Contributor

@danfinlay danfinlay left a comment

Choose a reason for hiding this comment

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

Left a comment from Brave, I'd like us to adjust to their specifications.

@danfinlay danfinlay dismissed stale reviews from ghost and kumavis via 11bfdf4 June 14, 2018 17:10
kumavis
kumavis previously approved these changes Jun 14, 2018
@kumavis kumavis dismissed danfinlay’s stale review June 14, 2018 17:12

addressed the feedback

@metamaskbot
Copy link
Collaborator

Builds ready [11bfdf4]: mascara, chrome, firefox, edge, opera

@metamaskbot
Copy link
Collaborator

Builds ready [d9ef72c]: mascara, chrome, firefox, edge, opera

@tmashuang tmashuang merged commit 299abee into develop Jun 14, 2018
@tmashuang tmashuang deleted the save-brave branch June 14, 2018 17:37
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.

5 participants