@atlaskit/editor-common
Version:
A package that contains common classes and components for editor and renderer
44 lines (43 loc) • 1.71 kB
TypeScript
type UserBrowserExtension = 'grammarly';
export type UserBrowserExtensionResults = UserBrowserExtension[];
type BaseOptions = {
extensions: UserBrowserExtension[];
};
type AsyncOptions = BaseOptions & {
async: true;
asyncTimeoutMs: number;
};
type SyncOptions = BaseOptions & {
async?: false;
asyncTimeoutMs?: never;
};
type Options = BaseOptions & (SyncOptions | AsyncOptions);
/**
* Call this to return a list (or a Promise of a list) of detected browser extensions.
*
* This function supports a **synchronous** and **asynchronous** mode through options. You
* must pass a list of the browser extension names you want to target for detection.
* Only UserBrowserExtension extensions are supported, other target names will be silently
* ignored.
*
* If the async option is enabled, you must also pass a final timeout by when it
* should stop all detection attempts and return any partially detected extensions.
*
* Example usage:
* ```
* // synchronously/immediately check for extensions
* const extensions = sniffUserBrowserExtensions({ extensions: ['grammarly', 'requestly'] });
* // result will be ['grammarly'] or ['grammarly','requestly'] or ['requestly'] or [];
*
* // asynchronously check for extensions up to 30s
* sniffUserBrowserExtensions({
* extensions: ['grammarly', 'requestly'],
* async: true,
* asyncTimeoutMs: 30000,
* }).then(extensions => {
* // result will be ['grammarly'] or ['grammarly','requestly'] or ['requestly'] or [];
* })
* ```
*/
export declare function sniffUserBrowserExtensions<O extends Options>(options: O): O extends AsyncOptions ? Promise<UserBrowserExtensionResults> : UserBrowserExtensionResults;
export {};