リファラーがFacebookであるが動作していない場合、コードにコードを挿入したいと考えています。これは私が以下に使用したコードです。Chrome拡張機能:コードを挿入するリファラーがfacebookの場合
manifest.jsonを
{
"name": "Injecta",
"version": "0.0.1",
"manifest_version": 2,
"description": "Injecting stuff",
"homepage_url": "http://danharper.me",
"background": {
"scripts": [
"background.js"
],
"persistent": true
},
"browser_action": {
"default_title": "Inject!"
},
"permissions": [
"https://*/*",
"http://*/*",
"tabs"
]
}
私はこの問題はここにあると思います。私は、URLの参照元がFacebookの場合は、コードを注入したい。
Background.js
var x = document.referrer;
if (x === "www.facebook.com") {
// listen for our browerAction to be clicked
chrome.browserAction.onClicked.addListener(function (tab) {
\t // for the current tab, inject the "inject.js" file & execute it
\t chrome.tabs.executeScript(tab.ib, {
\t \t file: 'inject.js'
\t });
});
}
Inject.js
// this is the code which will be injected into a given page...
(function() {
\t // just place a div at top right
\t var div = document.createElement('div');
\t div.style.position = 'fixed';
\t div.style.top = 0;
\t div.style.right = 0;
\t div.textContent = 'Injected!';
\t document.body.appendChild(div);
\t alert('inserted self... giggity');
})();
あなたが私のために働くコードを提供できれば嬉しいです。
必要な読書:[拡張アーキテクチャ](https://developer.chrome.com/extensions/overview#arch)。背景ページには、Webページへの直接アクセス権がありません。おそらくwebRequest APIを使用してレスポンスヘッダーを確認する必要があります。ドキュメントを参照してください。 – wOxxOm