Chrome 用户脚本是否像 Greasemonkey 脚本一样与全局命名空间分开? [英] Are Chrome user-scripts separated from the global namespace like Greasemonkey scripts?

查看:17
本文介绍了Chrome 用户脚本是否像 Greasemonkey 脚本一样与全局命名空间分开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 Greasemonkey 脚本自动包装在匿名函数中以某种方式隔离,以防止它们与页面中的脚本发生冲突.

I know Greasemonkey scripts are automatically wrapped in anonymous functions isolated in some way in order to prevent them conflicting with scripts in the page.

Chrome 用户脚本是否也会发生同样的情况?

Does the same happen with Chrome user-scripts?

推荐答案

是的,Greasemonkey 脚本是 通常包裹在匿名函数中.而且,Chrome 用户脚本显然也是如此.

Yes, Greasemonkey scripts are normally wrapped in an anonymous function. And, Chrome userscripts apparently are too.

但是,更重要的是,Greasemonkey 脚本通常1 包裹在 XPCNativeWrapper 沙箱,而 Google Chrome 将用户脚本转换为扩展程序,而 他们在一个被 Google 称为孤立世界"的舞台上运作2.

But, more importantly, Greasemonkey scripts are usually1 wrapped in an XPCNativeWrapper sandbox, while Google Chrome converts userscripts into extensions, and they operate in an arena that Google calls an "isolated world"2.

因此,出于安全目的,您无需将脚本代码包装在匿名函数中,它们已经受到保护.

So, you don't need to wrap your script code in anonymous functions for security purposes, they're already protected.

请注意:

  1. 如果您将代码直接注入页面(创建一个
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