Check the bridge
Call listDevices(). If there is no response, show setup instructions instead of retrying continuously.
Developer guide · API v1
LAN Device Bridge lets websites call LAN device APIs after user approval. The website does not manage device passwords.
Copy lan-device-bridge.js into your website source and import it locally. Avoid importing directly from this domain to prevent CORS dependencies and unexpected version changes.
import { lanDeviceBridge } from './lan-device-bridge.js';
const listed = await lanDeviceBridge.listDevices();
if (!listed.ok || listed.data.length === 0) {
// Show instructions: install the extension, add a device and grant this origin access.
showBridgeHelp();
return;
}
const device = listed.data[0];
const access = await lanDeviceBridge.getAccess(device.id);
if (access.data.scope !== 'full_api') {
// Guide: click the extension icon → choose a device → Full Device API → reload.
showPermissionHelp(device.name);
return;
}
const response = await lanDeviceBridge.call({
deviceId: device.id,
method: 'GET',
path: device.vendor === 'hikvision'
? '/ISAPI/System/deviceInfo'
: '/cgi-bin/magicBox.cgi?action=getDeviceType'
});
if (!response.ok) throw new Error(response.error.message);
if (!response.data.ok) throw new Error(`Device returned HTTP ${response.data.status}`);
console.log(response.data.text);
Call listDevices(). If there is no response, show setup instructions instead of retrying continuously.
Only show devices the website is permitted to see. Store deviceId in the app configuration if needed.
Call getAccess(deviceId) before write operations. If access is missing, direct the user to the extension popup.
| Function | Result |
|---|---|
listDevices() | Devices visible to the website; excludes passwords. |
getAccess(deviceId) | Scope: none, read or full_api. |
call({ deviceId, method, path, headers, body }) | The response contains status, text and contentType. |
BRIDGE_NOT_AVAILABLE, OPERATION_NOT_ALLOWED or network errors.response.data.status; HTTP 200 does not always mean the operation succeeded.Replace the bracketed sections, then paste the prompt into your coding assistant.