diff --git a/dom/base/test/useractivation/mochitest.ini b/dom/base/test/useractivation/mochitest.ini
index 5426b1522e8f..26c8594be87d 100644
--- a/dom/base/test/useractivation/mochitest.ini
+++ b/dom/base/test/useractivation/mochitest.ini
@@ -13,6 +13,8 @@ prefs =
[test_useractivation_transient.html]
[test_useractivation_sandbox_transient.html]
support-files = file_useractivation_sandbox_transient_popup.html
+[test_useractivation_scrollbar.html]
+skip-if = os == 'android' # scrollbar not showed on mobile
[test_useractivation_transient_consuming.html]
[test_clipboard_editor.html]
[test_clipboard_noeditor.html]
diff --git a/dom/base/test/useractivation/test_useractivation_scrollbar.html b/dom/base/test/useractivation/test_useractivation_scrollbar.html
new file mode 100644
index 000000000000..778d6d08982a
--- /dev/null
+++ b/dom/base/test/useractivation/test_useractivation_scrollbar.html
@@ -0,0 +1,135 @@
+
+
+
+User activation test: consume transient flag
+
+
+
+
+
+
+
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+ 
+
+
+
+
diff --git a/dom/events/EventStateManager.cpp b/dom/events/EventStateManager.cpp
index f451fa1c51c4..924e39929388 100644
--- a/dom/events/EventStateManager.cpp
+++ b/dom/events/EventStateManager.cpp
@@ -1001,6 +1001,24 @@ void EventStateManager::NotifyTargetUserActivation(WidgetEvent* aEvent,
return;
}
+ // Do not treat the click on scrollbar as a user interaction with the web
+ // content.
+ if (StaticPrefs::dom_user_activation_ignore_scrollbars() &&
+ (aEvent->mMessage == eMouseDown || aEvent->mMessage == ePointerDown) &&
+ aTargetContent->IsInNativeAnonymousSubtree()) {
+ nsIContent* current = aTargetContent;
+ do {
+ nsIContent* root = current->GetClosestNativeAnonymousSubtreeRoot();
+ if (!root) {
+ break;
+ }
+ if (root->IsXULElement(nsGkAtoms::scrollbar)) {
+ return;
+ }
+ current = root->GetParent();
+ } while (current);
+ }
+
MOZ_ASSERT(aEvent->mMessage == eKeyDown || aEvent->mMessage == eMouseDown ||
aEvent->mMessage == ePointerDown || aEvent->mMessage == eTouchEnd);
doc->NotifyUserGestureActivation();
diff --git a/modules/libpref/init/StaticPrefList.yaml b/modules/libpref/init/StaticPrefList.yaml
index 7afabfbccfc2..c3ff3dd71420 100644
--- a/modules/libpref/init/StaticPrefList.yaml
+++ b/modules/libpref/init/StaticPrefList.yaml
@@ -4053,6 +4053,12 @@
value: 5000
mirror: always
+# Whether to treat the clicks on scrollbars as user interaction with web content.
+- name: dom.user_activation.ignore_scrollbars
+ type: bool
+ value: true
+ mirror: always
+
# Whether to shim a Components object on untrusted windows.
- name: dom.use_components_shim
type: bool