你能检查用户是否正在使用 Electron 查看网页吗?

时间:2021-05-07 13:32:42

标签: javascript npm electron

假设我想构建一个简单的 Electron 应用程序,当用户到达 example.com 时提醒用户

这可能吗?如果是这样,我将如何检测用户是否正在查看某个网页?

1 个答案:

答案 0 :(得分:0)

Electron 具有 did-navigate 事件,当页面在 BrowserWindow 内重定向时会触发该事件。

参考上面的帖子,我认为,

const { BrowserWindow, dialog } = require('electron')
const win = new BrowserWindow({ width: 800, height: 600 })

win.webContents.on('did-navigate', (event, url, httpResponseCode, httpStatusText) => {
    if(url == "example.com") {
        dialog.showMessageBox({ type: "info", message: `You visited ${url}` });
        //dialog docs at https://www.electronjs.org/docs/api/dialog#dialogshowmessageboxbrowserwindow-options
    }  
})

相关问题