nwjs/nw.js · error · TypeException

Expecting get(string, optional boolean) or get(ClipboardData

Error message

Expecting get(string, optional boolean) or get(ClipboardData[]) or get(ClipboardData).

What it means

Thrown by nw.Clipboard.get when arguments match none of the supported overloads: get(string[, boolean]), get(ClipboardData[]), or get(ClipboardData). The dispatcher checks argument count and type tags (Array, String, object) and falls through to a TypeException if none match.

Source

Thrown at src/resources/api_nw_clipboard.js:48

  clipboard = new NWClipboard();
  return clipboard;
};

NWClipboard.prototype.get = function (type, raw) {
  var toString = $Object.prototype.toString;
  // get(ClipboardData[])
  if (arguments.length === 1 && toString.apply(type) === '[object Array]') {
    return nwClipboardBinding.getListSync(type);
  }
  // get(DOMString, boolean)
  if (!type || toString.apply(type) === '[object String]') {
    return nwClipboardBinding.getListSync([{type: type || 'text', raw: !!raw}])[0].data;
  }
  // get(ClipboardData)
  if (arguments.length === 1) {
    return nwClipboardBinding.getListSync([type])[0].data;
  }
  throw new TypeException('Expecting get(string, optional boolean) or get(ClipboardData[]) or get(ClipboardData).');
};
NWClipboard.prototype.set = function (content, type, raw) {
  var toString = $Object.prototype.toString;
  // set(ClipboardData[])
  if (arguments.length === 1 && toString.apply(content) === '[object Array]') {
    return nwClipboardBinding.setListSync(content);
  }
  // set(DOMString, DOMString, boolean)
  if (toString.apply(content) === '[object String]') {
    return nwClipboardBinding.setListSync([{type: type || 'text', raw: !!raw, data: content}]);
  }
  // set(ClipboardData)
  if (arguments.length === 1) {
    return nwClipboardBinding.setListSync([content]);
  }
  throw new TypeException('Expecting set(string, optional string, optional boolean) or set(ClipboardData[]) or set(ClipboardData).');
};
NWClipboard.prototype.clear = function () {

View on GitHub (pinned to e15da848e9)

Solutions

  1. For text: `nw.Clipboard.get('text')`.
  2. For multiple types: `nw.Clipboard.get([{ type: 'text' }, { type: 'png' }])`.
  3. For a single ClipboardData object: `nw.Clipboard.get({ type: 'text', raw: false })`.

Example fix

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

Strategy: validation

Validate before calling

function safeGet(arg) {
  if (arguments.length === 0) return nw.Clipboard.get('text');
  return nw.Clipboard.get(arg);
}

Type guard

function isClipboardDataArray(v) { return Array.isArray(v) && v.every(i => i && typeof i === 'object' && typeof i.type === 'string'); }

Try / catch

try { return nw.Clipboard.get(type, raw); } catch (e) { if (/Expecting get/.test(e.message)) return nw.Clipboard.get('text'); throw e; }

Prevention

When it happens

Trigger: Calling `nw.Clipboard.get()` with no args, `nw.Clipboard.get(123)`, or `nw.Clipboard.get(true, false, true)` (3 args).

Common situations: Assuming get() with no arguments returns plain text (it does not — pass 'text' explicitly); passing a number where a type string is expected.

Related errors


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