1

I'm creating new tab in chrome extension using following code;

var url="https://www.test.com";
chrome.tabs.create({url:url, active: false}, 
 function(tab)
 {      
 }
 );

How to identify, is the newly opened tab is created by my extension, or user has manually opened the url in a new tab?

I need to know it within content script. I have already some code in content script. I'm looking for a solution which not uses chrome.tabs.sendMessage();

But not knowing how to identify the caller before fully loading the page.

Can we pass an parameter when creating a new tab?

Any help would be appreciated.

  • [Injecting javascript variable before content script](https://stackoverflow.com/a/45105934) – wOxxOm Jan 14 '21 at 10:41

1 Answers1

1

I found out through using chrome.tabs.onCreated that when a user opens a new tab themselves the tab properties would have status as loading, url as chrome://newtab.

Try this:

chrome.tabs.onCreated.addListener(function(t){
    if(t.status === 'loading' && t.url === 'chrome://newtab'){}
});
JQuon
  • 11
  • 2