javascript - Chrome 扩展程序仅适用于“chrome://extensions”
问题描述
我正在做一个 chrome 扩展。如果满足特定条件,我想更改活动选项卡中的 URL(重定向)。这是我的代码:
function redirect_to(desire_url){
chrome.tabs.query({active:true,windowType:"normal", currentWindow: true},function(tabs){
chrome.tabs.update(tabs[0].id,{url:desire_url});
console.log('redirect to'+desire_url);
});
}
(function(){
redirect_to('http://google.com');
})();
我的 manifest.json 文件
{
"name":"My Extension",
"description":"Just a simple extension",
"version":"1.0",
"manifest_version":2,
"background":{
"scripts":["background.js"]
},
"content_scripts":[
{
"matches":[
"<all_urls>"
],
"js":["popup.js"]
}
],
"browser_action":{
"default_icon":"icon.png",
"default_popup":"popup.html"
},
"permissions":[
"tabs",
"activeTab",
"*://*/"
]
}
在“chrome://extensions” URL 中,它工作得很好。但是,在“https://blabla.com”之类的其他 URL 中,它不起作用。我知道这个问题已经有人问过了。但是,该解决方案对我不起作用。谢谢。
解决方案
推荐阅读
- php - preg_replace 到 php
- c++ - 如何在 SDL2 文本输入中禁用键重复
- javascript - 在所有主题名称字段上显示错误
- validation - 更新验证器插件管理器以实现自定义
- javascript - React 路由无法通过传递数据渲染组件
- django - 反向重定向上的 Django 消息格式错误
- docker - xvfb-run 在容器中挂起
- python - 在熊猫中使用 PeriodIndex 与 DateTimeIndex?
- c++-amp - 使用 C++ AMP 的退出代码中的问题
- android - 更新 blob 后,Android sqlite 无法读取