{"record":{"id":"72c43090bc73eb74","repo":"nwjs/nw.js","slug":"only-support-getting-plain-text-from-clipboard","errorCode":null,"errorMessage":"Only support getting plain text from Clipboard","messagePattern":"Only support getting plain text from Clipboard","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"src/api/clipboard/clipboard.js","lineNumber":43,"sourceCode":"}\nrequire('util').inherits(Clipboard, exports.Base);\n\nClipboard.prototype.set = function(data, type) {\n  if (typeof type == 'undefined')\n    type = 'text';\n\n  if (type != 'text')\n    throw new TypeError(\"Type of '\" + type + \"' is not supported\");\n\n  nw.callObjectMethod(this, 'Set', [ data, type ]);\n}\n\nClipboard.prototype.get = function(type) {\n  if (typeof type == 'undefined')\n    type = 'text';\n\n  if (type != 'text')\n    throw new TypeError('Only support getting plain text from Clipboard');\n\n  var result = nw.callObjectMethodSync(this, 'Get', [ type ]);\n  if (type == 'text')\n    return String(result);\n}\n\nClipboard.prototype.clear = function() {\n  nw.callObjectMethod(this, 'Clear', [ ]);\n}\n\nexports.Clipboard = {\n  get: function() {\n    if (clipboardInstance == null) {\n      clipboardInstance = new Clipboard();\n    }\n\n    return clipboardInstance;\n  }","sourceCodeStart":25,"sourceCodeEnd":61,"githubUrl":"https://github.com/nwjs/nw.js/blob/e15da848e9e08e6e467532dae78995c6ad2f55ee/src/api/clipboard/clipboard.js#L25-L61","documentation":"Clipboard.prototype.get mirrors set: only the 'text' type is readable. Any non-'text' value (or a case-variant like 'Text') throws a TypeError before the native Get call. The message is phrased differently from the set() error but expresses the same single-type limitation.","triggerScenarios":"Calling nw.Clipboard.get().get('html'), .get('png'), or .get('file'). Also a case-sensitive mismatch such as .get('TEXT').","commonSituations":"Reading image/HTML clipboard data — common in screenshot or paste-image features. Developers porting from Electron's clipboard.readImage/readHtml. Misreading docs and assuming a generic type parameter.","solutions":["Call get() or get('text') to retrieve the plain-text clipboard contents.","For non-text content, listen for native paste events in the renderer and handle the data transfer there instead of through nw.Clipboard.","Verify the type argument is exactly the lowercase string 'text'."],"exampleFix":"// before\nvar html = nw.Clipboard.get().get('html'); // throws\n\n// after\nvar text = nw.Clipboard.get().get('text');","handlingStrategy":"validation","validationCode":"function getText(type) {\n  type = (typeof type === 'undefined') ? 'text' : type;\n  if (type !== 'text') throw new Error('Unsupported clipboard read type: ' + type);\n  return nw.Clipboard.get().get('text');\n}","typeGuard":"function isReadableType(t) { return t === undefined || t === 'text'; }","tryCatchPattern":"try { return nw.Clipboard.get().get(type); }\ncatch (e) {\n  if (e instanceof TypeError && /plain text/.test(e.message)) {\n    return nw.Clipboard.get().get('text');\n  } throw e;\n}","preventionTips":["Call get() with no argument to read text.","For image/HTML paste, handle native paste events in the renderer.","Ensure the type argument is exactly 'text'."],"tags":["nwjs","clipboard","type-validation","unsupported-feature"],"backgroundTag":null,"analyzedSha":"e15da848e9e08e6e467532dae78995c6ad2f55ee","analyzedAt":"2026-08-13T04:15:35.452Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}