webext-content-scripts
Advanced tools
+1
-0
@@ -29,1 +29,2 @@ import type { ContentScript, ExtensionFileOrCode, RunAt } from './types.js'; | ||
| export declare function canAccessTab(target: number | Target): Promise<boolean>; | ||
| export declare function assertTabAccess(target: number | Target): Promise<void>; |
+4
-1
@@ -235,3 +235,3 @@ import chromeP from 'webext-polyfill-kinda'; | ||
| try { | ||
| await executeFunction(castTarget(target), () => true); | ||
| await assertTabAccess(target); | ||
| return true; | ||
@@ -243,1 +243,4 @@ } | ||
| } | ||
| export async function assertTabAccess(target) { | ||
| await executeFunction(castTarget(target), () => true); | ||
| } |
+1
-1
| { | ||
| "name": "webext-content-scripts", | ||
| "version": "2.7.3", | ||
| "version": "2.8.0", | ||
| "description": "Utility functions to inject content scripts in WebExtensions, for Manifest v2 and v3", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
+15
-0
@@ -28,2 +28,3 @@ # webext-content-scripts [](https://www.npmjs.com/package/webext-content-scripts) | ||
| canAccessTab, | ||
| assertTabAccess, | ||
| } from 'webext-content-scripts'; | ||
@@ -222,2 +223,16 @@ ``` | ||
| ### `assertTabAccess(tabId)` | ||
| ### `assertTabAccess({tabId, frameId})` | ||
| Like `canAccessTab`, but instead of returning `false` on failure it throws whatever error the browser throws. | ||
| Note that you don't need to verify access before calling `executeScript`, just call `executeScript` directly and it will throw exactly the same way. | ||
| ```js | ||
| const tabId = 42; | ||
| await assertTabAccess(tabId); // throws if the extension has no access | ||
| chrome.tabs.repload(tabId); | ||
| ``` | ||
| ### `isScriptableUrl(url)` | ||
@@ -224,0 +239,0 @@ |
20972
3.17%315
1.29%265
6%