简体   繁体   中英

Chrome Extension: Open window when running in background

So, I have my chrome extension, runs in background fine. And every few hours it uses the notification API to ask the user a question.

If they click one answer we open a tab in the current window.

Problem: If there are no chrome windows open (ie the extension is running as part of "Let google chrome run in the background" option), the tab doesn't open.

Here's the code which works fine as long as there is at least a single chrome window open:

// tried this too: chrome.windows.create();
chrome.tabs.create({url: pathToGo});

How to make "chrome.windows.create()" actually make a window if there are none already open.

Use chrome.windows.getAll(object getInfo, function callback) APIs to get all open windows. If in the callback, the array of windows is empty, create a new window using chrome.windows.create(object createData, function callback) .

Use chrome.notifications API if you are unable to create new window. http://developer.chrome.com/extensions/notifications.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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