Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

引用报错ReferenceError: eruda is not defined #69

Closed
zongyuan-vale opened this issue May 31, 2018 · 12 comments
Closed

引用报错ReferenceError: eruda is not defined #69

zongyuan-vale opened this issue May 31, 2018 · 12 comments

Comments

@zongyuan-vale
Copy link

使用gulp打包的微信网页项目,在微信开发者工具内报错,eruda.js我是放在项目内,非常感谢,如下:

image

@surunzi
Copy link
Member

surunzi commented Jun 19, 2018

只在微信开发者工具内报错吗?

surunzi added a commit that referenced this issue Jun 20, 2018
@surunzi
Copy link
Member

surunzi commented Jun 20, 2018

mishoo/UglifyJS#54 压缩工具对代码格式化第三方库进行 unicode 编码转换导致的问题,下个版本修复。

@zongyuan-vale
Copy link
Author

在手机上也没用,我是通过微信开发者工具查看后发现这个问题,好的,谢谢

@surunzi
Copy link
Member

surunzi commented Jun 21, 2018

可以先使用未压缩版本的,应该就不会报这个错误了。另外,这个 bug 似乎跟浏览器版本也有关系,我这边无法复现。

@zongyuan-vale
Copy link
Author

使用cdn或者未压缩就可以正常使用(Use CDN or uncompressed to work properly),谢谢你的帮助

@WangXiZhu
Copy link

目前使用的就是cdn的地址 ,同样报出 eruda is not defined
用法:

(function () { var script = document.createElement('script'); script.src="//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();

@hughfenghen
Copy link

hughfenghen commented Nov 3, 2019

似乎跟网站有关系,我通过代理工具注入eruda到网页,js都能正常加载。
https://sh.meituan.com/ 这个初始化成功
https://i.meituan.com/ 报错eruda is not defined

猜测,可能是将eruda挂载到全局变量上出问题了,或者eruda有什么副作用 跟业务代码冲突了?引入eruda后还报了其他错误。
image

@surunzi
Copy link
Member

surunzi commented Nov 3, 2019

@hughfenghen https://i.meituan.com/ 设置了 csp

@hughfenghen
Copy link

hughfenghen commented Nov 4, 2019

@surunzi 我已经把csp重写了,csp生效的时候浏览器不会去下载Eruda js,控制台也不会打印错误。
csp重写后Eruda下载并执行了,才会打印截图的错误。

另外我试了一下将Eruda注入到baidu.com,也会打印错误。可以复现。
访问百度首页,打开控制带执行以下代码:

(function () { var script = document.createElement('script'); script.src="//cdn.jsdelivr.net/npm/eruda"; document.body.appendChild(script); script.onload = function () { eruda.init() } })();

@surunzi
Copy link
Member

surunzi commented Nov 4, 2019

百度的我看了下,他可能是页面使用了 amd 导致的。你重写 csp 后在插入代码前先将 define 置为 null 试试。

@hughfenghen
Copy link

@surunzi 执行window.define=undfined后,能成功注入Eruda。👍

@hughfenghen
Copy link

广告一下刚写好的代理工具,可以直接将Eruda注入到页面,即使项目没有主动接入Eruda。
Erra
注入Eruda

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants