Skip to content

Commit d731a67

Browse files
authored
feat: add disableDialogs option to WebPreferences (electron#22395)
Allows to disable dialogs completely in a similar way of how safeDialogs option can be used. Overrides safeDialogs option.
1 parent 282a44e commit d731a67

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

docs/api/browser-window.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
369369
consecutive dialog protection is triggered. If not defined the default
370370
message would be used, note that currently the default message is in
371371
English and not localized.
372+
* `disableDialogs` Boolean (optional) - Whether to disable dialogs
373+
completely. Overrides `safeDialogs`. Default is `false`.
372374
* `navigateOnDragDrop` Boolean (optional) - Whether dragging and dropping a
373375
file or link onto the page causes a navigation. Default is `false`.
374376
* `autoplayPolicy` String (optional) - Autoplay policy to apply to

shell/browser/electron_javascript_dialog_manager.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,12 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog(
6161
return;
6262
}
6363

64+
auto* web_preferences = WebContentsPreferences::From(web_contents);
65+
66+
if (web_preferences && web_preferences->IsEnabled("disableDialogs")) {
67+
return std::move(callback).Run(false, base::string16());
68+
}
69+
6470
// No default button
6571
int default_id = -1;
6672
int cancel_id = 0;
@@ -75,7 +81,6 @@ void ElectronJavaScriptDialogManager::RunJavaScriptDialog(
7581

7682
origin_counts_[origin]++;
7783

78-
auto* web_preferences = WebContentsPreferences::From(web_contents);
7984
std::string checkbox;
8085
if (origin_counts_[origin] > 1 && web_preferences &&
8186
web_preferences->IsEnabled("safeDialogs") &&

0 commit comments

Comments
 (0)