{"record":{"id":"8fc5058e4ed505b6","repo":"nwjs/nw.js","slug":"only-menu-of-type-menubar-can-be-used-as-this-wi-8fc505","errorCode":null,"errorMessage":"Only menu of type \"menubar\" can be used as this.window menu","messagePattern":"Only menu of type \"menubar\" can be used as this\\.window menu","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_window.js","lineNumber":631,"sourceCode":"    });\n    Object.defineProperty(NWWindow.prototype, 'isAlwaysOnTop', {\n      get: function() {\n        return this.appWindow.isAlwaysOnTop();\n      }\n    });\n    Object.defineProperty(NWWindow.prototype, 'menu', {\n      get: function() {\n        var ret = privates(this).menu || {};\n        return ret;\n      },\n      set: function(menu) {\n        if(!menu) {\n          privates(this).menu = null;\n          currentNWWindowInternal.clearMenu();\n          return;\n        }\n        if (menu.type != 'menubar')\n          throw new TypeError('Only menu of type \"menubar\" can be used as this.window menu');\n\n        privates(this).menu =  menu;\n        var menuPatch = currentNWWindowInternal.setMenu(menu.id);\n        if (menuPatch.length) {\n          menuPatch.forEach((patch)=>{\n            let menuIndex = patch.menu;\n            let itemIndex = patch.index;\n            let menuToPatch = menu.items[menuIndex];\n            if (menuToPatch && menuToPatch.submenu) {\n              menuToPatch.submenu.insert(new nw.MenuItem(patch.option), itemIndex);\n            }\n          });\n        }\n      }\n    });\n    Object.defineProperty(NWWindow.prototype, 'window', {\n      get: function() {\n        return this.appWindow.contentWindow;","sourceCodeStart":613,"sourceCodeEnd":649,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_window.js#L613-L649","documentation":"Thrown by the NWWindow.prototype 'menu' setter (win.menu = menu) when menu is truthy and menu.type !== 'menubar'. A window-level menu must be a menubar-style menu (the kind that renders as a native top menu bar); context menus ('contextmenu' type) or menus without a type cannot be attached to a window. Assigning a falsy value clears the menu and is allowed.","triggerScenarios":"win.menu = new nw.Menu({ type: 'contextmenu' }); win.menu = new nw.Menu() (default type is not menubar); win.menu = aMenuObjectMissingType.","commonSituations":"Reusing a context menu instance for the window menu; forgetting to set type: 'menubar' when constructing the Menu; assuming the default Menu type is menubar (it is not).","solutions":["Construct the menu with type: 'menubar': const m = new nw.Menu({ type: 'menubar' }); then win.menu = m.","To clear the window menu, assign win.menu = null (falsy values are allowed and clear it).","Keep separate Menu instances for context menus vs window menus."],"exampleFix":"// before\nwin.menu = new nw.Menu({ type: 'contextmenu' });\n// after\nwin.menu = new nw.Menu({ type: 'menubar' });","handlingStrategy":"type-guard","validationCode":"if (menu && menu.type !== 'menubar') {\n  throw new TypeError('win.menu requires a menubar-type nw.Menu');\n}\nwin.menu = menu;","typeGuard":"function isWindowMenu(m) { return !m || (m instanceof nw.Menu && m.type === 'menubar'); }","tryCatchPattern":null,"preventionTips":["Construct window menus with type: 'menubar'.","Use null/falsy to clear the window menu.","Keep context menus and window menus as separate instances."],"tags":["nwjs","window","validation","menu","menubar","setter"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}