[英]chrome.tabs.update() redirects to 'chrome-extension://invalid/'
[英]Chrome extension redirects both tabs
我做了一個簡單的Chrome擴展程序,它使我可以將網站重定向到另一個網站。 但是在一個隨機網站中,當我單擊該site1.com鏈接上的“在新選項卡中打開鏈接”按鈕時,當前選項卡和新選項卡都將重定向到site2.com。
這是我的manifest.json
:
{
"manifest_version": 2,
"name": "name",
"description": "description",
"version": "1.0",
"background": {
"scripts": [
"background.js"
]
},
"permissions": [
"*://*.site1.com/*",
"webRequest",
"webRequestBlocking",
"tabs"
]
}
和background.js
:
chrome.webRequest.onBeforeSendHeaders.addListener(
function(tab) {
var getUrl = tab.url,
splitUrl = getUrl.split("/"),
title = splitUrl[4],
url = "https://site2.com/" + title;
chrome.tabs.update(tab.id, {url: url});
},
{urls: ["*://*.site1.com/*"]},
["blocking"]
);
這是因為chrome.webRequest.onBeforeSendHeaders
或chrome.tabs.update(tab.id)
嗎?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.