0

I would like to compute the identity of tabs in the chrome browser in a way that survives a browser restart. I am trying to implement the solution proposed in this question.

In my bg.htmtl, I wrote the following event handler:

chrome.windows.onCreated.addListener(
    function(win) {
        console.log("window.onCreated", win);
        for(tab in win.tabs) {
            console.log("window.created.tab", tab);
        }
    });

I then create a new window by pressing ctl-n with the focus on Chrome, but I don't get the event to fire. I then create a second tab via ctrl-t and the event still doesn't fire. I then close the window, create a new window again, and then reload the previously closed ' 2 tabs' item in the recently-closed list. The event then fires. Unforunately, it is missing the tabs property, which is described as optional in the documentation. I have "tabs" permission specified in my manifest.

What should I try next?

Community
  • 1
  • 1
Gene Golovchinsky
  • 6,101
  • 7
  • 53
  • 81

1 Answers1

0

I find it very strange that your onCreated listener isn't being triggered on Ctrl-N. I just tested this and it worked fine for me. Are you absolutely sure you are looking in the right console?

Once you've got the windowId, you can retrieve the tabs using chrome.windows.get with the populate field set in the getInfo argument.

Matthew Gertner
  • 4,487
  • 2
  • 32
  • 54