Javascript Chrome扩展,可捕获并重定向URL/搜索栏中键入的任何内容

Javascript Chrome扩展,可捕获并重定向URL/搜索栏中键入的任何内容,javascript,google-chrome,redirect,google-chrome-extension,Javascript,Google Chrome,Redirect,Google Chrome Extension,我想创建一个扩展,它将操作URL栏中键入的任何内容(匹配模式),并进行适当的重定向 更具体地说: 我想键入这样一种格式的URL:\u http://。我希望chrome重定向此http:// 以下是我的想法(基于): manifest.json { "name": "_Replace", "description": "Replace '_http' with 'http'", "version": "1.0", "manifest_version": 2, "backgro

我想创建一个扩展,它将操作URL栏中键入的任何内容(匹配模式),并进行适当的重定向

更具体地说: 我想键入这样一种格式的URL:
\u http://
。我希望chrome重定向此
http://

以下是我的想法(基于):

manifest.json

{
  "name": "_Replace",
  "description": "Replace '_http' with 'http'",
  "version": "1.0",
  "manifest_version": 2,
  "background": {"scripts":["background.js"]},
  "permissions": [
    "webRequest",
    "<all_urls>",
    "webRequestBlocking"
  ]
}
{
“名称”:“替换”,
“说明”:“将“_http”替换为“http”,
“版本”:“1.0”,
“清单版本”:2,
“背景”:{“脚本”:[“background.js”]},
“权限”:[
“网络请求”,
"",
“webRequestBlocking”
]
}
background.js

chrome.webRequest.onBeforeRequest.addListener(
    function(details) {

        var url = details.url;
        console.log(url);
        if(url[0] == "_")
         return {redirectUrl: url.substr(1)};
    },
    {
        urls: [
            "<all_urls>"
        ],
        types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
    },
    ["blocking"]
);
chrome.webRequest.onBeforeRequest.addListener(
功能(详情){
var url=details.url;
console.log(url);
如果(url[0]==“\”)
返回{redirectUrl:url.substr(1)};
},
{
网址:[
""
],
类型:[“主框架”、“子框架”、“样式表”、“脚本”、“图像”、“对象”、“xmlhttprequest”、“其他”]
},
[“封锁”]
);

不幸的是,自从“_http://xxx“在一个有效的URL中,谷歌会自动将其视为搜索短语,并将我重定向到谷歌搜索。我怎样才能阻止搜索并进行我想要的重定向?

如何检查url以及是否是带参数的google搜索_http://xxx然后重定向它?我的意思是,你无论如何也不能做任何其他事情……我想了想,无论如何,我必须提取参数并解密它。也许可以。然而,我想知道这是否是最好和最普遍的方式-如果我改变了搜索引擎(可能不会发生,但…?)?也许我应该使用
选项卡
对象?嗯,是的,
解码组件
等等。我看没有更好的方法了。没有API可以读取omnibox(地址栏)。@dstronczak I已经可以解析搜索URL并重定向到所需的目的地。沃克索姆独立得出了同样的结论。所以我想这确实是最好的方法。