|
426 | 426 | darkTheme: false, |
427 | 427 | uiLess: false, |
428 | 428 | title: "Webcam Tester", |
429 | | - tests: ["getUserMedia", "secureContext", "cameraPermissions", "micPermissions", "devices", "capture", "resolutions", "lighting", "otherApis"], |
| 429 | + tests: ["getUserMedia", "secureContext", "permissionsPolicy", "cameraPermissions", "micPermissions", "devices", "capture", "resolutions", "lighting", "otherApis"], |
430 | 430 | callbacks: { |
431 | 431 | onTestStart: null, |
432 | 432 | onTestComplete: null, |
|
467 | 467 | init() { |
468 | 468 | this.injectCSS(); |
469 | 469 | if (!this.config.uiLess) { |
470 | | - this.createHTML(); |
471 | | - this.bindEvents(); |
| 470 | + const elementExists = !!document.getElementById(this.containerId); |
| 471 | + const timeout = elementExists ? 0 : 1000; |
| 472 | + setTimeout(() => { |
| 473 | + this.createHTML(); |
| 474 | + this.bindEvents(); |
| 475 | + }, timeout); |
472 | 476 | } |
473 | 477 | } |
474 | 478 |
|
|
967 | 971 | const testMap = { |
968 | 972 | getUserMedia: () => this.testGetUserMedia(), |
969 | 973 | secureContext: () => this.testSecureContext(), |
| 974 | + permissionsPolicy: () => this.testPermissionsPolicy(), |
970 | 975 | cameraPermissions: () => this.testCameraPermissions(), |
971 | 976 | micPermissions: () => this.testMicPermissions(), |
972 | 977 | devices: () => this.testDeviceEnumeration(), |
|
1015 | 1020 | } |
1016 | 1021 | } |
1017 | 1022 |
|
| 1023 | + async testPermissionsPolicy() { |
| 1024 | + this.setLoadingState("Checking permissions policy..."); |
| 1025 | + await this.sleep(400); |
| 1026 | + |
| 1027 | + const policies = []; |
| 1028 | + const policyResults = []; |
| 1029 | + let hasIssues = false; |
| 1030 | + |
| 1031 | + // Check if Permissions Policy API is supported |
| 1032 | + if (!document.featurePolicy && !document.permissionsPolicy) { |
| 1033 | + this.addTestResult("permissionsPolicy", "⚠️", "Permissions Policy API not supported in this browser", "warning"); |
| 1034 | + return; |
| 1035 | + } |
| 1036 | + |
| 1037 | + const policy = document.permissionsPolicy || document.featurePolicy; |
| 1038 | + |
| 1039 | + // Check camera policy |
| 1040 | + try { |
| 1041 | + const cameraAllowed = policy.allowsFeature("camera"); |
| 1042 | + if (cameraAllowed) { |
| 1043 | + policies.push("Camera allowed"); |
| 1044 | + policyResults.push({ name: "camera", allowed: true }); |
| 1045 | + } else { |
| 1046 | + policies.push("Camera blocked by policy"); |
| 1047 | + policyResults.push({ name: "camera", allowed: false }); |
| 1048 | + hasIssues = true; |
| 1049 | + } |
| 1050 | + } catch (error) { |
| 1051 | + policyResults.push({ name: "camera", allowed: null, error: true }); |
| 1052 | + } |
| 1053 | + |
| 1054 | + // Check microphone policy |
| 1055 | + try { |
| 1056 | + const micAllowed = policy.allowsFeature("microphone"); |
| 1057 | + if (micAllowed) { |
| 1058 | + policies.push("Microphone allowed"); |
| 1059 | + policyResults.push({ name: "microphone", allowed: true }); |
| 1060 | + } else { |
| 1061 | + policies.push("Microphone blocked by policy"); |
| 1062 | + policyResults.push({ name: "microphone", allowed: false }); |
| 1063 | + hasIssues = true; |
| 1064 | + } |
| 1065 | + } catch (error) { |
| 1066 | + policyResults.push({ name: "microphone", allowed: false, error: true }); |
| 1067 | + } |
| 1068 | + |
| 1069 | + // Check display-capture (screen sharing) policy |
| 1070 | + // try { |
| 1071 | + // const displayCaptureAllowed = policy.allowsFeature("display-capture"); |
| 1072 | + // if (displayCaptureAllowed) { |
| 1073 | + // policies.push("Screen capture allowed"); |
| 1074 | + // policyResults.push({ name: "display-capture", allowed: true }); |
| 1075 | + // } else { |
| 1076 | + // policyResults.push({ name: "display-capture", allowed: false }); |
| 1077 | + // } |
| 1078 | + // } catch (error) { |
| 1079 | + // policyResults.push({ name: "display-capture", allowed: null, error: true }); |
| 1080 | + // } |
| 1081 | + |
| 1082 | + // Create detailed policy info for expandable section |
| 1083 | + let policyInfo = "<div><strong>Feature Policies:</strong></div>"; |
| 1084 | + policyResults.forEach((result) => { |
| 1085 | + let status = "❓"; |
| 1086 | + let statusText = "Unknown"; |
| 1087 | + |
| 1088 | + if (result.error) { |
| 1089 | + status = "⚠️"; |
| 1090 | + statusText = "Unable to check"; |
| 1091 | + } else if (result.allowed === true) { |
| 1092 | + status = "✅"; |
| 1093 | + statusText = "Allowed"; |
| 1094 | + } else if (result.allowed === false) { |
| 1095 | + status = "❌"; |
| 1096 | + statusText = "Blocked by policy"; |
| 1097 | + } |
| 1098 | + |
| 1099 | + policyInfo += `<div class="capability-item"><span class="capability-status">${status}</span>${result.name}: ${statusText}</div>`; |
| 1100 | + }); |
| 1101 | + |
| 1102 | + // Determine result type and message |
| 1103 | + if (hasIssues) { |
| 1104 | + this.addTestResult("permissionsPolicy", "⚠️", "Some features blocked by Permissions Policy", "warning", `Policies: ${policies.join(", ")}`, true, policyInfo); |
| 1105 | + } else { |
| 1106 | + this.addTestResult("permissionsPolicy", "✅", "Camera & Microphone allowed by Permissions Policy", "success", `Policies: ${policies.join(", ")}`, true, policyInfo); |
| 1107 | + } |
| 1108 | + } |
| 1109 | + |
1018 | 1110 | async testCameraPermissions() { |
1019 | 1111 | this.setLoadingState("Requesting camera permissions..."); |
1020 | 1112 |
|
|
1418 | 1510 | const testMap = { |
1419 | 1511 | getUserMedia: () => this.testGetUserMedia(), |
1420 | 1512 | secureContext: () => this.testSecureContext(), |
| 1513 | + permissionsPolicy: () => this.testPermissionsPolicy(), |
1421 | 1514 | cameraPermissions: () => this.testCameraPermissions(), |
1422 | 1515 | micPermissions: () => this.testMicPermissions(), |
1423 | 1516 | devices: () => this.testDeviceEnumeration(), |
|
0 commit comments