@@ -55,6 +55,7 @@ import {
5555 CorruptionHandler ,
5656 hasVault ,
5757} from './lib/state-corruption/state-corruption-recovery' ;
58+ import { initSidePanelContextMenu } from './lib/sidepanel-context-menu' ;
5859import {
5960 backedUpStateKeys ,
6061 PersistenceManager ,
@@ -175,7 +176,10 @@ const ONE_SECOND_IN_MILLISECONDS = 1_000;
175176// Timeout for initializing phishing warning page.
176177const PHISHING_WARNING_PAGE_TIMEOUT = ONE_SECOND_IN_MILLISECONDS ;
177178
178- lazyListener . once ( 'runtime' , 'onInstalled' ) . then ( handleOnInstalled ) ;
179+ lazyListener . once ( 'runtime' , 'onInstalled' ) . then ( ( details ) => {
180+ handleOnInstalled ( details ) ;
181+ handleSidePanelContextMenu ( ) ;
182+ } ) ;
179183
180184/**
181185 * This deferred Promise is used to track whether initialization has finished.
@@ -1672,26 +1676,14 @@ function onInstall() {
16721676 platform . openExtensionInBrowser ( ) ;
16731677 }
16741678}
1675- // Only register sidepanel context menu for browsers that support it (Chrome/Edge/Brave)
1676- // and when the feature flag is enabled
1677- if (
1678- browser . contextMenus &&
1679- browser . sidePanel &&
1680- process . env . IS_SIDEPANEL ?. toString ( ) === 'true'
1681- ) {
1682- browser . runtime . onInstalled . addListener ( ( ) => {
1683- browser . contextMenus . create ( {
1684- id : 'openSidePanel' ,
1685- title : 'MetaMask Sidepanel' ,
1686- contexts : [ 'all' ] ,
1687- } ) ;
1688- } ) ;
1689- browser . contextMenus . onClicked . addListener ( ( info , tab ) => {
1690- if ( info . menuItemId === 'openSidePanel' ) {
1691- // This will open the panel in all the pages on the current window.
1692- browser . sidePanel . open ( { windowId : tab . windowId } ) ;
1693- }
1694- } ) ;
1679+
1680+ /**
1681+ * Handles the onInstalled event for sidepanel context menu creation.
1682+ * This is registered via lazyListener to catch the event at module load time.
1683+ */
1684+ async function handleSidePanelContextMenu ( ) {
1685+ await isInitialized ;
1686+ await initSidePanelContextMenu ( controller ) ;
16951687}
16961688
16971689// // On first install, open a new tab with MetaMask
0 commit comments