Internet Explorer 扩展 (BHO) 中的沙盒 Javascript 执行
Firefox 有 Sandbox 和 evalInSandbox()。 Chrome 在其内容脚本中具有沙盒执行(他们称之为隔离执行)。我正在 IE 浏览器扩展中寻找同样的东西。
我可以加载一个 javascript 文件,然后调用 evalScript(),但代码在与页面上存在的 javascript 相同的环境中执行。我需要一种方法来在沙盒/隔离环境中运行我的库(其中包括并基于 jQuery),但仍然允许它修改 DOM,就像它在页面上运行一样。
Jint 看起来很有前途,但目前无法评估 jQuery。 (他们可以解析它。)
我该怎么做?
Firefox has the Sandbox and evalInSandbox(). Chrome has sandboxed execution in their content scripts (they call it isolated execution). I'm looking for the same thing in an IE browser extension.
I can load a javascript file, then call evalScript(), but the code executes in the same environment as javascript that exists on the page. I need a way to run my library (which includes and is based on jQuery) in an sandboxed/isolated environment, but still allow it to modify the DOM as if it were running on the page.
Jint looks promising, but cannot currently evaluate jQuery. (They can parse it.)
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
看起来你对这个问题感到很为难。
我真的希望能有更好的消息,但看起来可能需要一个小奇迹才能实现你正在寻找的东西……或者可能需要很多钱。 :)
你最好的选择可能是找到少数几个声称自己能够做到这一点的人之一,并付给他们很多钱来分享这个秘密,或者重新考虑为什么你真正想要你想要的东西,看看你是否无法完成另一种方式。
Looks like you are in a pickle with this one.
I really wish I had better news but it looks like it might take a small miracle to accomplish what you are looking for... or maybe a lot of money. : )
Your best bet is probably going to be finding one of the few who claim they have been able to do it and pay them a lot to share the secret or reconsider why you really want what you want and see if you can't accomplish it another way.
您可能会发现值得查看 Live Labs 中的 Microsoft Web Sandbox:
http://websandbox.livelabs.com/
虽然它更加成熟并且与混搭等相关可能会为您指明正确的方向。
You might find it worthwhile looking at the Microsoft Web Sandbox at the Live Labs:
http://websandbox.livelabs.com/
Although it's more fully fledged and related to mashups and the like it might point you in the right direction.
您正在寻找的是 ActiveScript 引擎(http://en.wikipedia.org/wiki/Active_Scripting)
我现在找不到任何有用的链接,MSDN 仅包含接口定义 (http://msdn.microsoft.com/en-us/library/ccd0zt2w(v=vs.85).aspx)
尝试谷歌“Active Scripting”(而不是“Action scripting”!)
您需要在扩展中实现 IActiveScriptHost 接口,创建一个 «JScript» 对象,调用 SetSite 并传递您的主机对象,然后您可以将 js 代码加载到此引擎并运行它。
由于缺乏相关文档,该技术相当困难。
如果您仍然对此感兴趣,我可以向您发送一些 C++/ATL 示例。
Thing you are looking for is ActiveScript engine (http://en.wikipedia.org/wiki/Active_Scripting)
I can`t find any usefull links now, MSDN contains only interfaces definition (http://msdn.microsoft.com/en-us/library/ccd0zt2w(v=vs.85).aspx)
Try to Google "Active Scripting" (not "Action scripting"!)
You need to implement interface IActiveScriptHost in your extension, create an object of «JScript», call SetSite and pass your host object, then you can load your js code into this engine and run it.
This technique is a quite difficult due to lack of documentation about it.
If you are still interested in this, I can send you some examples in C++/ATL.
您能详细说明一下您的目标吗?
我认为您没有明确定义您要实现的目标。如果您的代码能够修改页面的 DOM,那么它实际上在页面上下文中执行。它可以创建新的脚本块来执行它在同一执行环境中运行时可以完成的任何不安全或不可靠的操作。
IE 不提供执行您所要求的功能,并且我不相信 Firefox 和 Chrome 功能会按照您期望的方式工作。
Can you elaborate on your goals a bit?
I don't think you've clearly defined what you're trying to accomplish. If your code has the ability to modify the page's DOM, then it effectively is executing in the context of the page. It can create new script blocks to perform any unsafe or unreliable action that it could accomplish were it operating in the same execution environment.
IE doesn't offer a feature to do what you're asking, and I'm not convinced that the Firefox and Chrome features work the way that you expect that they do.