[英]How to identify a new tab is opened by user manually in chrome extension?
I'm creating new tab in chrome extension using following code;我正在使用以下代码在 chrome 扩展中创建新选项卡;
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?如何识别,新打开的标签是我的分机创建的,还是用户在新标签中手动打开了url?
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();
我正在寻找一种不使用 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.任何帮助,将不胜感激。
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
.我通过使用
chrome.tabs.onCreated
发现,当用户自己打开一个新选项卡时,选项卡属性的status
为loading
, url
为chrome://newtab
。
Try this:试试这个:
chrome.tabs.onCreated.addListener(function(t){
if(t.status === 'loading' && t.url === 'chrome://newtab'){}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.