mac https本地跨域配置

本地开启网页服务的方法很多,一般借助emcc自带的emrun命令 emrun --no_browser build 即可开启本地http服务

最近在搞webassembly多线程,由于chrome在91版本之后如果要开启对sharedarraybuffer的使用,需要对网页配置跨域隔离,搜了网了有不少解决方案,我这边试了两个:

1、设置参数--disable-web-security,[yourname]换成电脑名称,一般是admin,这种方法,虽然设置跨域成功了,但是sharedarraybuffer没有启用成功,有时间可以去研究一下

open -n /Applications/Google\ Chrome.app/ --args --disable-web-security  --user-data-dir=/Users/[yourname]/MyChromeDevUserData/

2、 开启https服务,注意不是http,两者有些区别,本地开启https是默认会开启跨域隔离的,接下来就是研究如何开启https服务,可以参考Using SSL in local developmenthttps://blog.revathskumar.com/2020/07/using-ssl-in-local-development.html

1)安装AC证书

这一步使用mac的homebrew安装,brew install mkcert

2)执行mkcert --install

3)执行mkcert localhos 127.0.0.1,这时候目录下面会出现两个localhost的pem的证书

4)执行python脚本启用https服务

跨域服务参考资料:

Cross Origin Isolation:如何进行跨域隔离 - sky0014 - 博客园

https://github.com/sky0014/blog/blob/main/cross-origin-isolation.md

解决 SharedArrayBuffer is not defined - 掘金

https://segmentfault.com/a/1190000012550346

你可能感兴趣的:(webAssembly,mkcert,https,跨域隔离)