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
<!DOCTYPE html><htmllang="en"><head><metacharset="UTF-8" /><metahttp-equiv="X-UA-Compatible" content="IE=edge" /><metaname="viewport" content="width=device-width, initial-scale=1.0" /><title>file save</title><style>#addText {
width:400px;
height:200px;
}
</style></head><body><h1>保存为本地文件并持续实时保存最新编辑的内容</h1><h4>text to save:</h4><div><textareaid="addText" name="addText">hello</textarea></div><buttononclick="saveFile()">1. start save</button><buttononclick="updateFile()">2. update</button><h4>file contents:</h4><pid="fileContent"></p><script>// https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStreamlet$textToAdd;let$fileContent;letnewHandle;constpickerOpts={types: [{description: "Text file",accept: {"text/plain": [".txt"],},},],suggestedName: "testFile",excludeAcceptAllOption: true,multiple: false,};asyncfunctionsaveFile(){// create a new handleconsole.log("showSaveFilePicker");newHandle=awaitwindow.showSaveFilePicker(pickerOpts);console.log("createWritable");// create a FileSystemWritableFileStream to write toconstwritableStream=awaitnewHandle.createWritable();updateFile();}asyncfunctiongetFileContents(){constfileData=awaitnewHandle.getFile();constres=awaitfileData.text();console.log("fileText: ",res);$fileContent.innerText=res;}asyncfunctionupdateFileContent(text){// create a FileSystemWritableFileStream to write toconstwritableStream=awaitnewHandle.createWritable();constdata=newBlob([text],{type: "text"});// write our fileawaitwritableStream.write(data);// close the file and write the contents to disk.awaitwritableStream.close();}asyncfunctionupdateFile(){consttext=$textToAdd.value;awaitupdateFileContent(text);awaitgetFileContents();}document.addEventListener("DOMContentLoaded",()=>{$textToAdd=document.getElementById("addText");$fileContent=document.getElementById("fileContent");});</script></body></html>
发散一下:可以利用这个特性进行攻击吗?
比如前端通过js改写下载文件的内容。
可以继续研究一下这个API有什么安全限制。
The text was updated successfully, but these errors were encountered:
保存为本地文件并持续实时保存最新编辑的内容
可以使用浏览器的FileSystemWritableFileStream来实现
https://developer.mozilla.org/en-US/docs/Web/API/FileSystemWritableFileStream
兼容性很不好:
思路:
发散一下:可以利用这个特性进行攻击吗?
比如前端通过js改写下载文件的内容。
可以继续研究一下这个API有什么安全限制。
The text was updated successfully, but these errors were encountered: