Skip to content

Commit

Permalink
perf: improve perceived performance by initially loading an asset-les…
Browse files Browse the repository at this point in the history
…s HTML file, `popup-init.html`, that then redirects to the slower `popup.html`

Co-authored-by: Mark Stacey <markjstacey@gmail.com>
  • Loading branch information
davidmurdoch and Gudahtt committed Aug 20, 2024
1 parent de47c48 commit cd11ad3
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 3 deletions.
2 changes: 1 addition & 1 deletion app/manifest/v2/_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"512": "images/icon-512.png"
},
"default_title": "MetaMask",
"default_popup": "popup.html"
"default_popup": "popup-init.html"
},
"commands": {
"_execute_browser_action": {
Expand Down
2 changes: 1 addition & 1 deletion app/manifest/v3/_base.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"512": "images/icon-512.png"
},
"default_title": "MetaMask",
"default_popup": "popup.html"
"default_popup": "popup-init.html"
},
"author": "https://metamask.io",
"background": {
Expand Down
2 changes: 1 addition & 1 deletion app/manifest/v3/firefox.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"512": "images/icon-512.png"
},
"default_title": "MetaMask",
"default_popup": "popup.html"
"default_popup": "popup-init.html"
},
"manifest_version": 2
}
39 changes: 39 additions & 0 deletions app/popup-init.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta http-equiv="refresh" content="0;url=/popup.html">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<title>MetaMask</title>
<style>
/**
* We try to match the user's system theme for the background color, but
* since the actual popup will use the theme from the user's extension
* settings we can't get it right 100% of the time. The browser doesn't
* allow a height or width of 0, otherwise we wouldn't bother with the
* background color.
* Unfortunately (and conveniently?), if the user *does* have a
* non-system theme set popup.html will flash the wrong theme, as the
* loading screen itself always uses the system theme. So while this page
* doesn't match popup.html's loading screen, the backgrounds will match,
* so the redirect isn't all that jarring.
*
* Implementing https://github.com/MetaMask/metamask-extension/issues/26545
* would improve the situation.
*
* Porting the loading screen (inlining all assets and CSS) to this init
* page may be a further UX improvement.
*/
html {
width: 357px;
height: 600px;
background: #f2f4f6;
}
@media screen and (prefers-color-scheme: dark) {
html {
background: #24272a;
}
}
</style>
</head>
</html>
7 changes: 7 additions & 0 deletions development/build/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,13 @@ function createFactoredBuild({
applyLavaMoat,
scripts,
});
renderHtmlFile({
htmlName: 'popup-init',
browserPlatforms,
shouldIncludeSnow,
applyLavaMoat,
scripts,
});
renderHtmlFile({
htmlName: 'notification',
browserPlatforms,
Expand Down

0 comments on commit cd11ad3

Please sign in to comment.