0
我只是想在當前選項卡的URL發送到我的分機:ContentScript.js和Chrome擴展程序之間的通信
以下是我的manifest.json
{
"name": "DocUrlExtention",
"version": "1.0",
"manifest_version": 2,
"description": "The first extension that I made.",
"browser_action": {
"default_icon": "icon.png",
"default_popup": "popup.html"
},
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["contentscript.js"]
}
]}
以下是我contentscript.js
chrome.extension.sendRequest({url: window.location.href}, function(response) {
console.log(response.farewell);
});
以下是我popup.html
<!doctype html>
<html>
<head>
<title>Getting Started Extension's Popup</title>
<script>
chrome.extension.onRequest.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
});
</script>
<!-- JavaScript and HTML must be in separate files for security. -->
<!--<script src="popup.js"></script>-->
</head>
<body>
<div id="mydiv">Doc Id:</div>
</body>
</html>
我在控制檯中看不到任何東西。我是Chrome擴展程序的新手。
人們發現我的相關答案很有用,它提供了一些有關Chrome擴展的信息,我學到了花費太多時間瞭解它們。 http://stackoverflow.com/questions/11920473/chrome-extension-background-page-html-not-working/19487091#19487091 –