{"record":{"id":"b54d1239277eb07b","repo":"nwjs/nw.js","slug":"invaild-parameter-need-shortcut-object","errorCode":null,"errorMessage":"Invaild parameter, need Shortcut object.","messagePattern":"Invaild parameter, need Shortcut object\\.","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/app/app.js","lineNumber":86,"sourceCode":"App.prototype.getProxyForURL = function (url) {\n  return nw.callStaticMethodSync('App', 'getProxyForURL', [ url ]);\n}\n\nApp.prototype.setProxyConfig = function (proxy_config) {\n  return nw.callStaticMethodSync('App', 'SetProxyConfig', [ proxy_config ]);\n}\n\nApp.prototype.addOriginAccessWhitelistEntry = function(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains) {\n    return nw.callStaticMethodSync('App', 'AddOriginAccessWhitelistEntry', sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);\n}\n\nApp.prototype.removeOriginAccessWhitelistEntry = function(sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains) {\n    return nw.callStaticMethodSync('App', 'RemoveOriginAccessWhitelistEntry', sourceOrigin, destinationProtocol, destinationHost, allowDestinationSubdomains);\n}\n\nApp.prototype.registerGlobalHotKey = function(shortcut) {\n  if (v8_util.getConstructorName(shortcut) != \"Shortcut\")\n    throw new TypeError(\"Invaild parameter, need Shortcut object.\");\n\n  return nw.callStaticMethodSync('App',\n                                 'RegisterGlobalHotKey',\n                                 [ shortcut.id ])[0];\n}\n\nApp.prototype.unregisterGlobalHotKey = function(shortcut) {\n  if (v8_util.getConstructorName(shortcut) != \"Shortcut\")\n    throw new TypeError(\"Invaild parameter, need Shortcut object.\");\n\n  nw.callStaticMethodSync('App', 'UnregisterGlobalHotKey', [ shortcut.id ]);\n}\n\nApp.prototype.__defineGetter__('argv', function() {\n  if (!argv) {\n    var fullArgv = this.fullArgv;\n    argv = [];\n    for (var i = 0; i < fullArgv.length; ++i) {","sourceCodeStart":68,"sourceCodeEnd":104,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/app/app.js#L68-L104","documentation":"Thrown by nw.App.registerGlobalHotKey() when the argument is not an instance of nw.Shortcut. The guard calls v8_util.getConstructorName(shortcut) and compares it to the literal string \"Shortcut\", so plain objects, primitive values, or objects built in a different JS realm all fail. This protects the native RegisterGlobalHotKey call, which immediately dereferences shortcut.id. The message itself contains a typo (\"Invaild\").","triggerScenarios":"Calling nw.App.registerGlobalHotKey(undefined), registerGlobalHotKey({key:'Ctrl+A'}), or registerGlobalHotKey('Ctrl+A'). Also triggered when the shortcut object was created in another frame/webview and passed across contexts, because the constructor-name string no longer matches.","commonSituations":"Developers hand-build the shortcut object ({key, active, failed}) instead of using the nw.Shortcut constructor; they pass the raw key string; or a refactor that moves Shortcut creation into an iframe/window breaks the cross-realm constructor check.","solutions":["Build the value with `new nw.Shortcut({ key: 'Ctrl+A', active: fn, failed: fn })` and pass that instance.","If the shortcut originates in another frame, re-create it in the main node context before registering.","Keep the Shortcut reference in a variable so the same instance can be passed to unregisterGlobalHotKey later."],"exampleFix":"// before\nnw.App.registerGlobalHotKey({ key: 'Ctrl+Shift+P', active: onActive });\n\n// after\nvar sc = new nw.Shortcut({ key: 'Ctrl+Shift+P', active: onActive, failed: onFail });\nnw.App.registerGlobalHotKey(sc);","handlingStrategy":"type-guard","validationCode":"function isShortcut(v) {\n  return v instanceof nw.Shortcut;\n}\n// before registering:\nif (!isShortcut(sc)) sc = new nw.Shortcut(sc);\nnw.App.registerGlobalHotKey(sc);","typeGuard":"function isShortcut(v) {\n  return v != null && typeof v === 'object' &&\n    (v instanceof nw.Shortcut ||\n     (v.constructor && v.constructor.name === 'Shortcut'));\n}","tryCatchPattern":"try {\n  nw.App.registerGlobalHotKey(sc);\n} catch (e) {\n  if (e instanceof TypeError && /Shortcut object/.test(e.message)) {\n    sc = new nw.Shortcut(sc); // coerce and retry once\n    nw.App.registerGlobalHotKey(sc);\n  } else { throw e; }\n}","preventionTips":["Centralize shortcut creation in one factory that always returns new nw.Shortcut(...).","Store every registered Shortcut instance so unregister uses the same reference.","Build shortcuts in the main node context, not in webviews/iframes."],"tags":["nwjs","app","shortcut","global-hotkey","type-validation"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}