From 0c05eef04f434e44b8cd2fd2759a11df49d57a04 Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Fri, 29 Dec 2023 23:15:27 +0800 Subject: [PATCH] Add `isSandboxedPage` --- index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.ts b/index.ts index 0e2a5a9..195f6a7 100644 --- a/index.ts +++ b/index.ts @@ -45,6 +45,9 @@ export const isExtensionContext = once((): boolean => typeof globalThis.chrome?.extension === 'object', ); +/** Indicates whether the code is being run in a sandboxed page (-extension:// URL protocol, but no chrome.* API access) */ +export const isSandboxedPage = once((): boolean => location.protocol.endsWith('-extension:') && !isExtensionContext()); + /** Indicates whether the code is being run in a content script */ export const isContentScript = once((): boolean => isExtensionContext() && isWebPage(),