【发布时间】:2014-10-07 14:33:24
【问题描述】:
当用户打开某个页面时,我想在打开新标签之前在现有标签中打开该页面。我试过 webRequest:
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
chrome.tabs.query({ url: 'https://example.com/' },function (tabs) {
chrome.tabs.update(tabs[0].id, { url: details.url, highlighted: true });
})
},
{urls: ['https://example.com/']},
['blocking']
);
我也尝试过使用 webNavigation:
chrome.webNavigation.onBeforeNavigate.addListener(function (details) {
if(details.url=="https://example.com/") {
chrome.tabs.query({ url: 'https://example.com/' },function (tabs) {
chrome.tabs.update(tabs[0].id, { url: details.url, highlighted: true });
});
}
});
这两个都会打开一个必须关闭的新标签,这会导致浏览器在标签之间跳转。
有没有办法在新标签打开之前拦截请求?
谢谢!
【问题讨论】:
标签: javascript redirect google-chrome-extension tabs google-chrome-devtools