当我在window.onerror中捕获错误时,我遇到了“Script Error。”的问题,即使我已经在S3上正确配置了CORS标头(我认为)。
CORS配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
<AllowedMethod>PUT</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
HTML:
<script crossorigin src="https://s3.amazonaws.com/safari-script-error/foo.js" />
其中包含:
window.addEventListener("keydown", function(event) {
if (event.keyCode === 69) { // "e" button
throw new Error("Oh shoot");
}
});
JS:
window.onerror = function(event) {
console.log(event);
}
Codepen: https://codepen.io/astashov/pen/yoEvRB
在Chrome、Firefox和IE11中可以正常工作,在Safari中只显示“脚本错误。”(我使用的版本是10.0.3(12602.4.8))。
如何让它在Safari中也能正常工作?
<script>
元素不能自闭合 - 我想这可能是错误的原因? - Dai