【问题标题】:Where is the source code for electron (atom-shell) Module.require?电子(原子壳)Module.require 的源代码在哪里?
【发布时间】:2015-08-15 05:09:15
【问题描述】:

我正在使用一个模仿 nodejs requirecustom require 函数,它工作正常。

但是,在 electron 中,我得到了

SecurityError: An attempt was made to break through the security policy of the user agent.

在自定义所需代码中调用 window.addEventListener 时。

如果我能阅读 electron 的 'require' 函数的源代码,我可能会理解我的版本失败的原因。

【问题讨论】:

  • 我在一些函数上使用了 toString() 来发现差异。唯一的变化与 Module._contextload 剥离有关。

标签: node.js electron


【解决方案1】:

您要查找的内容应该在 GitHub 上。

https://github.com/atom/atom 要么... https://github.com/atom/electron 要么... https://github.com/atom/node

根据您的更新,您正在寻找的代码(关于共享全局上下文)实际上在这里:https://github.com/atom/node/blob/atom-iojs/lib/module.js#L399

因为 Electron 不包含最新版本的 Node.js,所以我认为值得一提。

【讨论】:

  • 其实,没有。模块不在原子/电子源中。
  • Np。感谢您的解决方案!我仍然不确定我理解为什么 addEventListener 触发了看起来像沙箱上下文的东西。那是错误的实际来源吗?或者你能说一下是什么吗?
  • Nm... 查找 XSS。我现在知道意外的上下文是如何触发错误的。
【解决方案2】:

toString检查后,除了Module._contextload为真时编译,源码与nodejs相同。这部分似乎被优化掉了。

我的代码现在可以通过使用编译 sharing the global context 正常工作,因此表现得像来自同一来源(铬中的 XSS 预防)。这与电子中的require 功能相同。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多