We are currently trying to update our manifest v2 Chrome Extension to manifest v3.
The extension is using RequireJS in content (!) scripts, and we are currently overloading RequireJS load function to load scripts using eval, as shown here:
require.load = function (context, moduleName, url) {
var xhr = new XMLHttpRequest();
xhr.open("GET", url, true);
xhr.onreadystatechange = function (e) {
if (xhr.readyState === 4 && xhr.status === 200) {
eval(xhr.responseText);
context.completeLoad(moduleName)
}
};
xhr.send(null);
};
This approach has been demonstrated in several sources, for instance:
https://coderwall.com/p/j9bvug/chrome-extension-requirejs-content-scripts
This approach has worked fine in manifest v2 for years in our extension.
However, in manifest v3 using of eval is forbidden.
We tried different techniques, but did not manage to find an elegant solution to this problem.
Basically the question is: how one can use RequireJS in content (!) scripts in Chrome Extension with manifest v3.
What is important that we need a way to load not external code, but scripts that are part of the extension, and we need to load them as content (not background) scripts, and do it dynamically using RequiesJS.
I think that supporting RequireJS in manifest v3 Chrome Extensions is a must, since this library is so widely used.
Any ideas would be very much appreciated.
Regards,
Mikhail