首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >铬浏览器(Brave)默认主页URL

铬浏览器(Brave)默认主页URL
EN

Stack Overflow用户
提问于 2022-10-03 19:30:49
回答 1查看 127关注 0票数 1

我创建了一个浏览器扩展,它覆盖了新的选项卡页面(它也适用于铬),我想添加一个按钮来打开原始页面,这样我就可以看到那里显示的统计数据了。有我可以让这个按钮转到的URL吗?

如果没有URL,是否有方法获取统计数据的值?(跟踪器阻塞,带宽节省,时间节省)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-10-08 19:55:19

我是勇敢的工程师,感谢你的提问!

目前还没有API选项来检索New,不过我肯定会继续提交反馈意见以供考虑。

不幸的是,似乎也没有办法暂时让Chromium忽略您的自定义New页面,而打开浏览器的默认New页面。我本来希望有一个扩展API来暂时取消chrome_url_overrides,但Chromium的情况似乎并非如此。

您可以采取的一种方法是完全避免正式覆盖,而是监听浏览器中打开的新选项卡。如果用户打开一个新选项卡,将其重定向到您自己的自定义主页。这样,您可以将标志设置为有时不重定向,并使用户能够查看浏览器的NTP。

代码语言:javascript
复制
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 (用于可选消息传递和说明)的方法也是很好的:

代码语言:javascript
复制
const isBrave = navigator.userAgentData.brands.some(
    ({ brand }) => brand == "Brave"
);

我希望这能帮到你!

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73939997

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档