From 5a6adef15e75b63a18e600b58de68b97446b073c Mon Sep 17 00:00:00 2001 From: Federico Brigante Date: Tue, 30 Jul 2024 19:33:44 +0700 Subject: [PATCH] Add `isSandboxedPage` (#28) --- index.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/index.ts b/index.ts index abbc06b..66b5b29 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(),