The Permissions API enables your application to request access to user data and resources such as email addresses, special folders (Desktop, Documents, Pictures, Videos), apps, and subdomains.
When requesting permissions, users will be prompted to grant or deny access. If a permission has already been granted, the user will not be prompted again. This provides a seamless experience while maintaining user privacy and control.
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="request-email">Request Email Access</button>
<script>
document.getElementById('request-email').addEventListener('click', async () => {
const email = await puter.perms.requestEmail();
if (email) {
puter.print(`Email: ${email}`);
} else {
puter.print('Email access denied or not available');
}
});
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="request-desktop">Request Desktop Access</button>
<script>
document.getElementById('request-desktop').addEventListener('click', async () => {
const desktopPath = await puter.perms.requestReadDesktop();
if (desktopPath) {
puter.print(`Desktop path: ${desktopPath}`);
} else {
puter.print('Desktop access denied');
}
});
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="request-documents">Request Documents Write Access</button>
<script>
document.getElementById('request-documents').addEventListener('click', async () => {
const documentsPath = await puter.perms.requestWriteDocuments();
if (documentsPath) {
puter.print(`Documents path: ${documentsPath}`);
// Now you can write to the Documents folder
await puter.fs.write(`${documentsPath}/my-file.txt`, 'Hello from Documents!');
puter.print('File written to Documents folder');
} else {
puter.print('Documents write access denied');
}
});
</script>
</body>
</html>
<html>
<body>
<script src="https://js.puter.com/v2/"></script>
<button id="request-apps">Request Apps Read Access</button>
<script>
document.getElementById('request-apps').addEventListener('click', async () => {
const granted = await puter.perms.requestReadApps();
if (granted) {
puter.print('Apps read access granted');
// Now you can list the user's apps
const apps = await puter.apps.list();
puter.print(`User has ${apps.length} apps`);
} else {
puter.print('Apps read access denied');
}
});
</script>
</body>
</html>
These permission features are supported out of the box when using Puter.js:
puter.perms.request() - Request a specific permission stringputer.perms.requestEmail() - Request access to the user's email addressputer.perms.requestReadDesktop() - Request read access to the Desktop folderputer.perms.requestWriteDesktop() - Request write access to the Desktop folderputer.perms.requestReadDocuments() - Request read access to the Documents folderputer.perms.requestWriteDocuments() - Request write access to the Documents folderputer.perms.requestReadPictures() - Request read access to the Pictures folderputer.perms.requestWritePictures() - Request write access to the Pictures folderputer.perms.requestReadVideos() - Request read access to the Videos folderputer.perms.requestWriteVideos() - Request write access to the Videos folderputer.perms.requestReadApps() - Request read access to the user's appsputer.perms.requestManageApps() - Request write (manage) access to the user's appsputer.perms.requestReadSubdomains() - Request read access to the user's subdomainsputer.perms.requestManageSubdomains() - Request write (manage) access to the user's subdomainsYou can see various Puter.js permission features in action from the following examples: