当用户单击浏览器操作按钮时,我从后台页面注入我的内容脚本,如下所示:
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript(null, { file: "content.js" });
});
Run Code Online (Sandbox Code Playgroud)
那么如何从我的内部访问jQuery content.js
?我没有看到同时注入的方法.
我通过Chrome扩展程序在页面末尾添加了一些外部JavaScript.然后外部JavaScript尝试将一些数据发布回服务器,但是没有发生.
JavaScript希望获取当前页面和引用者的URL并将其发回服务器.
任何人都可以请教我这里有什么问题,如果不可能这样我怎样才能将数据从当前页面发回服务器.
的manifest.json
{
"name": "Website Safety",
"version": "1.0",
"manifest_version": 2,
"description": "The Website Safety Extension.",
"browser_action": {
"name": "View the website information for ",
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"background": {
// "scripts": ["refresh.js"]
"page": "background.html"
},
"content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'",
//"background_page": "background.html"
"content_scripts": [
{
"matches": ["<all_urls>"],
"js": ["contentScript.js"]
}
]
}
Run Code Online (Sandbox Code Playgroud)
现在是contentScript.js
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-31046309-1']);
_gaq.push(['_setAllowLinker', true]);
_gaq.push(['_trackPageview']);
(function() {
var ga = …
Run Code Online (Sandbox Code Playgroud) javascript dom google-analytics google-chrome-extension content-script