2

I added a background page that contains a form with a button. I am using jQuery for handling DOM and events. On hitting Search button it doesn't work as expected, it should show alert( "Handler for .click() called." );

Update: On Console I get:

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' chrome-extension-resource:".

Relevant code given below:

Manifest.json

{
    "manifest_version": 2,
    "name" : "my Ext,
    "description" : "Copy Rows",
    "version" : "1.0",
    "content_scripts" : [{
        "matches" : ["http://example.com/"],
        "js" : ["jquery.js","script.js"]
    }],
"background":{
  "scripts": ["jquery.js","background.js"]
},
    "browser_action": {
        "default_title": "Title"
      }
}

script.js

var currentURL = document.location.href;
$(document).ready(function(){

    $("#button").click(function()
    {
        alert( "Handler for .click() called." );
    });
});

chrome.extension.onMessage.addListener(function(msg, sender, sendResponse)
{
    alert(msg.param);
    if (msg.method == "getHTML")
      sendResponse({data: "Welcome Bg"});
});

background.js

chrome.browserAction.onClicked.addListener(function(activeTab){
  var loaderURL = chrome.extension.getURL("dashboard.html");
  chrome.tabs.create({ url: loaderURL });
});

function search()
{
//    alert("hi search");
//    chrome.tabs.sendMessage(activeTab.id, {method: "getHTML",param:"myParam"}, function(response) {
//    alert(response.data);
//  });
}
$(document).ready(function()
{
    $("#button").click(function()
    {
        alert( "Handler for .click() called." );
    });

});

dashboard.html (My BackgroundPage)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <script src="jquery.js"></script>
  </head>
  <body>
      <form>
      <textarea id="serch"></textarea>
      <input id="button" type="button" value="Search" />
      </form>
  </body>
</html>
Volatil3
  • 14,253
  • 38
  • 134
  • 263
  • 1
    http://stackoverflow.com/questions/11545743/chrome-extension-insert-content-script-on-browser-action –  Jan 04 '14 at 04:00
  • @Dexter Yes I did figure it out too so I moved on code to background.js, I don't see the message but click is not working either. – Volatil3 Jan 04 '14 at 04:04
  • Ok, I was not including ****, when did it behaved as expected. @Dexter can you please make your comment as answer? – Volatil3 Jan 04 '14 at 04:11

1 Answers1

2

The issue is solved here (essentially inline scripts were disallowed)

chrome extension insert content script on browser action

Community
  • 1
  • 1