-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extension: switch to scripting api, should work with chrome mv3 now!
for firefox mv3 still need some work for permissions
- Loading branch information
Showing
7 changed files
with
216 additions
and
153 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import browser from "webextension-polyfill" | ||
import type {Scripting} from "webextension-polyfill" | ||
|
||
import {assert} from './common' | ||
|
||
|
||
export async function executeScript<R>(injection: Scripting.ScriptInjection): Promise<R> { | ||
/** | ||
* In firefox, executeScript sets error property, whereas in chrome it just throws | ||
* (see https://issues.chromium.org/issues/40205757) | ||
* For consistency, this wrapper throws in all cases instead | ||
*/ | ||
const results = await browser.scripting.executeScript(injection) | ||
assert(results.length == 1) | ||
const [{result, error}] = results | ||
if (error != null) { | ||
if (error instanceof Error) { | ||
throw error | ||
} else { | ||
throw new Error(`Error during executeScript: ${error}`) | ||
} | ||
} | ||
return result | ||
} |
Oops, something went wrong.