小编Que*_*ire的帖子

电子“上下文桥”

要加载远程内容时提供安全的适当水平,更说明一个BrowserWindowcontextIsolationnodeIntegration选项必须启用和禁用分别。在这种情况下,主渲染器进程将无法使用 Node/Electron API。为了公开特定功能,窗口的预加载脚本可能会利用 Electron 的contextBridge功能,为主渲染器提供对选定 Node/Electron API 的访问权限。

尽管 Electron 文档中提供了信息,contextBridge但总体上缺乏具体的使用示例。一般来说,现有的文档/教程在实现 Electron 应用程序时并不关注采用安全实践。

以下是contextBridge我设法在网上找到的一个使用示例:https : //github.com/reZach/secure-electron-template

您能否提供额外的资源/示例,这些资源/示例可能对实现安全的 Electron 应用程序(依赖于contextBridge功能)有用?

contextBridge最佳实践的洞察力也受到高度赞赏。

javascript security node.js electron

10
推荐指数
3
解决办法
8011
查看次数

RequestAnimationFrame定期加快/降低速度

据我了解,requestAnimationFrame的运行速度应尽可能接近浏览器的帧速率(约60fps)。为了确保确实发生这种情况,我一直在记录每个requestAnimationFrame调用的时间戳,如下所示:

function animate(now){
    console.log(now);
    window.requestAnimationFrame(animate);
}
window.requestAnimationFrame(animate);
Run Code Online (Sandbox Code Playgroud)

Console.log数据显示调用始终在大约0.016674毫秒之间进行,因此表明帧速率为?。60fps(精确到59.9736116108912fps)。

Console.logs(样本数据):

Timestamp   FPS               (Current - previous) timestamp
------------------------------------------------------------
100.226     59.97361161       0.016674
116.9       59.97361161       0.016674
133.574     59.97361161       0.016674
   .             .               .
   .             .               .
150.248     59.97361161       0.016674
166.922     59.97361161       0.016674
183.596     59.97361161       0.016674
200.27      59.97361161       0.016674
Run Code Online (Sandbox Code Playgroud)

到目前为止,requestAnimationFrame调用是在一致的时间间隔内进行的,并且调用不会滞后/执行得太快。

但是,修改animate()函数的内容以执行相对更复杂的函数会导致requestAnimationFrame调用不一致。

Console.logs(样本数据):

Timestamp       FPS               (Current - previous) timestamp
------------------------------------------------------------
7042.73         59.97361161       0.016674
7066.278        42.4664515        0.023548
7082.952        59.97361161       0.016674
7099.626        59.97361161       0.016674
   .                 .                .
   .                 .                .
17104.026       59.97361161       0.016674
17112.84        113.4558657       0.008814
17129.514 …
Run Code Online (Sandbox Code Playgroud)

html javascript performance animation requestanimationframe

7
推荐指数
1
解决办法
245
查看次数