javascript - Chrome Extension: Open new tab on startup -
what open new tab (chrome://newtab) everytime chrome starts. javascript code working fine:
chrome.tabs.create({}); everytime script executed new tab opens, focuses , places cursor in address bar. problem is, code isn't executed - when no chrome process running before chrome started.
my second approach create event listener once executed chrome know when started. i've tried using script:
chrome.windows.oncreated.addlistener(function (window window) { chrome.tabs.create({}); }); but didn't work @ all.
my manifest looks this:
{ "manifest_version": 2, ... "background": { "scripts": ["newtab.js"], "persistent": false } } ... therefore, correct way of realizing this?
function (window window) { invalid syntax.
chrome.windows.oncreated.addlistener(function() { chrome.tabs.create({}) }) work instead.
however, may not want, cause new tabs when new windows created using menu -> new window.
you can solve checking latest opened window one.
chrome.windows.oncreated.addlistener(function() { chrome.windows.getall(function(windows) { if(windows.length == 1) { chrome.tabs.create({}) } }) })`
Comments
Post a Comment