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

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -