【发布时间】:2018-02-01 07:54:49
【问题描述】:
我收到“脚本错误”。在 window.onerror 中捕获错误时,即使在 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>元素不能自动关闭 - 我想知道这是否是导致错误的原因?
标签: javascript html safari cors onerror