Skip to content

Commit facdf3f

Browse files
committed
enhance: add user guidance for Local Network Access permission in Chromium 142+
1 parent dbf5817 commit facdf3f

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

_articles/faq/chromium-142-local-network-access-issue.md

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,38 @@ For security reasons, it is recommended to allow only the necessary origin rathe
107107
You can optionally query Local Network Access permission at runtime.
108108
This isn’t required, but implementing a check can help you proactively notify users and provide clearer guidance if permission is missing.
109109
```javascript
110-
let status = await navigator.permissions.query({ name: "local-network-access" });
111-
console.log(status.state);
110+
// Before initializing Dynamsoft WebTWAIN (DWT), you can remind users
111+
// that Chrome may ask for Local Network Access permission.
112+
(async () => {
113+
try {
114+
const result = await navigator.permissions.query({ name: "local-network-access" });
115+
console.log(`LNA permission state: ${result.state}`);
116+
117+
const state = result.state; // 'denied', 'prompt', 'granted'
118+
119+
if (state === "denied") {
120+
const currentSite = encodeURIComponent(window.location.origin);
121+
const settingsUrl = `chrome://settings/content/siteDetails?site=${currentSite}`;
122+
console.log(`Local network access is currently denied.\n\nPlease go to:\n${settingsUrl}\nand enable 'Local network access' permission for this site.`);
123+
// Optionally show a UI guide or help link here.
124+
} else if (state === "prompt") {
125+
alert("To connect with the local scanning service, Chrome will ask for 'Local network access' permission.\n\nPlease click 'Allow' when prompted.");
126+
// Proceed to init DWT after this message.
127+
// e.g., Dynamsoft.DWT.Load() or CreateDWTObjectEx or your init DWT function
128+
} else if (state === "granted") {
129+
console.log("Local network access already granted.");
130+
// Initialize DWT or proceed directly.
131+
// e.g., Dynamsoft.DWT.Load() or CreateDWTObjectEx or your init DWT function
132+
} else {
133+
console.log("Unexpected LNA state:", state);
134+
}
135+
136+
} catch (e) {
137+
console.log("This browser does not support Chromium LNA Permissions API yet.");
138+
// Fallback: directly initialize DWT
139+
// Dynamsoft.DWT.Load() or CreateDWTObjectEx or your init DWT function
140+
}
141+
})();
112142
```
113143
If the permission is not granted, consider displaying a user-friendly message directing them to:
114144

0 commit comments

Comments
 (0)