Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a browser window from a desktop notification that's generated from a background page?

I have built a simple chrome application which has a background page that shows desktop notifications when a new article is available.

If a user clicks on the notifications when a browser window is open, then they are taken to the new article page and everything is right with the world.

If however the browser is closed when the notification is shown, then the href does not open the browser. I have also tried to capture the click and set a window.open, but that isn't working either.

As an aside, it would also be good if I could check to see if an instance of my app is already open and use that window/tab when the notification is clicked, but that's secondary to the first problem.

Any help would be great!

Thanks

like image 709
Kenneth Avatar asked Nov 05 '22 15:11

Kenneth


1 Answers

Check if chrome window is open. if open the create in new tab else oepn new window.

chrome.windows.getCurrent(function(currentWindow) {
  if (currentWindow != null) {
    return chrome.tabs.create({
      'url': url
    });
  } else {
    return chrome.windows.create({
      'url': url,
      'focused': true
    });
  }
});
like image 156
Shankar Morwal Avatar answered Nov 09 '22 10:11

Shankar Morwal