i'm trying to call an async function defined in my extension from a webpage and print the returned value of this function, but i get "Error: Permission denied to access property "then"" (if i do it with a non async function i still get a Permission denied error).
My extension :
let ethereum = new window.Object();
let request = async function () {
console.log("request");
return ["0x00"]; }
exportFunction(request, ethereum, {
defineAs: "request" });
window.wrappedJSObject.ethereum = ethereum;
My webpage :
const address = await ethereum.request();
The console.log("request") works.
I think I need to Wrap the returned variable or something but can't find what....
Thanks in advance !
exportFunctionwon't work because your JS function is internally wired to the content script'sPromise(this is whatasyncdoes under the hood) and its prototypes (used to create its returned instance ofPromise), which aren't auto-exported as they are not a part of the function.Use
evalornew Functionin the context of the page if the site's CSP allowsunsafe-eval.or
Use a
scriptelement if the site's CSP allows, example.