私は拡張機能を作って遊んでいます。ユーザーが拡張機能をインストールしている場合、ユーザーがWebページでクリックしたリンクをキャプチャしたいと思います。これを行う方法はよくわかりませんが、簡単なようです。追加するかもしれませんが、プラグインがインストールされて有効になっている限り、これを実行したいのですが、ユーザーがツールバーで「アクティブ化」するために何かをする必要はありません。
開始方法がわからない。また、JSファイルが多すぎると思いますが、そのうちの1つをコンソールに記録しようとしています。どちらもしません。私の最終的な目標は、特定の場所に移動した場合に、それらをイントラネットページにリダイレクトしたいということです。
background.js
var redirectedSites = ["https://www.facebook.com/profile.php?id=<SOMEPROFILEID>"];
// when the browser tries to get to a page, check it against a list
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
console.log('is this even getting hit?');
for(var i=0; i < redirectedSites.length; ++i) {
// if the attempt is to a listed site, redirect the request
if( details.url == redirectedSites[i] )
return {redirectUrl: "http://intranet/landing?from=" + details.url };
}
},
{urls: ["*://www.facebook.com/*"]},
["blocking"]
);
マニフェスト.json
{
"name": "Capture Click",
"version": "0.1",
"description": "Simple tool that logs clicked links.",
"permissions": [
"tabs",
"webRequest",
"webRequestBlocking",
"https://*.facebook.com/*"
],
"background": {
"scripts": ["background.js"]
},
"manifest_version": 2
}