我正在使用一个自定义的 require函数,它模仿nodejs require并且它工作正常。
但是,在电子中,我得到
SecurityError: An attempt was made to break through the security policy of the user agent.
window.addEventListener
在自定义所需的代码中调用时。
如果我可以阅读电子的“要求”功能的源代码,我可能会理解我的版本失败的原因。
我正在使用一个自定义的 require函数,它模仿nodejs require并且它工作正常。
但是,在电子中,我得到
SecurityError: An attempt was made to break through the security policy of the user agent.
window.addEventListener
在自定义所需的代码中调用时。
如果我可以阅读电子的“要求”功能的源代码,我可能会理解我的版本失败的原因。
您要查找的内容应该在 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,所以我认为值得一提。
经检查,除了编译时为真toString
,来源与nodejs相同。Module._contextload
这部分似乎被优化掉了。
我的代码现在通过使用共享全局上下文的编译正常工作,因此表现得像来自同一来源(铬中的 XSS 预防)。这与电子中的功能相同require
。