/
ashipov
/
react
Обзор
Документация
Войти
/
ashipov
/
react
Код
Запросы
0
Задачи 2.0
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
main
packages/react-devtools-shared/src/frontend/utils/withPermissionsCheck.js
35 строк
1 KB
Ruslan Lesiutin
chore[DevTools]: make clipboardWrite optional for chromium (#32262)
30 янв 2025, 23:08
Не верифицирован
30 янв 2025, 23:08
221f300
Код
Авторство
О чём код?
/** * Copyright (c) Meta Platforms, Inc. and affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import {PermissionNotGrantedError} from 'react-devtools-shared/src/errors/PermissionNotGrantedError'; type SupportedPermission = 'clipboardWrite'; type Permissions = Array<SupportedPermission>; type PermissionsOptions = {permissions: Permissions}; // browser.permissions is not available for DevTools pages in Firefox // https://bugzilla.mozilla.org/show_bug.cgi?id=1796933 // We are going to assume that requested permissions are not optional. export function withPermissionsCheck<T: (...$ReadOnlyArray<empty>) => mixed>( options: PermissionsOptions, callback: T, ): T | (() => Promise<ReturnType<T>>) { if (!__IS_CHROME__ && !__IS_EDGE__) { return callback; } else { return async () => { const granted = await chrome.permissions.request(options); if (granted) { return callback(); } return Promise.reject(new PermissionNotGrantedError()); }; } }