nwjs/nw.js · error · TypeException
Expecting set(string, optional string, optional boolean) or
Error message
Expecting set(string, optional string, optional boolean) or set(ClipboardData[]) or set(ClipboardData).
What it means
Thrown by nw.Clipboard.set when arguments match none of the supported overloads: set(string[, string[, boolean]]), set(ClipboardData[]), or set(ClipboardData). The dispatcher checks Array tag, String tag, and argument count, then throws if nothing matches.
Source
Thrown at src/resources/api_nw_clipboard.js:64
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 () {
return nwClipboardBinding.clearSync();
};
NWClipboard.prototype.readAvailableTypes = function() {
return nwClipboardBinding.readAvailableTypes();
};
nwClipboardBinding['get'] = NWClipboard['get'];
View on GitHub (pinned to e15da848e9)
Solutions
- Set text: `nw.Clipboard.set('hello', 'text')` or just `nw.Clipboard.set('hello')`.
- Set multiple entries: `nw.Clipboard.set([{ type: 'text', data: 'hi' }])`.
- Set a single ClipboardData: `nw.Clipboard.set({ type: 'text', data: 'hi' })`.
Example fix
// before
nw.Clipboard.set();
// after
nw.Clipboard.set('hello', 'text'); Defensive patterns
Strategy: validation
Validate before calling
function safeSet(content, type) {
if (typeof content !== 'string' && !Array.isArray(content) && (typeof content !== 'object' || content === null))
throw new TypeError('Invalid clipboard content');
return nw.Clipboard.set(content, type);
} Type guard
function isClipboardData(v) { return v && typeof v === 'object' && typeof v.type === 'string'; } Try / catch
try { nw.Clipboard.set(content, type); } catch (e) { if (/Expecting set/.test(e.message)) nw.Clipboard.set(String(content), 'text'); else throw e; } Prevention
- Coerce content to a string before calling set for text.
- Use ClipboardData objects for non-text types.
When it happens
Trigger: Calling `nw.Clipboard.set()` with no args, `nw.Clipboard.set(null)`, or `nw.Clipboard.set(123)`.
Common situations: Passing a number or object as content without wrapping it as a ClipboardData; forgetting the content argument when specifying only a type.
Related errors
- Expecting get(string, optional boolean) or get(ClipboardData
- Type of '{type}' is not supported
- Only support getting plain text from Clipboard
- 'active' must be a valid function.
- 'failed' must be a valid function.
AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13).
Data as JSON: /api/errors/23ce54ab72f7ee77.
Report an issue: GitHub.