I am working on migrating my extension to manifest V3. My extension utilizes "window.webkitRequestFileSystem" to store blob content. Here is the code for the same:
export function writeBlob(fileName, blob, onSuccess, onFailure, appendContent) {
const fileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
if (!fileSystem) {
return;
}
navigator.webkitPersistentStorage.queryUsageAndQuota((usedBytes, grantedBytes) => {
if (grantedBytes - usedBytes < blob.size) {
window.requestFileSystem = window.requestFileSystem || window.webkitRequestFileSystem;
navigator.webkitPersistentStorage.requestQuota(grantedBytes + quotaIncreaseAmount, (newGrantedBytes) => {
writeToFileSystem(fileSystem, newGrantedBytes, fileName, blob, onSuccess, onFailure, appendContent);
}, onFailure);
} else {
writeToFileSystem(fileSystem, grantedBytes, fileName, blob, onSuccess, onFailure, appendContent);
}
});
}
function writeToFileSystem(fileSystem, grantedBytes, fileName, blob, onSuccess, onFailure, appendContent) {
fileSystem(window.PERSISTENT, grantedBytes, (fs) => {
fs.root.getFile(fileName, { create: true }, (fileEntry) => {
fileEntry.createWriter((fileWriter) => {
if (appendContent) {
fileWriter.seek(fileWriter.length);
}
let truncated = false;
fileWriter.onwrite = (e) => {
if (!truncated) {
truncated = true;
this.truncate(this.position);
onSuccess(fileEntry.toURL());
}
};
fileWriter.write(blob);
}, onFailure);
}, onFailure);
}, onFailure);
}