2

を示唆して検索する変更私は、ユーザーの既定の検索プロバイダーを変更し、この拡張子を持つ:Chromeの拡張機能のURL

"chrome_settings_overrides" : { 
    "homepage" : "http://example.com/", 

    "search_provider" : { 
     "name": "Example Search", 
     "is_default" : true, 
     "encoding" : "UTF-8", 
     "favicon_url": "http://example.com/favicon.png", 
     "keyword" : "obifind", 
     "search_url" : "http://example.com/?q={searchTerms}&gid=DWB020344", 
     "suggest_url" : "http://example.com/suggest.php?q={searchTerms}&gid=DWB020344" 
    }, 
    "startup_pages" : ["http://example.com"] 
}, 

search_urlsuggest_urlが固定されており、彼らが働いています。

ただし、内線がインストールされていて、初めてbackground.jsが実行された場合、uidが生成され、localStorageに格納されます。

http://example.com/?q={searchTerms}&gid=DWB020344&uid=00445c2e-6aca-11e6-8b77-86f30ca893d3:私は、それは次のようにする必要が

http://example.com/?q={searchTerms}&gid=DWB020344

:私はsearch_urlは、上記1のようなものである場合もsearch_urlsuggest_url等とのクエリで送信されるこのuidのために必要。

ユーザーがURLバーで何かを検索するときに、その余分なパラメータを渡すにはどうすればよいですか?そのような

+0

対応するURLにUIDが含まれていない場合は、 'webRequest' APIを使ってリダイレクトすることができます。 – Xan

+0

さて、それは非倫理的な追跡のように思えます。 'navigator.doNotTrack'に従ってください。 – Xan

+0

@Xan私はどこが間違っているのか分かりません.WebRequest APIを使用していますが、追加したくないだけです。 'chrome.webRequest.onBeforeRequest.addListener'は、プロパティー' redirectUrl'を含むオブジェクトを返すコールバックを持っているはずですか? – clzola

答えて

1

何かが背景ページでwebRequest APIを使用して、トリックを行う必要があります。

var uid = localStorage["uid"]; // Have it ready for max performance of webRequest 

if (navigator.doNotTrack != 1) { // Let's not be evil, OK? 
    chrome.webRequest.onBeforeRequest.addListener(
    function(details) { 
     if (details.url.indexOf("uid=") == -1) { // If no UID yet 
     return { // return a BlockingResponse object 
      redirectUrl: request.url.replace("?", "?uid=" + uid + "&") 
      // Add uid as first parameter, to make sure we don't run into URL fragments 
     }; 
     } 
    }, 
    {urls: ["http://example.com/?*gid=DWB020344*"]}, 
    ["blocking"] 
); 
} 

"persistent": falseを使用することはできません)"webRequest""webRequestBlocking"権限と永続的な背景ページが必要です。

関連する問題