You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Chrome中clipboard.write抛出"Type application/json not supported on write"错误求助

问题原因及解决方案

Chrome的Clipboard API目前不支持写入application/json类型的剪贴板数据,这是浏览器对剪贴板写入的MIME类型限制导致的,所以你执行代码时会抛出该错误。

解决办法

改用浏览器支持的text/plain类型写入JSON内容,代码修改如下:

const json = JSON.stringify(item);
const data = [
  new ClipboardItem({'text/plain': new Blob([json], {type: 'text/plain'})})
];
await navigator.clipboard.write(data);

如果需要让粘贴数据的一方明确知道这是JSON格式,可以在内容开头添加标识,比如:

const json = `JSON:${JSON.stringify(item)}`;
const data = [
  new ClipboardItem({'text/plain': new Blob([json], {type: 'text/plain'})})
];
await navigator.clipboard.write(data);

后续读取剪贴板时,再通过前缀识别并解析JSON即可。

注:Chrome支持的剪贴板写入MIME类型包括text/plain、text/html、image/png等常见类型,application/json不在当前支持范围内。

内容的提问来源于stack exchange,提问作者fr0

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.06 00:10:51