Komunikacja między ContentScript.js a rozszerzeniem Chrome
Chcę po prostu wysłać bieżący adres URL karty do mojego rozszerzenia:
Poniżej znajduje się mój manifest.json
<code>{ "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"] } ]} </code>
Poniżej znajduje się mój contentscript.js
<code>chrome.extension.sendRequest({url: window.location.href}, function(response) { console.log(response.farewell); }); </code>
Poniżej znajduje się moje popup.html
<code><!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> </code>
Nie widzę niczego w konsoli. Jestem nowym użytkownikiem rozszerzeń Chrome.