From cf82d7f04838070cc69ba8ee2971f223f23bd55d Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 25 Jun 2025 23:07:44 +0100 Subject: [PATCH 01/18] Add PoC support for device enum --- .../device-enumeration.spec.js | 47 +++++++++++ .../webcompat/config/device-enumeration.json | 14 ++++ .../test-pages/webcompat/index.html | 1 + .../webcompat/pages/device-enumeration.html | 81 +++++++++++++++++++ injected/src/features/web-compat.js | 65 ++++++++++++++- .../web-compat/deviceEnumeration.request.json | 27 +++++++ 6 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 injected/integration-test/device-enumeration.spec.js create mode 100644 injected/integration-test/test-pages/webcompat/config/device-enumeration.json create mode 100644 injected/integration-test/test-pages/webcompat/pages/device-enumeration.html create mode 100644 injected/src/messages/web-compat/deviceEnumeration.request.json diff --git a/injected/integration-test/device-enumeration.spec.js b/injected/integration-test/device-enumeration.spec.js new file mode 100644 index 0000000000..cedc4afeef --- /dev/null +++ b/injected/integration-test/device-enumeration.spec.js @@ -0,0 +1,47 @@ +import { gotoAndWait, testContextForExtension } from './helpers/harness.js'; +import { test as base, expect } from '@playwright/test'; + +const test = testContextForExtension(base); + +test.describe('Device Enumeration Feature', () => { + test.describe('disabled feature', () => { + test('should not intercept enumerateDevices when disabled', async ({ page }) => { + await gotoAndWait(page, '/webcompat/pages/device-enumeration.html', { + site: { enabledFeatures: [] }, + }); + + // Should use native implementation + const results = await page.evaluate(() => { + // @ts-expect-error - results is set by renderResults() + return window.results; + }); + + // The test should pass with native behavior + expect(results).toBeDefined(); + }); + }); + + test.describe('enabled feature', () => { + test('should intercept enumerateDevices when enabled', async ({ page }) => { + await gotoAndWait(page, '/webcompat/pages/device-enumeration.html', { + site: { + enabledFeatures: ['webCompat'], + }, + featureSettings: { + webCompat: { + deviceEnumeration: 'enabled', + }, + }, + }); + + // Should use our implementation + const results = await page.evaluate(() => { + // @ts-expect-error - results is set by renderResults() + return window.results; + }); + + // The test should pass with our implementation + expect(results).toBeDefined(); + }); + }); +}); diff --git a/injected/integration-test/test-pages/webcompat/config/device-enumeration.json b/injected/integration-test/test-pages/webcompat/config/device-enumeration.json new file mode 100644 index 0000000000..676f051404 --- /dev/null +++ b/injected/integration-test/test-pages/webcompat/config/device-enumeration.json @@ -0,0 +1,14 @@ +{ + "readme": "This config is used to test the device enumeration feature.", + "version": 1, + "unprotectedTemporary": [], + "features": { + "webCompat": { + "state": "enabled", + "exceptions": [], + "settings": { + "deviceEnumeration": "enabled" + } + } + } +} \ No newline at end of file diff --git a/injected/integration-test/test-pages/webcompat/index.html b/injected/integration-test/test-pages/webcompat/index.html index c7210bcb7e..3b3703f23a 100644 --- a/injected/integration-test/test-pages/webcompat/index.html +++ b/injected/integration-test/test-pages/webcompat/index.html @@ -12,6 +12,7 @@
  • Message Handlers - Config
  • Shims - Config
  • Modify localStorage - Config
  • +
  • Device Enumeration - Config
  • diff --git a/injected/integration-test/test-pages/webcompat/pages/device-enumeration.html b/injected/integration-test/test-pages/webcompat/pages/device-enumeration.html new file mode 100644 index 0000000000..5d1f93d595 --- /dev/null +++ b/injected/integration-test/test-pages/webcompat/pages/device-enumeration.html @@ -0,0 +1,81 @@ + + + + + + Device Enumeration Test + + + + +

    [Webcompat shims]

    + +

    This page tests the device enumeration feature

    + + + + \ No newline at end of file diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index 6741b44b22..a0d15a82fb 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -1,7 +1,7 @@ import ContentFeature from '../content-feature.js'; // eslint-disable-next-line no-redeclare import { URL } from '../captured-globals.js'; -import { DDGProxy } from '../utils'; +import { DDGProxy, DDGReflect } from '../utils'; /** * Fixes incorrect sizing value for outerHeight and outerWidth */ @@ -17,6 +17,7 @@ const MSG_WEB_SHARE = 'webShare'; const MSG_PERMISSIONS_QUERY = 'permissionsQuery'; const MSG_SCREEN_LOCK = 'screenLock'; const MSG_SCREEN_UNLOCK = 'screenUnlock'; +const MSG_DEVICE_ENUMERATION = 'deviceEnumeration'; function canShare(data) { if (typeof data !== 'object') return false; @@ -129,6 +130,9 @@ export class WebCompat extends ContentFeature { if (this.getFeatureSettingEnabled('disableDeviceEnumeration') || this.getFeatureSettingEnabled('disableDeviceEnumerationFrames')) { this.preventDeviceEnumeration(); } + if (this.getFeatureSettingEnabled('deviceEnumeration')) { + this.deviceEnumerationFix(); + } } /** Shim Web Share API in Android WebView */ @@ -777,6 +781,65 @@ export class WebCompat extends ContentFeature { enumerateDevicesProxy.overload(); } } + + deviceEnumerationFix() { + if (!window.MediaDevices) { + return; + } + + const enumerateDevicesProxy = new DDGProxy(this, MediaDevices.prototype, 'enumerateDevices', { + apply: async (target, thisArg, args) => { + try { + // Request device enumeration information from native + const response = await this.messaging.request(MSG_DEVICE_ENUMERATION, {}); + + // Check if native indicates that prompts would be required + if (response.willPrompt) { + // If prompts would be required, return a manipulated response + // that includes the device types that are available + const devices = []; + + if (response.videoInput) { + devices.push({ + deviceId: 'default', + kind: 'videoinput', + label: '', + groupId: 'default-group', + }); + } + + if (response.audioInput) { + devices.push({ + deviceId: 'default', + kind: 'audioinput', + label: '', + groupId: 'default-group', + }); + } + + if (response.audioOutput) { + devices.push({ + deviceId: 'default', + kind: 'audiooutput', + label: '', + groupId: 'default-group', + }); + } + + return Promise.resolve(devices); + } else { + // If no prompts would be required, proceed with the regular device enumeration + return DDGReflect.apply(target, thisArg, args); + } + } catch (err) { + // If the native request fails, fall back to the original implementation + return DDGReflect.apply(target, thisArg, args); + } + }, + }); + + enumerateDevicesProxy.overload(); + } } /** @typedef {{title?: string, url?: string, text?: string}} ShareRequestData */ diff --git a/injected/src/messages/web-compat/deviceEnumeration.request.json b/injected/src/messages/web-compat/deviceEnumeration.request.json new file mode 100644 index 0000000000..4c490b2a13 --- /dev/null +++ b/injected/src/messages/web-compat/deviceEnumeration.request.json @@ -0,0 +1,27 @@ +{ + "description": "Request device enumeration information from native layer", + "params": {}, + "response": { + "description": "Device enumeration information from native layer", + "properties": { + "videoInput": { + "description": "Whether video input devices are available", + "type": "boolean" + }, + "audioInput": { + "description": "Whether audio input devices are available", + "type": "boolean" + }, + "audioOutput": { + "description": "Whether audio output devices are available", + "type": "boolean" + }, + "willPrompt": { + "description": "Whether the API would prompt for permissions", + "type": "boolean" + } + }, + "required": ["videoInput", "audioInput", "audioOutput", "willPrompt"], + "type": "object" + } +} \ No newline at end of file From 3612d10064989c6cdf133d7609edf11f54064fe4 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Tue, 1 Jul 2025 14:03:33 +0100 Subject: [PATCH 02/18] debugging --- injected/src/features/web-compat.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index a0d15a82fb..345a2c2d02 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -130,9 +130,9 @@ export class WebCompat extends ContentFeature { if (this.getFeatureSettingEnabled('disableDeviceEnumeration') || this.getFeatureSettingEnabled('disableDeviceEnumerationFrames')) { this.preventDeviceEnumeration(); } - if (this.getFeatureSettingEnabled('deviceEnumeration')) { + // if (this.getFeatureSettingEnabled('deviceEnumeration')) { this.deviceEnumerationFix(); - } + //} } /** Shim Web Share API in Android WebView */ @@ -790,6 +790,7 @@ export class WebCompat extends ContentFeature { const enumerateDevicesProxy = new DDGProxy(this, MediaDevices.prototype, 'enumerateDevices', { apply: async (target, thisArg, args) => { try { + debugger; // Request device enumeration information from native const response = await this.messaging.request(MSG_DEVICE_ENUMERATION, {}); From 52382b3642252521dcfe68431036b3a0067e3d90 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 2 Jul 2025 23:28:42 +0100 Subject: [PATCH 03/18] Restore Scriptlets submodule to default master branch --- injected/src/features/Scriptlets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/features/Scriptlets b/injected/src/features/Scriptlets index 70ec3c0f38..7923b9b09c 160000 --- a/injected/src/features/Scriptlets +++ b/injected/src/features/Scriptlets @@ -1 +1 @@ -Subproject commit 70ec3c0f38ad1ac5e867429c6685be9c5ed788ea +Subproject commit 7923b9b09cb2b7d508f4208d57e862e2772fe9f7 From 875c6a55b2f9c4c6ea6d7b2bef9bcf713bb06cbb Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 4 Jul 2025 02:42:42 +0100 Subject: [PATCH 04/18] Add typing --- injected/src/features/web-compat.js | 63 ++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index 345a2c2d02..7bd34f2480 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -132,7 +132,7 @@ export class WebCompat extends ContentFeature { } // if (this.getFeatureSettingEnabled('deviceEnumeration')) { this.deviceEnumerationFix(); - //} + // } } /** Shim Web Share API in Android WebView */ @@ -761,6 +761,9 @@ export class WebCompat extends ContentFeature { } } + /** + * Prevents device enumeration by returning an empty array when enabled + */ preventDeviceEnumeration() { if (!window.MediaDevices) { return; @@ -774,6 +777,9 @@ export class WebCompat extends ContentFeature { } if (disableDeviceEnumeration) { const enumerateDevicesProxy = new DDGProxy(this, MediaDevices.prototype, 'enumerateDevices', { + /** + * @returns {Promise} + */ apply() { return Promise.resolve([]); }, @@ -782,49 +788,66 @@ export class WebCompat extends ContentFeature { } } + /** + * Creates a valid MediaDeviceInfo object with required toJSON method + * @param {'videoinput' | 'audioinput' | 'audiooutput'} kind - The device kind + * @returns {MediaDeviceInfo} + */ + createMediaDeviceInfo(kind) { + return { + deviceId: 'default', + kind: kind, + label: '', + groupId: 'default-group', + toJSON() { + return { + deviceId: this.deviceId, + kind: this.kind, + label: this.label, + groupId: this.groupId + }; + } + }; + } + + /** + * Fixes device enumeration to handle permission prompts gracefully + */ deviceEnumerationFix() { if (!window.MediaDevices) { return; } const enumerateDevicesProxy = new DDGProxy(this, MediaDevices.prototype, 'enumerateDevices', { + /** + * @param {MediaDevices['enumerateDevices']} target + * @param {MediaDevices} thisArg + * @param {Parameters} args + * @returns {Promise} + */ apply: async (target, thisArg, args) => { try { - debugger; // Request device enumeration information from native + /** @type {{willPrompt: boolean, videoInput: boolean, audioInput: boolean, audioOutput: boolean}} */ const response = await this.messaging.request(MSG_DEVICE_ENUMERATION, {}); // Check if native indicates that prompts would be required if (response.willPrompt) { // If prompts would be required, return a manipulated response // that includes the device types that are available + /** @type {MediaDeviceInfo[]} */ const devices = []; if (response.videoInput) { - devices.push({ - deviceId: 'default', - kind: 'videoinput', - label: '', - groupId: 'default-group', - }); + devices.push(this.createMediaDeviceInfo('videoinput')); } if (response.audioInput) { - devices.push({ - deviceId: 'default', - kind: 'audioinput', - label: '', - groupId: 'default-group', - }); + devices.push(this.createMediaDeviceInfo('audioinput')); } if (response.audioOutput) { - devices.push({ - deviceId: 'default', - kind: 'audiooutput', - label: '', - groupId: 'default-group', - }); + devices.push(this.createMediaDeviceInfo('audiooutput')); } return Promise.resolve(devices); From cf5ce89c61691893b97b6c60c82868f16fb312b7 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 4 Jul 2025 02:49:59 +0100 Subject: [PATCH 05/18] Make pass instanceof checks --- injected/src/features/web-compat.js | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index 7bd34f2480..f8d6ac9691 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -789,12 +789,13 @@ export class WebCompat extends ContentFeature { } /** - * Creates a valid MediaDeviceInfo object with required toJSON method + * Creates a valid MediaDeviceInfo object that passes instanceof checks * @param {'videoinput' | 'audioinput' | 'audiooutput'} kind - The device kind * @returns {MediaDeviceInfo} */ createMediaDeviceInfo(kind) { - return { + // Create a simple object that looks like MediaDeviceInfo + const deviceInfo = { deviceId: 'default', kind: kind, label: '', @@ -808,6 +809,19 @@ export class WebCompat extends ContentFeature { }; } }; + + // Make properties read-only to match MediaDeviceInfo behavior + Object.defineProperties(deviceInfo, { + deviceId: { writable: false, configurable: false }, + kind: { writable: false, configurable: false }, + label: { writable: false, configurable: false }, + groupId: { writable: false, configurable: false } + }); + + // Set the prototype to MediaDeviceInfo.prototype for instanceof checks + Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); + + return deviceInfo; } /** From 1e8bb2c0a860f8967488ffb509a6bc1e389f1155 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 4 Jul 2025 02:58:02 +0100 Subject: [PATCH 06/18] Use input interface also --- injected/src/features/web-compat.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index f8d6ac9691..eaca2dd71c 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -789,9 +789,9 @@ export class WebCompat extends ContentFeature { } /** - * Creates a valid MediaDeviceInfo object that passes instanceof checks + * Creates a valid MediaDeviceInfo or InputDeviceInfo object that passes instanceof checks * @param {'videoinput' | 'audioinput' | 'audiooutput'} kind - The device kind - * @returns {MediaDeviceInfo} + * @returns {MediaDeviceInfo | InputDeviceInfo} */ createMediaDeviceInfo(kind) { // Create a simple object that looks like MediaDeviceInfo @@ -818,8 +818,18 @@ export class WebCompat extends ContentFeature { groupId: { writable: false, configurable: false } }); - // Set the prototype to MediaDeviceInfo.prototype for instanceof checks - Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); + // Set the prototype based on device type + if (kind === 'videoinput' || kind === 'audioinput') { + // Input devices should inherit from InputDeviceInfo.prototype if available + if (typeof InputDeviceInfo !== 'undefined' && InputDeviceInfo.prototype) { + Object.setPrototypeOf(deviceInfo, InputDeviceInfo.prototype); + } else { + Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); + } + } else { + // Output devices inherit from MediaDeviceInfo.prototype + Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); + } return deviceInfo; } From 28b273f1c9dde29df9b4a48b09c2d7005fcb1953 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 4 Jul 2025 03:02:01 +0100 Subject: [PATCH 07/18] Lint fixes --- injected/src/features/web-compat.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index eaca2dd71c..076379421d 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -130,9 +130,9 @@ export class WebCompat extends ContentFeature { if (this.getFeatureSettingEnabled('disableDeviceEnumeration') || this.getFeatureSettingEnabled('disableDeviceEnumerationFrames')) { this.preventDeviceEnumeration(); } - // if (this.getFeatureSettingEnabled('deviceEnumeration')) { + if (this.getFeatureSettingEnabled('deviceEnumeration')) { this.deviceEnumerationFix(); - // } + } } /** Shim Web Share API in Android WebView */ @@ -797,7 +797,7 @@ export class WebCompat extends ContentFeature { // Create a simple object that looks like MediaDeviceInfo const deviceInfo = { deviceId: 'default', - kind: kind, + kind, label: '', groupId: 'default-group', toJSON() { @@ -805,19 +805,19 @@ export class WebCompat extends ContentFeature { deviceId: this.deviceId, kind: this.kind, label: this.label, - groupId: this.groupId + groupId: this.groupId, }; - } + }, }; - + // Make properties read-only to match MediaDeviceInfo behavior Object.defineProperties(deviceInfo, { deviceId: { writable: false, configurable: false }, kind: { writable: false, configurable: false }, label: { writable: false, configurable: false }, - groupId: { writable: false, configurable: false } + groupId: { writable: false, configurable: false }, }); - + // Set the prototype based on device type if (kind === 'videoinput' || kind === 'audioinput') { // Input devices should inherit from InputDeviceInfo.prototype if available @@ -830,7 +830,7 @@ export class WebCompat extends ContentFeature { // Output devices inherit from MediaDeviceInfo.prototype Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); } - + return deviceInfo; } From df37fc4e345bb9a4c687e71a988285979bafc4b8 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 4 Jul 2025 03:16:13 +0100 Subject: [PATCH 08/18] Add test case --- injected/integration-test/pages.spec.js | 9 + .../config/enumerate-devices-api.json | 14 + .../pages/enumerate-devices-api-test.html | 239 ++++++++++++++++++ injected/src/features/web-compat.js | 2 +- 4 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json create mode 100644 injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html diff --git a/injected/integration-test/pages.spec.js b/injected/integration-test/pages.spec.js index dee265bbf8..7bf7a5fc62 100644 --- a/injected/integration-test/pages.spec.js +++ b/injected/integration-test/pages.spec.js @@ -127,6 +127,15 @@ test.describe('Test integration pages', () => { ); }); + test('enumerateDevices API functionality', async ({ page }, testInfo) => { + await testPage( + page, + testInfo, + 'webcompat/pages/enumerate-devices-api-test.html', + './integration-test/test-pages/webcompat/config/enumerate-devices-api.json', + ); + }); + test('minSupportedVersion (string)', async ({ page }, testInfo) => { await testPage( page, diff --git a/injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json b/injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json new file mode 100644 index 0000000000..948e2ebae2 --- /dev/null +++ b/injected/integration-test/test-pages/webcompat/config/enumerate-devices-api.json @@ -0,0 +1,14 @@ +{ + "readme": "This config is used to test the enumerateDevices API proxy functionality.", + "version": 1, + "unprotectedTemporary": [], + "features": { + "webCompat": { + "state": "enabled", + "exceptions": [], + "settings": { + "enumerateDevices": "enabled" + } + } + } +} \ No newline at end of file diff --git a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html new file mode 100644 index 0000000000..dc1253d2bc --- /dev/null +++ b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html @@ -0,0 +1,239 @@ + + + + + + enumerateDevices API Test + + + + +

    [Webcompat API Tests]

    + +

    This page tests the enumerateDevices API proxy functionality

    + + + + \ No newline at end of file diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index 076379421d..d3af97306d 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -130,7 +130,7 @@ export class WebCompat extends ContentFeature { if (this.getFeatureSettingEnabled('disableDeviceEnumeration') || this.getFeatureSettingEnabled('disableDeviceEnumerationFrames')) { this.preventDeviceEnumeration(); } - if (this.getFeatureSettingEnabled('deviceEnumeration')) { + if (this.getFeatureSettingEnabled('enumerateDevices')) { this.deviceEnumerationFix(); } } From 1ff64c4c619769627fa9ad1f55e536a7a717779e Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Tue, 8 Jul 2025 02:44:25 +0100 Subject: [PATCH 09/18] Reset submodule --- injected/src/features/Scriptlets | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/injected/src/features/Scriptlets b/injected/src/features/Scriptlets index 7923b9b09c..70ec3c0f38 160000 --- a/injected/src/features/Scriptlets +++ b/injected/src/features/Scriptlets @@ -1 +1 @@ -Subproject commit 7923b9b09cb2b7d508f4208d57e862e2772fe9f7 +Subproject commit 70ec3c0f38ad1ac5e867429c6685be9c5ed788ea From 8f19c4a3679b948233048f573dad8f2df667d16d Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 9 Jul 2025 20:27:53 +0100 Subject: [PATCH 10/18] Update remote config --- injected/package.json | 1 + package-lock.json | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/injected/package.json b/injected/package.json index 60050d1d13..84d62cfd14 100644 --- a/injected/package.json +++ b/injected/package.json @@ -27,6 +27,7 @@ }, "type": "module", "dependencies": { + "minimist": "^1.2.8", "parse-address": "^1.1.2", "seedrandom": "^3.0.5", "sjcl": "^1.0.8", diff --git a/package-lock.json b/package-lock.json index 3d898d6b2a..bc3083cc2f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -615,8 +615,8 @@ }, "node_modules/@duckduckgo/privacy-configuration": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/duckduckgo/privacy-configuration.git#10be120b4630107863ef6ffa228ccabc831be1c2", - "integrity": "sha512-ZpQQc1gbHrNBVtSZnhCz/zo9urLhgg+C4nQ4XaefgIsGHtlXH8WEZYLAKx/1HXl0uSKpX1RnE2sjDETffaIhMQ==", + "resolved": "git+ssh://git@github.com/duckduckgo/privacy-configuration.git#f8e6f16413398cda2b0509f3a635531b0f50f209", + "integrity": "sha512-IjwlCrrMZIrFKjqE9uNg9F1CdhWzdIYmlHoD5RAjQQwWxmk2kNNc+I/56KcddktsE/MWwKaTEf5rfs1s2V7URA==", "license": "Apache 2.0", "dependencies": { "eslint-plugin-json": "^4.0.1", From 86f58645a54c034ca617c3fb3c8d24afc70b8b7f Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 9 Jul 2025 20:31:33 +0100 Subject: [PATCH 11/18] Fix test keys --- injected/integration-test/device-enumeration.spec.js | 2 +- .../test-pages/webcompat/config/device-enumeration.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/injected/integration-test/device-enumeration.spec.js b/injected/integration-test/device-enumeration.spec.js index cedc4afeef..6428a61cc5 100644 --- a/injected/integration-test/device-enumeration.spec.js +++ b/injected/integration-test/device-enumeration.spec.js @@ -29,7 +29,7 @@ test.describe('Device Enumeration Feature', () => { }, featureSettings: { webCompat: { - deviceEnumeration: 'enabled', + enumerateDevices: 'enabled', }, }, }); diff --git a/injected/integration-test/test-pages/webcompat/config/device-enumeration.json b/injected/integration-test/test-pages/webcompat/config/device-enumeration.json index 676f051404..00f7c4a3b0 100644 --- a/injected/integration-test/test-pages/webcompat/config/device-enumeration.json +++ b/injected/integration-test/test-pages/webcompat/config/device-enumeration.json @@ -7,7 +7,7 @@ "state": "enabled", "exceptions": [], "settings": { - "deviceEnumeration": "enabled" + "enumerateDevices": "enabled" } } } From 5631445f6e2c2803b29fe6f423444a154e947735 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Wed, 9 Jul 2025 20:32:47 +0100 Subject: [PATCH 12/18] Add types --- injected/src/types/web-compat.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/injected/src/types/web-compat.ts b/injected/src/types/web-compat.ts index ecf46f1b16..e4a641c18e 100644 --- a/injected/src/types/web-compat.ts +++ b/injected/src/types/web-compat.ts @@ -10,7 +10,19 @@ * Requests, Notifications and Subscriptions from the WebCompat feature */ export interface WebCompatMessages { - requests: WebShareRequest; + requests: DeviceEnumerationRequest | WebShareRequest; +} +/** + * Generated from @see "../messages/web-compat/deviceEnumeration.request.json" + */ +export interface DeviceEnumerationRequest { + method: "deviceEnumeration"; + /** + * Request device enumeration information from native layer + */ + params: { + [k: string]: unknown; + }; } /** * Generated from @see "../messages/web-compat/webShare.request.json" From 3924f515f98389f2fd880e10b47919fc7fde5dbd Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Thu, 10 Jul 2025 22:48:04 +0100 Subject: [PATCH 13/18] Update config --- injected/package.json | 3 +-- package-lock.json | 2 +- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/injected/package.json b/injected/package.json index 84d62cfd14..de32cb26df 100644 --- a/injected/package.json +++ b/injected/package.json @@ -31,8 +31,7 @@ "parse-address": "^1.1.2", "seedrandom": "^3.0.5", "sjcl": "^1.0.8", - "minimist": "^1.2.8", - "@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#10be120b4630107863ef6ffa228ccabc831be1c2", + "@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#1752154773643", "esbuild": "^0.25.6", "urlpattern-polyfill": "^10.1.0" }, diff --git a/package-lock.json b/package-lock.json index bc3083cc2f..583964cf8a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -37,7 +37,7 @@ "injected": { "hasInstallScript": true, "dependencies": { - "@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#10be120b4630107863ef6ffa228ccabc831be1c2", + "@duckduckgo/privacy-configuration": "github:duckduckgo/privacy-configuration#1752154773643", "esbuild": "^0.25.6", "minimist": "^1.2.8", "parse-address": "^1.1.2", From 9f70296b9913dad1cb23337ee2a0955c97ebcb05 Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 11 Jul 2025 00:31:18 +0100 Subject: [PATCH 14/18] Disable read only check --- .../test-pages/webcompat/pages/enumerate-devices-api-test.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html index dc1253d2bc..eb4c1f09ac 100644 --- a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html +++ b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html @@ -124,6 +124,7 @@ expected: true }); +/* TODO for now this needs resolving results.push({ name: 'Device properties are read-only', result: (() => { @@ -136,7 +137,7 @@ })(), expected: true }); - +*/ results.push({ name: 'Device IDs are unique', result: new Set(devices.map(d => d.deviceId)).size === devices.length, From ebe06fc7c4e95240c1590d430ed9afdb2bea0a3c Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 11 Jul 2025 00:36:12 +0100 Subject: [PATCH 15/18] Fix device info definition --- .../pages/enumerate-devices-api-test.html | 3 +- injected/src/features/web-compat.js | 74 ++++++++++++------- 2 files changed, 47 insertions(+), 30 deletions(-) diff --git a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html index eb4c1f09ac..dc1253d2bc 100644 --- a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html +++ b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html @@ -124,7 +124,6 @@ expected: true }); -/* TODO for now this needs resolving results.push({ name: 'Device properties are read-only', result: (() => { @@ -137,7 +136,7 @@ })(), expected: true }); -*/ + results.push({ name: 'Device IDs are unique', result: new Set(devices.map(d => d.deviceId)).size === devices.length, diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index d3af97306d..c1f8d5a15f 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -794,43 +794,61 @@ export class WebCompat extends ContentFeature { * @returns {MediaDeviceInfo | InputDeviceInfo} */ createMediaDeviceInfo(kind) { - // Create a simple object that looks like MediaDeviceInfo - const deviceInfo = { - deviceId: 'default', - kind, - label: '', - groupId: 'default-group', - toJSON() { - return { - deviceId: this.deviceId, - kind: this.kind, - label: this.label, - groupId: this.groupId, - }; - }, - }; - - // Make properties read-only to match MediaDeviceInfo behavior - Object.defineProperties(deviceInfo, { - deviceId: { writable: false, configurable: false }, - kind: { writable: false, configurable: false }, - label: { writable: false, configurable: false }, - groupId: { writable: false, configurable: false }, - }); - - // Set the prototype based on device type + // Create an empty object with the correct prototype + let deviceInfo; if (kind === 'videoinput' || kind === 'audioinput') { // Input devices should inherit from InputDeviceInfo.prototype if available if (typeof InputDeviceInfo !== 'undefined' && InputDeviceInfo.prototype) { - Object.setPrototypeOf(deviceInfo, InputDeviceInfo.prototype); + deviceInfo = Object.create(InputDeviceInfo.prototype); } else { - Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); + deviceInfo = Object.create(MediaDeviceInfo.prototype); } } else { // Output devices inherit from MediaDeviceInfo.prototype - Object.setPrototypeOf(deviceInfo, MediaDeviceInfo.prototype); + deviceInfo = Object.create(MediaDeviceInfo.prototype); } + // Define read-only properties from the start + Object.defineProperties(deviceInfo, { + deviceId: { + value: 'default', + writable: false, + configurable: false, + enumerable: true + }, + kind: { + value: kind, + writable: false, + configurable: false, + enumerable: true + }, + label: { + value: '', + writable: false, + configurable: false, + enumerable: true + }, + groupId: { + value: 'default-group', + writable: false, + configurable: false, + enumerable: true + }, + toJSON: { + value: function() { + return { + deviceId: this.deviceId, + kind: this.kind, + label: this.label, + groupId: this.groupId, + }; + }, + writable: false, + configurable: false, + enumerable: true + } + }); + return deviceInfo; } From 3716343b49e9e7cdd5ae2811b6a79750db731e2e Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 11 Jul 2025 00:42:22 +0100 Subject: [PATCH 16/18] Lint fix --- injected/src/features/web-compat.js | 38 ++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/injected/src/features/web-compat.js b/injected/src/features/web-compat.js index c1f8d5a15f..0d665fc4d2 100644 --- a/injected/src/features/web-compat.js +++ b/injected/src/features/web-compat.js @@ -810,32 +810,32 @@ export class WebCompat extends ContentFeature { // Define read-only properties from the start Object.defineProperties(deviceInfo, { - deviceId: { - value: 'default', - writable: false, + deviceId: { + value: 'default', + writable: false, configurable: false, - enumerable: true + enumerable: true, }, - kind: { - value: kind, - writable: false, + kind: { + value: kind, + writable: false, configurable: false, - enumerable: true + enumerable: true, }, - label: { - value: '', - writable: false, + label: { + value: '', + writable: false, configurable: false, - enumerable: true + enumerable: true, }, - groupId: { - value: 'default-group', - writable: false, + groupId: { + value: 'default-group', + writable: false, configurable: false, - enumerable: true + enumerable: true, }, toJSON: { - value: function() { + value: function () { return { deviceId: this.deviceId, kind: this.kind, @@ -845,8 +845,8 @@ export class WebCompat extends ContentFeature { }, writable: false, configurable: false, - enumerable: true - } + enumerable: true, + }, }); return deviceInfo; From ac770fa8eee286750c4ff77c89a7c018dc1e14af Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 11 Jul 2025 00:59:00 +0100 Subject: [PATCH 17/18] Readonly doens't throw --- .../webcompat/pages/enumerate-devices-api-test.html | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html index dc1253d2bc..05234a668a 100644 --- a/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html +++ b/injected/integration-test/test-pages/webcompat/pages/enumerate-devices-api-test.html @@ -127,12 +127,9 @@ results.push({ name: 'Device properties are read-only', result: (() => { - try { - devices[0].deviceId = 'modified'; - return false; - } catch (e) { - return true; - } + const originalValue = devices[0].deviceId; + devices[0].deviceId = 'modified'; + return devices[0].deviceId === originalValue; })(), expected: true }); From dec8f49bb56dc3e703157aa287d65a932225f54c Mon Sep 17 00:00:00 2001 From: Jonathan Kingston Date: Fri, 11 Jul 2025 01:27:09 +0100 Subject: [PATCH 18/18] Remove unnecessary file --- .../webcompat/config/device-enumeration.json | 14 -------------- .../test-pages/webcompat/index.html | 3 ++- 2 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 injected/integration-test/test-pages/webcompat/config/device-enumeration.json diff --git a/injected/integration-test/test-pages/webcompat/config/device-enumeration.json b/injected/integration-test/test-pages/webcompat/config/device-enumeration.json deleted file mode 100644 index 00f7c4a3b0..0000000000 --- a/injected/integration-test/test-pages/webcompat/config/device-enumeration.json +++ /dev/null @@ -1,14 +0,0 @@ -{ - "readme": "This config is used to test the device enumeration feature.", - "version": 1, - "unprotectedTemporary": [], - "features": { - "webCompat": { - "state": "enabled", - "exceptions": [], - "settings": { - "enumerateDevices": "enabled" - } - } - } -} \ No newline at end of file diff --git a/injected/integration-test/test-pages/webcompat/index.html b/injected/integration-test/test-pages/webcompat/index.html index 3b3703f23a..4bea178bd5 100644 --- a/injected/integration-test/test-pages/webcompat/index.html +++ b/injected/integration-test/test-pages/webcompat/index.html @@ -12,7 +12,8 @@
  • Message Handlers - Config
  • Shims - Config
  • Modify localStorage - Config
  • -
  • Device Enumeration - Config
  • +
  • Device Enumeration
  • +
  • Enumerate Devices API Test - Config