nwjs/nw.js · error · TypeError
Type of '{type}' is not supported
Error message
Type of '{type}' is not supported What it means
Clipboard.prototype.set only supports the 'text' type. After defaulting type to 'text' when undefined, any other value (e.g., 'png', 'html', 'file') throws a TypeError before the native Set call. This is a deliberate limitation of the nw.js clipboard binding, not a generic clipboard API.
Source
Thrown at src/api/clipboard/clipboard.js:33
// PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNES
// S FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
// OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WH
// ETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
var clipboardInstance = null;
function Clipboard() {
nw.allocateObject(this, {});
}
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', [ ]);View on GitHub (pinned to e15da848e9)
Solutions
- Call set(data) or set(data, 'text') — plain text is the only supported type.
- If you need rich content (HTML/image), write the data to a temp file and put the path/text on the clipboard instead.
- Double-check there is no capitalization typo in the type argument.
Example fix
// before
nw.Clipboard.get().set('<b>hi</b>', 'html'); // throws
// after
nw.Clipboard.get().set('<b>hi</b>', 'text'); // stored as literal text Defensive patterns
Strategy: validation
Validate before calling
function setText(data, type) {
type = (typeof type === 'undefined') ? 'text' : type;
if (type !== 'text') throw new Error('Unsupported clipboard type: ' + type);
nw.Clipboard.get().set(data, 'text');
} Type guard
function isTextType(t) { return t === undefined || t === 'text'; } Try / catch
try { nw.Clipboard.get().set(data, type); }
catch (e) {
if (e instanceof TypeError && /not supported/.test(e.message)) {
nw.Clipboard.get().set(String(data), 'text'); // fall back to text
} else { throw e; }
} Prevention
- Always call set(data) with no type, or set(data, 'text').
- Never assume HTML/image types are supported; they are not.
- Watch for capitalization: only lowercase 'text' passes.
When it happens
Trigger: Calling nw.Clipboard.get().set(data, 'html'), .set(data, 'png'), or .set(data, 'rtf'). Passing a typo like .set(data, 'Text') (capital T) also fails because the check is case-sensitive against the literal 'text'.
Common situations: Developers assume nw.js mirrors Electron/Chromium's clipboard with types like 'image/png' or 'html'. Migration from Electron where clipboard.writeText/writeImage were separate calls. Case-sensitivity mistakes ('Text' vs 'text').
Related errors
- Only support getting plain text from Clipboard
- Invaild parameter, need Shortcut object.
- Menu.append() requires a valid MenuItem
- 'submenu' must be a valid Menu
- 'click' must be a valid Function
AI-assisted analysis of nwjs/nw.js@e15da848e9 (2026-08-13).
Data as JSON: /api/errors/3864de09153bf9a9.
Report an issue: GitHub.