{"record":{"id":"5b34dea7d168f0a6","repo":"nwjs/nw.js","slug":"click-must-be-a-valid-function-5b34de","errorCode":null,"errorMessage":"'click' must be a valid Function","messagePattern":"'click' must be a valid Function","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/tray/tray.js","lineNumber":55,"sourceCode":"    option.icon = nw.getAbsolutePath(option.icon);\n  }\n\n  if (option.hasOwnProperty('alticon')) {\n    option.shadowAlticon = String(option.alticon);\n    option.alticon = nw.getAbsolutePath(option.alticon);\n  }\n\n  if (option.hasOwnProperty('iconsAreTemplates'))\n    option.iconsAreTemplates = Boolean(option.iconsAreTemplates);\n  else\n    option.iconsAreTemplates = true;\n\n  if (option.hasOwnProperty('tooltip'))\n    option.tooltip = String(option.tooltip);\n\n  if (option.hasOwnProperty('click')) {\n    if (typeof option.click != 'function') {\n      throw new TypeError(\"'click' must be a valid Function\");\n    } else {\n      this.click = option.click;\n    }\n   }\n\n  if (option.hasOwnProperty('menu')) {\n    if (v8_util.getConstructorName(option.menu) != 'Menu')\n      throw new TypeError(\"'menu' must be a valid Menu\");\n\n    // Transfer only object id\n    v8_util.setHiddenValue(this, 'menu', option.menu);\n    option.menu = option.menu.id;\n  }\n\n  v8_util.setHiddenValue(this, 'option', option);\n  nw.allocateObject(this, option);\n\n  // All properties must be set after initialization.","sourceCodeStart":37,"sourceCodeEnd":73,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/tray/tray.js#L37-L73","documentation":"Thrown by the nw.Tray constructor when 'click' is present in options but is not a function. The click handler is invoked on left-click of the tray icon, so it must be callable.","triggerScenarios":"Calling `new nw.Tray({ icon: 'i.png', click: 'onClick' })` or passing a reference that resolved to undefined.","commonSituations":"Storing the handler name as a string in config; passing an object wrapper instead of the bound method.","solutions":["Provide a function reference for 'click'.","Omit 'click' if you do not need left-click handling and use the 'click' event via on() instead."],"exampleFix":"// before\nnew nw.Tray({ icon: 'i.png', click: 'trayClicked' });\n// after\nnew nw.Tray({ icon: 'i.png', click: trayClicked });","handlingStrategy":"type-guard","validationCode":"if (option.hasOwnProperty('click') && typeof option.click !== 'function') {\n  delete option.click;\n}","typeGuard":"function isClickHandler(v) { return typeof v === 'function'; }","tryCatchPattern":"try { new nw.Tray(opt); } catch (e) { if (/click/.test(e.message)) { delete opt.click; new nw.Tray(opt); } else throw e; }","preventionTips":["Pass method references, not names.","Use tray.on('click', fn) as an alternative to the constructor option."],"tags":["tray","constructor","type-check","nwjs"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}