nwjs/nw.js · error · TypeError

Only support getting plain text from Clipboard

Error message

Only support getting plain text from Clipboard

What it means

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.

Source

Thrown at src/api/clipboard/clipboard.js:43

}
require('util').inherits(Clipboard, exports.Base);

Clipboard.prototype.set = function(data, type) {
  if (typeof type == 'undefined')
    type = 'text';

  if (type != 'text')
    throw new TypeError("Type of '" + type + "' is not supported");

  nw.callObjectMethod(this, 'Set', [ data, type ]);
}

Clipboard.prototype.get = function(type) {
  if (typeof type == 'undefined')
    type = 'text';

  if (type != 'text')
    throw new TypeError('Only support getting plain text from Clipboard');

  var result = nw.callObjectMethodSync(this, 'Get', [ type ]);
  if (type == 'text')
    return String(result);
}

Clipboard.prototype.clear = function() {
  nw.callObjectMethod(this, 'Clear', [ ]);
}

exports.Clipboard = {
  get: function() {
    if (clipboardInstance == null) {
      clipboardInstance = new Clipboard();
    }

    return clipboardInstance;
  }

View on GitHub (pinned to e15da848e9)

Solutions

  1. Call get() or get('text') to retrieve the plain-text clipboard contents.
  2. For non-text content, listen for native paste events in the renderer and handle the data transfer there instead of through nw.Clipboard.
  3. Verify the type argument is exactly the lowercase string 'text'.

Example fix

// before
var html = nw.Clipboard.get().get('html'); // throws

// after
var text = nw.Clipboard.get().get('text');
Defensive patterns

Strategy: validation

Validate before calling

function getText(type) {
  type = (typeof type === 'undefined') ? 'text' : type;
  if (type !== 'text') throw new Error('Unsupported clipboard read type: ' + type);
  return nw.Clipboard.get().get('text');
}

Type guard

function isReadableType(t) { return t === undefined || t === 'text'; }

Try / catch

try { return nw.Clipboard.get().get(type); }
catch (e) {
  if (e instanceof TypeError && /plain text/.test(e.message)) {
    return nw.Clipboard.get().get('text');
  } throw e;
}

Prevention

When it happens

Trigger: Calling nw.Clipboard.get().get('html'), .get('png'), or .get('file'). Also a case-sensitive mismatch such as .get('TEXT').

Common situations: 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.

Related errors


AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13). Data as JSON: /api/errors/72c43090bc73eb74. Report an issue: GitHub.