{"record":{"id":"ebf8bf56da051017","repo":"nwjs/nw.js","slug":"only-menu-of-type-menubar-can-be-used-as-this-wi","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":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_newwin.js","lineNumber":717,"sourceCode":"Object.defineProperty(NWWindow.prototype, 'isAlwaysOnTop', {\n  get: function() {\n    this.cWindow = currentNWWindowInternal.getCurrent(this.cWindow.id, {'populate': true});\n    return this.cWindow.alwaysOnTop;\n  }\n});\nObject.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(this.cWindow.id);\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, this.cWindow.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});\nObject.defineProperty(NWWindow.prototype, 'window', {\n  get: function() {\n    this.cWindow = currentNWWindowInternal.getCurrent(this.cWindow.id, {'populate': true});","sourceCodeStart":699,"sourceCodeEnd":735,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_newwin.js#L699-L735","documentation":"Thrown by the NWWindow 'menu' setter when the assigned menu's type is not 'menubar'. Only a menubar-style nw.Menu can be set as a window's application menu; a contextmenu (popup) menu is rejected because it cannot back a window-level menu bar.","triggerScenarios":"Running `win.menu = new nw.Menu({ type: 'contextmenu' })` or assigning a menu built without specifying type (defaults to contextmenu).","commonSituations":"Reusing the same context Menu instance for both a popup and the window menu; forgetting to set type: 'menubar' when constructing the application menu.","solutions":["Construct the menu as menubar: `new nw.Menu({ type: 'menubar' })` before assigning.","Set `win.menu = null` to clear an existing window menu."],"exampleFix":"// before\nconst menu = new nw.Menu();\nwin.menu = menu;\n// after\nconst menu = new nw.Menu({ type: 'menubar' });\nwin.menu = menu;","handlingStrategy":"type-guard","validationCode":"if (menu && menu.type !== 'menubar') throw new TypeError('window menu must be type menubar');","typeGuard":"function isMenuBar(m) { return m && m.type === 'menubar'; }","tryCatchPattern":"try { win.menu = m; } catch (e) { if (/menubar/.test(e.message)) { win.menu = new nw.Menu({ type: 'menubar' }); } else throw e; }","preventionTips":["Construct window menus with type: 'menubar'.","Do not reuse a context-menu instance as a window menu."],"tags":["window","menu","setter","enum","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}