Technically, it's possible to perform eval of any code inside MV3 extension's own context, but it won't be allowed in CWS.
The trick is to define a fetch event handler in the service worker:
const prefix = location.origin + '/?code=';
self.onfetch = e => {
if (e.clientId && e.request.url.startsWith(prefix)) {
e.respondWith(new Response(e.request.url.slice(prefix.length), {
headers: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
}));
}
};
...and use a virtual URL in an extension page like the popup:
function evalCode(code) {
const script = document.createElement('script');
script.src = '/?code=' + encodeURIComponent(code);
document.documentElement.appendChild(script);
}
It can be also used via import('/?code=' +
encodeURIComponent(code)) or even to run an arbitrary remote URL as shown in
https://crbug.com/1239976. None of it is allowed in CWS, though.