You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
asyncfunctionsetClipboard(text){consttype="text/plain";constblob=newBlob([text],{ type });constdata=[newClipboardItem({[type]: blob})];awaitnavigator.clipboard.write(data);}
asyncfunctionpasteImage(){try{constclipboardContents=awaitnavigator.clipboard.read();for(constitemofclipboardContents){if(!item.types.includes("image/png")){thrownewError("Clipboard does not contain PNG image data.");}constblob=awaititem.getType("image/png");destinationImage.src=URL.createObjectURL(blob);}}catch(error){log(error.message);}}
请求剪贴板写权限
asyncfunctionaskWritePermission(){try{const{ state }=awaitnavigator.permissions.query({name: "clipboard-write",});returnstate==="granted";}catch(error){returnfalse;}}
请求剪贴板读取权限
asyncfunctionaskReadPermission(){try{const{ state }=awaitnavigator.permissions.query({name: "clipboard-read",});returnstate==="granted";}catch(error){returnfalse;}}
MDN
将数据写入剪切板
从读取剪切板数据
请求剪贴板写权限
请求剪贴板读取权限
复制图片
The text was updated successfully, but these errors were encountered: