Script error.全面解析中我们介绍了Script error.的由来。这篇博客,我们将各种情况(不同浏览器、本地远程托管JS文件)考虑进去,进行一个深度的测试,为读者带来一个全面的了解。

GitHub仓库: Fundebug/script-error

基本准备

index.html中使用onerror监控错误。

<!DOCTYPE html>
<html>
<head>
<title>Test Script error</title>
<script type="text/javascript">
window.onerror = function(errorMessage, scriptURI, lineNumber, columnNumber, error){
console.log(errorMessage);
console.log(scriptURI);
console.log(lineNumber);
console.log(columnNumber);
console.log(error);
}
</script>
<script type="text/javascript" src="./scripterror.js"></script>
</head>
<body>
</body>
</html>

scripterror.js中抛出一个Error对象:

throw new Error('Hello, Fundebug');

该Error对象会被window.onerror捕获。

本地直接打开

如果我们直接在本地打开index.html, 可以看到Safari, Firefox, IE浏览器都能正确打印出错误信息。

唯独Chrome只显示Script error.

这是因为Chrome浏览器默认不允许访问本地文件

To load local resources in Chrome when just using your local computer and not using a webserver you need to add the --allow-file-access-from-files flag.

如果一定要使用,需要开启访问本地文件的候选项,可以参考chrome 等浏览器不支持本地ajax请求的问题

使用服务器挂载静态资源

我们将使用http-server

安装http-server:

npm install http-server -g

运行http-server:

http-server
Starting up http-server, serving ./
Available on:
http://127.0.0.1:8080
http://172.20.1.86:8080
http://192.168.59.100:8080
Hit CTRL-C to stop the server

访问http://localhost:8080/index.html

情况三:将scripterror.js托管

为了测试Script error., 我将scripterror.js分别托管在了Coding七牛

Coding

index.html

<script type="text/javascript" src="http://coding.net/u/stefanzan/p/stefanzan/git/raw/coding-pages/public/js/src/scripterror.js"></script>

Chrome, Safari和IE浏览器都将错误信息隐藏,返回Script error.

不过Firefox比较特别,依然将错误信息完整的打印出来,大概是为了方便开发者排错。

七牛云

index.html

<script type="text/javascript" src="https://og6593g2z.qnssl.com/scripterror.js"></script>

结果和托管在Coding上是一样的。

将引入脚本修改一下,加入crossorigin="anaonymous":

<script type="text/javascript" src="https://og6593g2z.qnssl.com/scripterror.js" crossorigin="anonymous"></script>

再次执行运行,在不同浏览器的表现如下:

Chrome, Safari可以获取详细的出错信息了,但是IE浏览器依然是Script error. 。这一点比较奇怪, 根据MDN - CORS settings attributes,IE11应该是没有问题的。

在这里我将Coding和七牛对于scripterror.jsResponse Headers对一下:

七牛的Access-Control-Allow-Origin允许来自所有域名的请求,而Coding没有。七牛是一个资源托管分发平台,因此特意配置了不同的返回头,方便开发者将脚本放在七牛云同时又可以拿到出错信息。

下一篇博客中,我们将提出Script error解决方法

关于Fundebug

Fundebug专注于JavaScript、微信小程序、微信小游戏、支付宝小程序、React Native、Node.js和Java实时BUG监控。 自从2016年双十一正式上线,Fundebug累计处理了7亿+错误事件,得到了Google、360、金山软件、百姓网等众多知名用户的认可。欢迎免费试用!

版权声明

转载时请注明作者Fundebug以及本文地址:

https://blog.fundebug.com/2017/04/06/test-script-error/

