0
コードの挿入にGoogleのsample codeを変更しようとしています。ファイルmanifest.json
は、バックグラウンドスクリプトが含まれます。Chrome拡張機能のコンテンツスクリプトから変数を取得するにはどうすればよいですか?
"background": {
"scripts": ["background.js"],
"persistent": false
},
を、私はcontent scriptを追加します。
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["filter.js"]
}
],
今、私は、ユーザーが拡張機能のボタンをクリックしたときにfilter.js
で定義された関数foo()
を呼びたいです。私はbackground.js
でこれを行う:
testText
変数を渡すことはできません
function foo(test) {
alert('Test: ' + String(test));
}
var testText = 'foo';
として
foo()
が
filter.js
で定義されている
chrome.browserAction.onClicked.addListener(function(tab) {
chrome.tabs.executeScript({
code: 'foo(testText);'
});
});
。私はVM3181:1 Uncaught ReferenceError: testText is not defined
を得る。
私は変数を間違って参照していますが、正しく行うにはどうすればよいですか? Googleからの再利用