karma
karma copied to clipboard
Support cross-origin isolation
I'm testing code that uses SharedArrayBuffer and I'm getting the following warning in the Chrome console:
[Deprecation] SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021. See https://developer.chrome.com/blog/enabling-shared-array-buffer/ for more details.
Will there be a way to enable cross-origin isolation in Karma so that SharedArrayBuffer doesn't break?
After some digging through the code, I fould out that you can inject custom middlewares into the http server like this:
karma.config.js
:
function CrossOriginIsolationMiddlewareFactory(config) {
return function crossOriginIsolation(req, res, next) {
res.setHeader('Cross-Origin-Opener-Policy', 'same-origin');
res.setHeader('Cross-Origin-Embedder-Policy', 'require-corp');
next();
};
}
module.exports = function (config) {
config.set({
// ...
plugins: [
// load all default karma plugins (this would be the default value if we didn't specify the plugins manually)
'karma-*',
// add custom middleware plugin
{ 'middleware:cross-origin-isolation': ['factory', CrossOriginIsolationMiddlewareFactory] }
],
// ...
beforeMiddleware: [
'cross-origin-isolation',
],
// ...
});
};
Would be amazing to have a simple configuration option nonetheless.
Thank you so much for posting this code! 100% agree that it would be really useful to have this as a simple configuration option.