I'm trying to make a popup interface for a chrome extension. I can't seem to send a message from the popup.html/popup.js to the content.js script. Here's what I have so far. When I click on the extension icon I get a button that says clickme. I click it and nothing happens, no errors in the chrome javascript console, and no message to content.js. I've been reading up on this for 2 days and there are examples of this working, but I can't get my example to work.
Manifest
{
"content_security_policy": "script-src 'self' 'unsafe-eval'; object-src 'self'",
"manifest_version": 2,
"name": "extensiontest",
"version": "0.2",
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
],
"browser_action": {
"default_icon": "Beaker.png",
"default_popup":"popup.html"
},
"background": {
"scripts": ["background.js"]
},
"permissions": [
"tabs"
]
}
popup.html
<html>
<head></head>
<script src="popup.js"></script>
<body>
<input id="button1" type=button value=clickme>
</body></html>
popup.js
function popup(){
alert(1);
chrome.tabs.query({active: true, currentWindow: true}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "start"});
});
button1=document.getElementById("button1");
button1.addEventListener('click', popup)
}
content.js
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "start" ) {
start();
}
}
);
function start(){
alert("started");
}
::DISCLAIMER::--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------The contents of this e-mail and any attachment(s) are confidential and intended for the named recipient(s) only. E-mail transmission is not guaranteed to be secure or error-free as information could be intercepted, corrupted, lost, destroyed, arrive late or incomplete, or may contain viruses in transmission. The email and its contents (with or without referred errors) shall therefore not attach any liability on the originator or BORN or its affiliates. Views or opinions, if any, presented in this email are solely those of the author and may not necessarily reflect the views or opinions of BORN or its affiliates. Any form of reproduction, dissemination, copying, disclosure, modification, distribution and/or publication of this message without the prior written consent of authorized representative of BORN is strictly prohibited. If you have received this email in error please delete it and notify the sender immediately. Before opening any email and/or attachments, please check them for viruses and other defects.--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To post to this group, send email to chromium-...@chromium.org.
Visit this group at https://groups.google.com/a/chromium.org/group/chromium-extensions/.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/8e89b340-50c3-4a72-afed-0ad1aa4c6741%40chromium.org.
For more options, visit https://groups.google.com/a/chromium.org/d/optout.
Front End Developer, BORN
India Direct Dial: +91 9942352417
2nd Floor, Hardy Tower, Ramanujan IT SEZ,
TRIL Infopark Limited, Taramani, Chennai – 600 113
|
|
|
|
||||||
|
Hello! I use a new email filtering service called BitBounce to filter my email. To deliver your email to my inbox, please click the button below and pay the small cryptocurrency fee. Thank you! $0.05 to deliver your email. |
||||||
|
|
|
I’m from a business — what are my delivery options |
BitBounce and Credo are transacted through CredoEx |
| Made by Turing Technology Inc. in San Mateo, California Sign Up for BitBounce |