main
js 31 lines 885 Bytes
Raw
1 /**
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 *
7 * @flow
8 */
9
10 import {canUseDOM} from 'shared/ExecutionEnvironment';
11
12 export let passiveBrowserEventsSupported: boolean = false;
13
14 // Check if browser support events with passive listeners
15 // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#Safely_detecting_option_support
16 if (canUseDOM) {
17 try {
18 const options: {
19 passive?: void,
20 } = {};
21 Object.defineProperty(options, 'passive', {
22 get: function () {
23 passiveBrowserEventsSupported = true;
24 },
25 });
26 window.addEventListener('test', options, options);
27 window.removeEventListener('test', options, options);
28 } catch (e) {
29 passiveBrowserEventsSupported = false;
30 }
31 }