我创建了一个浏览器扩展,它覆盖了新的选项卡页面(它也适用于铬),我想添加一个按钮来打开原始页面,这样我就可以看到那里显示的统计数据了。有我可以让这个按钮转到的URL吗?
如果没有URL,是否有方法获取统计数据的值?(跟踪器阻塞,带宽节省,时间节省)
发布于 2022-10-08 19:55:19
我是勇敢的工程师,感谢你的提问!
目前还没有API选项来检索New,不过我肯定会继续提交反馈意见以供考虑。
不幸的是,似乎也没有办法暂时让Chromium忽略您的自定义New页面,而打开浏览器的默认New页面。我本来希望有一个扩展API来暂时取消chrome_url_overrides,但Chromium的情况似乎并非如此。
您可以采取的一种方法是完全避免正式覆盖,而是监听浏览器中打开的新选项卡。如果用户打开一个新选项卡,将其重定向到您自己的自定义主页。这样,您可以将标志设置为有时不重定向,并使用户能够查看浏览器的NTP。
let override = true;
const newTabURL = "chrome://newtab/";
// Listen for all "new tab" events
chrome.tabs.onCreated.addListener( ({ id, url, pendingUrl }) => {
// We might have been instructed to ignore this event
if ( !override ) {
override = true;
return;
}
// If the new tab is the default new tab page
if ( newTabURL == ( url || pendingUrl ) ) {
// Redirect this new tab to our internal page
chrome.tabs.update( id, {
url: chrome.runtime.getURL("index.html")
});
}
});
// In this example, clicking the browser action button
// instructs the extension to allow the default NTP to
// be displayed.
chrome.action.onClicked.addListener( () => {
override = false;
chrome.tabs.create({ url: newTabURL });
});因为这个扩展将在Brave之外使用,所以检测Brave (用于可选消息传递和说明)的方法也是很好的:
const isBrave = navigator.userAgentData.brands.some(
({ brand }) => brand == "Brave"
);我希望这能帮到你!
https://stackoverflow.com/questions/73939997
复制相似问题