0

contentscript.js

function createIDArray() { var IDArray = []; IDArray[0] = $('#u_4_0 > span > div').html(); return IDArray; } chrome.runtime.onMessage.addListener( function(request, sender, sendResponse) { console.log("This is being received from popup.js"); if (request.greeting == "hello") console.log(createIDArray()); sendResponse({farewell: "goodbye"}); return true; }); 

popup.js

$('#9610').click ( function() { chrome.tabs.query({active: true, currentWindow: true}, function(tabs) { chrome.tabs.sendMessage(tabs[0].id, {greeting: "This is data."}, function(response) { console.log(response.farewell); }); }); } ); 

Not receiving any response between the two scripts. My end goal here is going to be upon clicking a button in the popup, activate a function in the content script.

popup.html

<head> <script type="text/javascript" src="jquery.js"></script> <script src="popup.js"></script> </head> <body> <button id="9610">Copy SRT Data</button> <button id="1691">Paste SRT Data</button> </body> 

manifest.json

{ "manifest_version": 2, "name": "Task Auto Fill", "description": "This extension shows a Google Image search result for the current page", "version": "1.0", "browser_action": { "default_icon": "icon.png", "default_popup": "popup.html" }, "name": "My extension", "background": { "scripts": ["background.js"] }, "permissions": [ "https://our.intern.facebook.com/", "tabs", "activeTab" ], "content_scripts": [ { "matches": ["http://*/*", "https://*/*"], "js": ["myscript.js"] } ] } 

1 Answer 1

0
  1. Please move your <script> tag in popup.html to the bottom of <body> tag. Please be aware currently you are putting them inside <head> and when $('#9610').click() is executed, the <body> is not constructed and you won't find the button at all.

  2. Update request.greeting == "hello" in your contentscript.js. Please keep it sync with the data you sent from popup.js

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.