Native File System

// 目前不允许后台(sw)访问

// 老的 File and Directory Entries API:
  • 在沙盒中操作文件
  • 已被弃用
  • 可用 IndexedDB 替代


await window.chooseFileSystemEntries(); // 修改参数打开新文件,写文件后关闭时有保存窗口,需要用户手势
const file = await fileHandle.getFile();
const contents = await file.text();

async function writeFile(fileHandle, contents) {
// Create a writer (request permission if necessary).
const writer = await fileHandle.createWriter();
// Write the full length of the contents
await writer.write(0, contents);
// Close the file and write the contents to disk
await writer.close();
}