Stepan Yakovenko Stepan Yakovenko - 1 year ago 180
Javascript Question

Get window id from javascript with help of chrome extension

Currently I send message from my html page to chrome extension and it, in turn calls (win) {

to get window Id. But if user selects another (or opens new) window just before this call, I get incorrect id. How can I get id of window, where my js code is running?

Answer Source

In your background script, you probably use chrome.runtime.onMessage.addListener(function(message, sender, sendResponse){ ... }

In that listener, you can use to get the Id of the window that sent the message to the background script, regardless of the current active window.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download