@@ -483,9 +483,7 @@ window.assignManager = {
483483 } ,
484484
485485 contextualIdentityRemoved ( changeInfo ) {
486- browser . contextMenus . remove (
487- changeInfo . contextualIdentity . cookieStoreId
488- ) ;
486+ this . removeMenuItem ( changeInfo . contextualIdentity . cookieStoreId ) ;
489487 } ,
490488
491489 async _onClickedHandler ( info , tab ) {
@@ -672,11 +670,11 @@ window.assignManager = {
672670 // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1215376#c16
673671 // We also can't change for always private mode
674672 // See: https://bugzilla.mozilla.org/show_bug.cgi?id=1352102
675- browser . contextMenus . remove ( this . MENU_ASSIGN_ID ) ;
676- browser . contextMenus . remove ( this . MENU_REMOVE_ID ) ;
677- browser . contextMenus . remove ( this . MENU_SEPARATOR_ID ) ;
678- browser . contextMenus . remove ( this . MENU_HIDE_ID ) ;
679- browser . contextMenus . remove ( this . MENU_MOVE_ID ) ;
673+ this . removeMenuItem ( this . MENU_ASSIGN_ID ) ;
674+ this . removeMenuItem ( this . MENU_REMOVE_ID ) ;
675+ this . removeMenuItem ( this . MENU_SEPARATOR_ID ) ;
676+ this . removeMenuItem ( this . MENU_HIDE_ID ) ;
677+ this . removeMenuItem ( this . MENU_MOVE_ID ) ;
680678 } ,
681679
682680 async calculateContextMenu ( tab ) {
@@ -850,12 +848,19 @@ window.assignManager = {
850848 } ,
851849
852850 async removeBookmarksMenu ( ) {
853- browser . contextMenus . remove ( this . OPEN_IN_CONTAINER ) ;
851+ this . removeMenuItem ( this . OPEN_IN_CONTAINER ) ;
854852 const identities = await browser . contextualIdentities . query ( { } ) ;
855853 for ( const identity of identities ) {
856- browser . contextMenus . remove ( identity . cookieStoreId ) ;
854+ this . removeMenuItem ( identity . cookieStoreId ) ;
857855 }
858856 } ,
857+
858+ removeMenuItem ( menuItemId ) {
859+ // Callers do not check whether the menu exists before attempting to remove
860+ // it. contextMenus.remove rejects when the menu does not exist, so we need
861+ // to catch and swallow the error to avoid logspam.
862+ browser . contextMenus . remove ( menuItemId ) . catch ( ( ) => { } ) ;
863+ }
859864} ;
860865
861866assignManager . init ( ) ;
0 commit comments