- 
                Notifications
    You must be signed in to change notification settings 
- Fork 5.4k
fix: cp-12.15.0 Prevent fullscreen UI from opening every startup #31332
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
Conversation
5578d50    to
    79237e9      
    Compare
  
    | I haven't written any tests for this yet. This is a bit trick to test because we can't really unit test these integrations with the extension/service worker API. We won't know that the integration works without a real browser. And we can't test this using a standard E2E test build because the behavior we're testing (opening a new tab on install) is disabled. We should be able to write an E2E test that uses a production build though, similar to the vault decryption build. Given the urgency of fixing this problem, I'd prefer to use manual testing for now. I'll follow up with the E2E test in a later PR. | 
79237e9    to
    d4713a6      
    Compare
  
    | addAppInstalledEvent(); | ||
| platform.openExtensionInBrowser(); | ||
| } | ||
| onNavigateToTab(); | 
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'm not sure why this function was here, it's not really related to the install event. This was being called irrespective of whether this session was the first after install as well, which is confusing.
I've moved it down to initBackground, so it should get called as part of initialization the same way it always was before.
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.
Looks great! Solution is a maybe bit non-idiomatic, but still much easier to reason about than the async storage complexity.
Left only some nits/questions, nothing that must be changed.
I'll give it a few runs locally tomorrow before give it the ✅
        
          
                app/scripts/background.js
              
                Outdated
          
        
      | // This condition is for when `background.js` was loaded before the `onInstalled` listener was | ||
| // called. | ||
| } else { | ||
| globalThis.__metamaskTriggerOnInstall = () => onInstall(); | 
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.
neat!
| Not quite sure why the "App Installed Event" E2E tests are failing. | 
2f3b1e3    to
    ac3a801      
    Compare
  
    006de3c    to
    7e06ea8      
    Compare
  
    | Builds ready [7e06ea8]
 UI Startup Metrics (1191 ± 58 ms)
 Bundle size diffs [🚀 Bundle size reduced!]
 | 
| Builds ready [18e2d1b]
 UI Startup Metrics (1172 ± 54 ms)
 Bundle size diffs [🚀 Bundle size reduced!]
 | 
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.
On Firefox I was automatically greeted with the "Welcome back" login screen, not the "Let's get started" screen, in fullscreen after installing the extension as a "Temporary Add-on".
My hunch is that this is because I had previously installed it this way, so this was a new install, but firefox persisted the database from the last time I installed MM as a Temporary add-on.
If I manually remove MM (instead of waiting for it to expire and get automatically removed by FF) and then install it again it opens in full screen with the "Let's get started" screen, as expected.
I think this behavior is fine, it is a change from the original way we did this (check if we had written to storage before), so I just wanted to mention it.
| E2E test added in #31435 | 
Description
Prevent tab from opening upon every browser startup.
A recent PR updated the logic for how we determine whether the extension was just installed or not; we used to check state, but now we use the
runtime.onInstalledevent instead to store a flag in session storage indicating whether the extension was just installed.Unfortunately this PR had a couple of bugs; the condition using this flag was accidentally reversed, and the read from session storage was never successful because of a race condition (the write had not finished yet).
To address both problems, the logic for detecting first install was refactored to use a global variable instead of session storage. Globals can be accessed and written synchronously, preventing any possibility of a race condition.
The solution was complicated by the fact that MV3 builds must add an
onInstalledlistener in the root service worker module, otherwise the listener is never called (we tested this experimentally). It was also unclear whether the listener would always run before or after thebackground.jsscript loading, and we need to trigger an action inbackground.json install. But we've accounted for both possibilities in this solution.Related issues
Fixes: #30924
Manual testing steps
yarn distandyarn dist:mv2), or download the builds from themetamaskbotcommentScreenshots/Recordings
N/A
Pre-merge author checklist
Pre-merge reviewer checklist