Script error.深度测试的更多相关文章

  1. Fundebug前端JavaScript插件更新至1.7.1,拆分录屏代码,还原部分Script error.

    摘要: BUG监控插件压缩至18K. 1.7.1拆分了录屏代码,BUG监控插件压缩至18K,另外我们还原了部分Script error,帮助用户更方便地Debug.请大家及时更新哈~ 拆分录屏代码 从 ...

  2. Script error.全面解析

    一些用户向我们反馈,Fundebug的[JavaScript](https://docs.fundebug.com/notifier/javascript/)监控插件抓到了很多**Script err ...

  3. 解决 "Script Error" 的另类思路

    本文由小芭乐发表 前端的同学如果用 window.onerror 事件做过监控,应该知道,跨域的脚本会给出 "Script Error." 提示,拿不到具体的错误信息和堆栈信息. ...

  4. Uncaught Error: Script error for "popper.js", needed by: bootstrap - require.js

    Uncaught Error: Script error for "popper.js", needed by: bootstrap https://requirejs.org/d ...

  5. script error总结

    移动端的页面在控制台报出一个script error,通常的原因有一下几点: 1. 脚本引入错误 可能是脚本的地址不对,协议不对(http或https问题),本地host文件绑定的地址不对 2. 方法 ...

  6. 怎样解决Script error报错问题

    如果脚本网址与网页网址不在同一个域(比如使用了 CDN), 那如果这个脚本执行报错了, 就会报:Script error. 由于同源策略, 浏览器禁止向外部脚本泄漏信息, 因此不会提供完整的报错信息, ...

  7. unity c# script error CS0664: Literal of type double cannot be implicitly converted to type `float'. Add suffix `f' to create a literal of this type

    例如在unity c# script中定义 private float x=0.0; 则会报 error CS0664: Literal of type double cannot be implic ...

  8. java + spring (jython\python\script) Error:SyntaxError: no viable alternative at character '\n'

    使用Jython结合java和Python开发功能时,要是遇到如下情况: 2016-03-10 16:16:49 DEBUG [com.freedom.orion.configs.JyhtonConf ...

  9. Script error.解决方法

    1. 添加 crossorigin="anonymous" 到script标签 <script src="https://xxx.com/xxx.js" ...

随机推荐

  1. ASP.NET MVC下使用AngularJs语言(四):$window.alert

    判断文本框是否有填写,没有填写使用angularjs的$window.alert来提示用户. 创建一个ASP.NET MVC控制器: 接下来是准备一个angularjs的控制器: pilotApp.c ...

  2. java之LinkedList详细介绍

    1 LinkedList介绍 LinkedList简介 LinkedList 是一个继承于AbstractSequentialList的双向链表.它也可以被当作堆栈.队列或双端队列进行操作.Linke ...

  3. SQL注入的优化和绕过

    作者:Arizona 原文来自:https://bbs.ichunqiu.com/thread-43169-1-1.html 0×00 ~ 介绍 SQL注入毫无疑问是最危险的Web漏洞之一,因为我们将 ...

  4. Servlet案例7:jsp技术及案例

    jsp运行原理: 根据jsp文件创建java文件(servlet),并编译运行 第一次访问时会被翻译成servlet后执行 jsp三个指令: 1.page指令:页面翻译运行的属性的配置(通常使用默认) ...

  5. Linux - 查看文件信息的三个命令

    ls命令 - list directory contents 显示文件详细信息:ls -l <file name> file命令 - determine file type determi ...

  6. Python基础教程(第3版) 笔记(二)

    1.8模块Python提供了完成(某人的年 龄为32.9,并想将这个值向下圆整为32,因为他还没有满33岁)这种任务的函 数floor.导入模块,可以使用特殊命令import.函数floor包含在模块 ...

  7. Can't sendRedirect() after data has committed to the client

    resin下 response.sendRedirect("XXX"); 会报异常:java.lang.IllegalStateException: Can't sendRedir ...

  8. Spring Cloud的注册中心和服务者,消费者的构建

    Spring Cloud的注册中心和服务者,消费者的构建 注册中心Eureka: 新建项目stu-eureka: StuEurekaApplication: package com.demo.stue ...

  9. Google Optimization Tools实现加工车间任务规划【Python版】

    上一篇介绍了<使用.NET Core与Google Optimization Tools实现加工车间任务规划>,这次将Google官方文档python实现的版本的完整源码献出来,以满足喜爱 ...

  10. SpringBoot的幕后推手...

    一.背景 ​ 这两年随着微服务的盛行,SpringBoot框架水到渠成的得到了高曝光,作为程序猿的我们,现在要是不知道一点SpringBoot相关的东西,貌似出去找工作都会被深深地鄙视,不过在我们开始 ...