{"record":{"id":"5c366c9c8edc4399","repo":"nwjs/nw.js","slug":"shortcut-argument-is-not-an-instance-of-nw-short","errorCode":null,"errorMessage":"'shortcut' argument is not an instance of nw.Shortcut","messagePattern":"'shortcut' argument is not an instance of nw\\.Shortcut","errorType":"exception","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/resources/api_nw_shortcut.js","lineNumber":197,"sourceCode":"  this.on('failed', function() {\n    if (!self.failed) return;\n    if (typeof self.failed != 'function')\n      throw new TypeError(OPTION_FAILED_INVALID);\n    self.failed.apply(self, arguments);\n  });\n\n  this.key = option.key;\n  this.active = option.active;\n  this.failed = option.failed;\n\n  this._accelerator = keyToAccelerator(option.key);\n}\n\nnw.require('util').inherits(Shortcut, EventEmitter);\n\nShortcut.registerGlobalHotKey = function(shortcut) {\n  if (!(shortcut instanceof Shortcut)) {\n    throw new TypeError(ARUGMENT_NOT_SHORTCUT);\n  }\n\n  if(nwShortcutBinding.registerAccelerator(shortcut._accelerator)) {\n    registerLocal(shortcut);\n  } else {\n    shortcut.emit('failed', new Error(UNABLE_REGISTER_HOTKEY));\n  }\n};\n\nShortcut.unregisterGlobalHotKey = function(shortcut) {\n  if (!(shortcut instanceof Shortcut)) {\n    throw new TypeError(ARUGMENT_NOT_SHORTCUT);\n  }\n\n  var handler = getRegistryLocal(shortcut._accelerator);\n  if(handler && nwShortcutBinding.unregisterAccelerator(shortcut._accelerator)) {\n    unregisterLocal(shortcut);\n  } else {","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/resources/api_nw_shortcut.js#L179-L215","documentation":"Thrown by nw.Shortcut.registerGlobalHotKey(shortcut) when the argument is not an instance of Shortcut (checked via shortcut instanceof Shortcut). The method needs a Shortcut because it reads shortcut._accelerator (the parsed internal representation) and calls shortcut.emit('failed') on registration failure. A plain object or wrong type lacks these.","triggerScenarios":"nw.Shortcut.registerGlobalHotKey({ key: 'ctrl+a' }) (plain object instead of Shortcut instance); passing the key string; passing a Menu or Tray object by mistake; passing a shortcut created in a different context/realm whose prototype chain differs.","commonSituations":"Forgetting to call new nw.Shortcut() first; cross-realm objects (e.g. from an iframe or different window) where instanceof fails despite correct shape; copy-paste that drops the construction step.","solutions":["Construct the shortcut first: const sc = new nw.Shortcut({ key: 'ctrl+a', active: fn }); then nw.Shortcut.registerGlobalHotKey(sc).","For cross-realm objects, duck-type on _accelerator or reconstruct the Shortcut in the current realm before registering.","Add an instanceof check in your own wrapper to fail with a clearer message."],"exampleFix":"// before\nnw.Shortcut.registerGlobalHotKey({ key: 'ctrl+a' });\n// after\nconst sc = new nw.Shortcut({ key: 'ctrl+a', active: fn });\nnw.Shortcut.registerGlobalHotKey(sc);","handlingStrategy":"type-guard","validationCode":"if (!(shortcut instanceof nw.Shortcut)) {\n  throw new TypeError('registerGlobalHotKey requires an nw.Shortcut instance');\n}\nnw.Shortcut.registerGlobalHotKey(shortcut);","typeGuard":"function isShortcutInstance(o) { return o instanceof nw.Shortcut; }","tryCatchPattern":null,"preventionTips":["Always construct with new nw.Shortcut() before registering.","Keep references to the constructed instance, not the raw options.","For cross-realm objects, reconstruct in the current realm first."],"tags":["nwjs","shortcut","validation","instanceof","registration"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}