简体   繁体   English

如何获取Node.js中的活动标签url?

[英]How to get the active tab url in Node js?

I am looking for a solution to get the url from the active tab of the browser (Chrome, Firefox, Opera, Safari etc) for a cross platform desktop app made in Electron js.我正在寻找一种解决方案,以从浏览器的活动选项卡(Chrome、Firefox、Opera、Safari 等)中获取 url,用于在 Electron js 中制作的跨平台桌面应用程序。

I found a solution for mac to get the active tab url's of "Chrome" and "Safari" using "applescript" but still could not find a way for "Firefox".我找到了 mac 的解决方案,使用“applescript”获取“Chrome”和“Safari”的活动标签 url,但仍然找不到“Firefox”的方法。

Is there any smart way to get the url of the active tab of the browser in Mac, Windows and Linux using Node.js?有什么聪明的方法可以使用Node.js获取Mac浏览器活动选项卡的url,Windows和Linux?

For firefox in linux you will find the file -> ~/.mozilla/firefox/iq8hatig.default/sessionstore-backups/recovery.jsonlz4对于 linux 中的 firefox,您将找到文件 -> ~/.mozilla/firefox/iq8hatig.default/sessionstore-backups/recovery.jsonlz4

To parse this file in nodejs you can use https://www.npmjs.com/package/bookmark-parser要在 nodejs 中解析此文件,您可以使用https://www.npmjs.com/package/bookmark-parser

    BMParser.readFromJSONLZ4File("~/.mozilla/firefox/iq8hatig.default/sessionstore-backups/recovery.jsonlz4")
        .then(result => { 
          console.log(result.windows)
       }).catch(err => {
         res.send(err);
       });

last entry in this file is the active tab.此文件中的最后一个条目是活动选项卡。

Here is the code you can find browser URL这是您可以在浏览器 URL 中找到的代码

let url = window.location.href

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM