Hello, I need your collective knowledge
I’ve been trying for days to find a way to save an XML file to the temporary plugin folder, but it’s not working at all. I don’t care if it’s an XML file or a TXT file, and I’m flexible about the location as long as I can successfully save a dataset in the background and edit it later. Unfortunately, all my attempts so far have failed. Here’s my test plugin code for saving an XML file in the plugin folder:
HTML:
<!DOCTYPE html>
<html>
<head>
<title>XML File Creator</title>
</head>
<body>
<button id="createXmlButton">Create XML File</button>
<script src="js/main.js"></script>
</body>
</html>
JS
const { storage } = require("uxp");
const fs = storage.localFileSystem;
document.addEventListener('DOMContentLoaded', () => {
const createXmlButton = document.getElementById('createXmlButton');
createXmlButton.addEventListener('click', async () => {
try {
const pluginDataFolder = await fs.getDataFolder();
const xmlFileName = "myFile.xml";
const xmlFileContent = '<root><data>My XML Data</data></root>';
const xmlFile = await pluginDataFolder.createFile(xmlFileName, { overwrite: true });
await xmlFile.write(xmlFileContent);
//alert(`XML file successfully created and saved: ${xmlFile.nativePath}`);
} catch (error) {
console.error("Error creating or saving XML file:", error);
}
});
});
Permissions in my manifest
"manifestVersion": 5,
"requiredPermissions": {
"webview": {
"allow": "yes",
"domains": [
"https://google.com"
],
"enableMessageBridge": "localAndRemote"
},
"network": {
"domains": "all"
},
"launchProcess": {
"schemes": ["https"]
}
},
I would be grateful for any hints! <3