Performance: Permission prompts at runtime
This affects page load speed and user interaction responsiveness by delaying script execution until permissions are granted.
if ((await Deno.permissions.query({ name: 'read', path: '/path/to/file.txt' })).state !== 'granted') { await Deno.permissions.request({ name: 'read', path: '/path/to/file.txt' }); } const data = await Deno.readTextFile('/path/to/file.txt');
const data = await Deno.readTextFile('/path/to/file.txt');
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Implicit permission request during operation | N/A | 0 | 0 | [X] Bad |
| Explicit permission request before operation | N/A | 0 | 0 | [OK] Good |
Deno.permissions.query() do in a Deno program?Deno.permissions.query()request() which asks for permission, query() only checks the status without changing it.data.txt in Deno?request() method takes an object with a name property for permission type and optional path for file-specific permission.name: "read" and path: "data.txt". Other options misuse parameters or use query instead of request.const status = await Deno.permissions.query({ name: "net" });
console.log(status.state);
If the program has not requested network permission yet, what will be printed?const permission = Deno.permissions.request({ name: "read" });
if (permission.state === "granted") {
console.log("Access allowed");
}request() method returns a Promise, so it must be awaited to get the permission status object.permission is a Promise, so accessing permission.state is invalid and causes errors.Pass the test and this pattern moves unknown