Skip to content

Commit e6f03ef

Browse files
Support Windows permission handling in nested iframes in DDG-WebView (#2027)
* Support Windows permission handling in nested iframes in DDG-WebView * Fix style issues * move `isDdgWebView` to top level user preferences (windows) --------- Co-authored-by: Shane Osbourne <shane.osbourne8@gmail.com>
1 parent 91171f0 commit e6f03ef

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

injected/src/config-feature.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export default class ConfigFeature {
3030
* platform: import('./utils.js').Platform,
3131
* desktopModeEnabled?: boolean,
3232
* forcedZoomEnabled?: boolean,
33+
* isDdgWebView?: boolean,
3334
* featureSettings?: Record<string, unknown>,
3435
* assets?: import('./content-feature.js').AssetConfig | undefined,
3536
* site: import('./content-feature.js').Site,

injected/src/features/windows-permission-usage.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ export default class WindowsPermissionUsage extends ContentFeature {
1717
Paused: 'paused',
1818
};
1919

20-
const isFrameInsideFrame = window.self !== window.top && window.parent !== window.top;
20+
// isDdgWebView is a Windows-specific property injected via userPreferences
21+
const isDdgWebView = this.args?.isDdgWebView;
22+
23+
const isFrameInsideFrameInWebView2 = isDdgWebView
24+
? false // In DDG WebView, we can handle nested frames properly
25+
: window.self !== window.top && window.parent !== window.top; // In WebView2, we need to deny permission for nested frames
2126

2227
function windowsPostMessage(name, data) {
2328
// @ts-expect-error https://app.asana.com/0/1201614831475344/1203979574128023/f
@@ -38,8 +43,8 @@ export default class WindowsPermissionUsage extends ContentFeature {
3843
// proxy for navigator.geolocation.watchPosition -> show red geolocation indicator
3944
const watchPositionProxy = new DDGProxy(this, Geolocation.prototype, 'watchPosition', {
4045
apply(target, thisArg, args) {
41-
if (isFrameInsideFrame) {
42-
// we can't communicate with iframes inside iframes -> deny permission instead of putting users at risk
46+
if (isFrameInsideFrameInWebView2) {
47+
// we can't communicate with iframes inside iframes in WebView2 -> deny permission instead of putting users at risk
4348
throw new DOMException('Permission denied');
4449
}
4550

@@ -313,8 +318,8 @@ export default class WindowsPermissionUsage extends ContentFeature {
313318
if (window.MediaDevices) {
314319
const getUserMediaProxy = new DDGProxy(this, MediaDevices.prototype, 'getUserMedia', {
315320
apply(target, thisArg, args) {
316-
if (isFrameInsideFrame) {
317-
// we can't communicate with iframes inside iframes -> deny permission instead of putting users at risk
321+
if (isFrameInsideFrameInWebView2) {
322+
// we can't communicate with iframes inside iframes in WebView2-> deny permission instead of putting users at risk
318323
return Promise.reject(new DOMException('Permission denied'));
319324
}
320325

0 commit comments

Comments
 (0)